diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java index 3907953e7..211152d1d 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019, Gluon and/or its affiliates. + * Copyright (c) 2017, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -76,6 +76,7 @@ import com.oracle.javafx.scenebuilder.kit.editor.selection.Selection; import com.oracle.javafx.scenebuilder.kit.editor.util.ContextMenuController; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMIntrinsic; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject; @@ -2557,7 +2558,7 @@ private void updateFxomDocument(String fxmlText, URL fxmlLocation, ResourceBundl final FXOMDocument newFxomDocument; if (fxmlText != null) { - newFxomDocument = new FXOMDocument(fxmlText, fxmlLocation, getLibrary().getClassLoader(), resources); + newFxomDocument = new FXOMDocument(fxmlText, fxmlLocation, getLibrary().getClassLoader(), resources, FXOMDocumentSwitch.NORMALIZED); } else { newFxomDocument = null; } diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorPlatform.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorPlatform.java index 538816683..4914bf1ed 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorPlatform.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorPlatform.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Gluon and/or its affiliates. + * Copyright (c) 2016, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -55,6 +55,14 @@ * @treatAsPrivate */ public class EditorPlatform { + + public enum OS { + LINUX, MAC, WINDOWS; + + public static OS get() { + return IS_LINUX ? LINUX : IS_MAC ? MAC : WINDOWS; + } + } private static final String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT); //NOI18N diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddContextMenuToSelectionJob.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddContextMenuToSelectionJob.java index 2602b6087..c84a08e72 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddContextMenuToSelectionJob.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddContextMenuToSelectionJob.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -37,6 +38,7 @@ import com.oracle.javafx.scenebuilder.kit.editor.selection.AbstractSelectionGroup; import com.oracle.javafx.scenebuilder.kit.editor.selection.ObjectSelectionGroup; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject; import com.oracle.javafx.scenebuilder.kit.library.BuiltinLibrary; import com.oracle.javafx.scenebuilder.kit.library.Library; @@ -134,7 +136,8 @@ private void constructContextMenuMap() { for (FXOMObject fxomObject : osg.getItems()) { final FXOMDocument contextMenuDocument = new FXOMDocument( contextMenuFxmlText, - contextMenuFxmlURL, library.getClassLoader(), null); + contextMenuFxmlURL, library.getClassLoader(), null, + FXOMDocumentSwitch.NORMALIZED); assert contextMenuDocument != null; final FXOMObject contextMenuObject = contextMenuDocument.getFxomRoot(); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddTooltipToSelectionJob.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddTooltipToSelectionJob.java index 3bd26f800..99520977e 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddTooltipToSelectionJob.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/job/AddTooltipToSelectionJob.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -37,6 +38,7 @@ import com.oracle.javafx.scenebuilder.kit.editor.selection.AbstractSelectionGroup; import com.oracle.javafx.scenebuilder.kit.editor.selection.ObjectSelectionGroup; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject; import com.oracle.javafx.scenebuilder.kit.library.BuiltinLibrary; import com.oracle.javafx.scenebuilder.kit.library.Library; @@ -134,7 +136,8 @@ private void constructTooltipMap() { for (FXOMObject fxomObject : osg.getItems()) { final FXOMDocument contextMenuDocument = new FXOMDocument( contextMenuFxmlText, - tooltipFxmlURL, library.getClassLoader(), null); + tooltipFxmlURL, library.getClassLoader(), null, + FXOMDocumentSwitch.NORMALIZED); assert contextMenuDocument != null; final FXOMObject contextMenuObject = contextMenuDocument.getFxomRoot(); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/ImportWindowController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/ImportWindowController.java index 4140224ac..711827bea 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/ImportWindowController.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/ImportWindowController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Gluon and/or its affiliates. + * Copyright (c) 2017, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -56,6 +56,7 @@ import com.oracle.javafx.scenebuilder.kit.editor.panel.util.dialog.AbstractModalDialog; import com.oracle.javafx.scenebuilder.kit.editor.panel.util.dialog.ErrorDialog; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.i18n.I18N; import com.oracle.javafx.scenebuilder.kit.library.BuiltinLibrary; import com.oracle.javafx.scenebuilder.kit.library.user.UserLibrary; @@ -557,7 +558,8 @@ void unsetProcessing() { previewGroup.getChildren().clear(); final String fxmlText = BuiltinLibrary.makeFxmlText(t1.getJarReportEntry().getKlass()); try { - FXOMDocument fxomDoc = new FXOMDocument(fxmlText, null, importClassLoader, null); + FXOMDocument fxomDoc = new FXOMDocument(fxmlText, null, importClassLoader, null, + FXOMDocumentSwitch.NORMALIZED); zeNode = (Node) fxomDoc.getSceneGraphRoot(); } catch (IOException ioe) { showErrorDialog(ioe); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/LibraryPanelController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/LibraryPanelController.java index b28eeaa89..ee0fccbb5 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/LibraryPanelController.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/library/LibraryPanelController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017 Gluon and/or its affiliates. + * Copyright (c) 2016, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -1003,7 +1003,8 @@ private boolean hasDependencies(File fxmlFile) throws IOException { FXOMDocument fxomDocument = new FXOMDocument(FXOMDocument.readContentFromURL(location), location, getEditorController().getFxomDocument().getClassLoader(), - getEditorController().getFxomDocument().getResources()); + getEditorController().getFxomDocument().getResources(), + FXOMDocument.FXOMDocumentSwitch.NORMALIZED); res = hasDependencies(fxomDocument.getFxomRoot()); return res; diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java new file mode 100644 index 000000000..6833edb82 --- /dev/null +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022, Gluon and/or its affiliates. + * All rights reserved. Use is subject to license terms. + * + * This file is available and licensed under the following license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of Oracle Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.oracle.javafx.scenebuilder.kit.fxom; + +import java.util.Objects; + +import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.OS; + +/** + * Modifies FXML to be loaded so that properties in the FXML will not interfere + * with Scene Builder. + */ +class FXMLPropertiesDisabler { + + private final OS os; + + /** + * Creates a new FXMLPropertiesDisabler which is aware of the platform and can + * prepare the FXML test according required platform behavior. + */ + public FXMLPropertiesDisabler() { + this(OS.get()); + } + + /** + * This constructor is primarily intended to enable testing of operating system + * depending behavior. Please favor the default constructor + * {@code FXMLPropertiesDisabler()}. + * + * @param os {@link OS} Represents the operating system where Scene Builder is + * supposed to work on. + */ + FXMLPropertiesDisabler(OS os) { + this.os = Objects.requireNonNull(os); + } + + /** + * In some cases, during FXML Loading, certain properties must be disabled. + * This method modifies the FXML source accordingly. + * + * @param fxmlText FXML source to be modified + * @return FXML source with all properties disabled (=false) where WYSIWYG editing is not suitable. + * @throws NullPointerException in case of fxmlText is null + */ + public String disableProperties(String fxmlText) { + Objects.requireNonNull(fxmlText, "fxmlText must not be null"); + String modifiedFxml = disableUseSystemMenuBarProperty(fxmlText); + return modifiedFxml; + } + + /** + * On MacOS, when loading a FXML with a menu bar where useSystemMenuBarProperty() + * is enabled, the menu in the FXML will hide the menu of Scene Builder. + * In this case, Scene Builder becomes unusable. + * + * Setting the property here to false has the advantage, that the FXML to be saved + * will still contain the defined property BUT the Scene Builder menu bar will remain + * visible. + * + * The modification of properties which are not desired to be active while + * editing must happen before loading the FXML using the FXMLLoader. + * + * Here a disconnect between the FXOM and FXML is created as the state of the + * useSystemMenuBarProperty is now different in both models. + * + * @param fxmlText FXML source to be modified + * @return FXML source with all properties disabled (=false) where WYSIWYG editing is not suitable. + * @throws NullPointerException in case of fxmlText is null + */ + private String disableUseSystemMenuBarProperty(String fxmlText) { + Objects.requireNonNull(fxmlText, "fxmlText must not be null"); + if (OS.MAC == os) { + /* + * Regex description: + * mandatory white space + * useSystemMenuBar + * optional white space + * = + * optional white space + * "true" + */ + String regex = "(\\s)useSystemMenuBar(\\s*)[=](\\s*)\"true\""; + return fxmlText.replaceAll(regex, " useSystemMenuBar=\"false\""); + } + return fxmlText; + } +} diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java index f9c3d0505..845a092a0 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Gluon and/or its affiliates. + * Copyright (c) 2019, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -39,6 +39,8 @@ import java.util.ArrayList; import java.util.List; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; + /** * */ @@ -72,7 +74,8 @@ public List decode(FXOMDocument targetDocument) final URL location = e.getLocation(); final String fxmlText = e.getFxmlText(); final FXOMDocument d = new FXOMDocument(fxmlText, location, - targetDocument.getClassLoader(), targetDocument.getResources()); + targetDocument.getClassLoader(), targetDocument.getResources(), + FXOMDocumentSwitch.NORMALIZED); final FXOMObject fxomRoot = d.getFxomRoot(); assert fxomRoot != null; fxomRoot.moveToFxomDocument(targetDocument); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java index b888e4b61..5a8bd248d 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019 Gluon and/or its affiliates. + * Copyright (c) 2017, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -44,8 +44,10 @@ import java.util.List; import java.util.Map; import java.util.ResourceBundle; +import java.util.Set; import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform; + import javafx.beans.property.ReadOnlyIntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.scene.Node; @@ -80,16 +82,38 @@ public class FXOMDocument { private List> initialDeclaredClasses; - public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, ResourceBundle resources, boolean normalize) throws IOException { + /** + * Creates a new {@link FXOMDocument} from given FXML source. Depending on the + * use case, the {@link FXOMDocumentSwitch} items can be used to configure the + * document creation process according to specific needs. E.g. normalization is + * not enabled by default, thus if required the {@link FXOMDocumentSwitch} + * {@code NORMALIZED} should be added as constructor argument. + * + * @param fxmlText FXML source + * @param location {@link URL} describing the actual document location + * @param classLoader {@link ClassLoader} to be used + * @param resources {@link ResourceBundle} to be used + * @param switches {@link FXOMDocumentSwitch} configuration options to enable + * or disable certain steps in {@link FXOMDocument} creation + * (e.g. enforcing normalization) + * @throws IOException when the fxmlText cannot be loaded + */ + public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, ResourceBundle resources, FXOMDocumentSwitch... switches) throws IOException { this.glue = new GlueDocument(fxmlText); this.location = location; this.classLoader = classLoader; this.resources = resources; initialDeclaredClasses = new ArrayList<>(); if (this.glue.getRootElement() != null) { + String fxmlTextToLoad = fxmlText; + Set availableSwitches = Set.of(switches); + if (!availableSwitches.contains(FXOMDocumentSwitch.FOR_PREVIEW)) { + final FXMLPropertiesDisabler fxmlPropertiesDisabler = new FXMLPropertiesDisabler(); + fxmlTextToLoad = fxmlPropertiesDisabler.disableProperties(fxmlText); + } final FXOMLoader loader = new FXOMLoader(this); - loader.load(fxmlText); - if (normalize) { + loader.load(fxmlTextToLoad); + if (availableSwitches.contains(FXOMDocumentSwitch.NORMALIZED)) { final FXOMNormalizer normalizer = new FXOMNormalizer(this); normalizer.normalize(); } @@ -102,13 +126,7 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso hasGluonControls = fxmlText.contains(EditorPlatform.GLUON_PACKAGE); } - - - public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, ResourceBundle resources) throws IOException { - this(fxmlText, location, classLoader, resources, true /* normalize */); - } - - + public FXOMDocument() { this.glue = new GlueDocument(); } @@ -443,4 +461,25 @@ public static interface SceneGraphHolder { public void fxomDocumentWillRefreshSceneGraph(FXOMDocument fxomDocument); public void fxomDocumentDidRefreshSceneGraph(FXOMDocument fxomDocument); } + + /** + * Depending on where the {@link FXOMDocument} shall be used, + * it is necessary to configure the {@link FXOMDocument} creation process. + * The switches here can be used to configure the creation process in the desired way. + */ + public enum FXOMDocumentSwitch { + /** + * When this flag is present, the {@link FXOMDocument} will be normalized (see {@link FXOMNormalizer}). + */ + NORMALIZED, + + /** + * When this flag is present during {@link FXOMDocument} creation, the + * {@link FXMLPropertiesDisabler} will be used to modify the FXML source in such + * a way that the included settings will not interfere Scene Builder's + * configuration. One possible example here is the option to use the MacOS + * system menu bar. + */ + FOR_PREVIEW; + } } diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java index 1da228dc7..96d87766e 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java @@ -1,4 +1,5 @@ -/* +/* + * Copyright (c) 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -31,6 +32,7 @@ */ package com.oracle.javafx.scenebuilder.kit.fxom; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.fxom.glue.GlueDocument; import com.oracle.javafx.scenebuilder.kit.fxom.glue.GlueInstruction; import com.oracle.javafx.scenebuilder.kit.metadata.Metadata; @@ -155,7 +157,8 @@ public static FXOMObject newObject(FXOMDocument targetDocument, File file) fxmlText, targetDocument.getLocation(), targetDocument.getClassLoader(), - targetDocument.getResources()); + targetDocument.getResources(), + FXOMDocumentSwitch.NORMALIZED); result = transientDoc.getFxomRoot(); if (result != null) { result.moveToFxomDocument(targetDocument); @@ -206,7 +209,8 @@ public static FXOMIntrinsic newInclude(FXOMDocument targetDocument, File file) fxmlText, fxmlURL, targetDocument.getClassLoader(), - targetDocument.getResources()); + targetDocument.getResources(), + FXOMDocumentSwitch.NORMALIZED); if (transientDoc.getFxomRoot() != null) { final PrefixedValue pv = PrefixedValue.makePrefixedValue(fxmlURL, targetDocument.getLocation()); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMRefresher.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMRefresher.java index 8d736cfbd..893b18fa3 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMRefresher.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMRefresher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Gluon and/or its affiliates. + * Copyright (c) 2019, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -64,8 +64,7 @@ public void refresh(FXOMDocument document) { = new FXOMDocument(fxmlText, document.getLocation(), document.getClassLoader(), - document.getResources(), - false /* normalized */); + document.getResources()); final TransientStateBackup backup = new TransientStateBackup(document); // if the refresh should not take place (e.g. due to an error), remove a property from intrinsic if (newDocument.getSceneGraphRoot() == null && newDocument.getFxomRoot() == null) { diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/LibraryItem.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/LibraryItem.java index 4ae637543..858d4d580 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/LibraryItem.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/library/LibraryItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Gluon and/or its affiliates. + * Copyright (c) 2016, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -33,6 +33,8 @@ package com.oracle.javafx.scenebuilder.kit.library; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; + import java.io.IOException; import java.net.URL; import java.util.Objects; @@ -85,7 +87,7 @@ public FXOMDocument instantiate() { FXOMDocument result; try { - result = new FXOMDocument(fxmlText, null, library.getClassLoader(), null); + result = new FXOMDocument(fxmlText, null, library.getClassLoader(), null, FXOMDocumentSwitch.NORMALIZED); } catch(Error|IOException x) { x.printStackTrace(); result = null; diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/Metadata.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/Metadata.java index 534995c6f..45134fa8d 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/Metadata.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/Metadata.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017 Gluon and/or its affiliates. + * Copyright (c) 2016, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -1260,6 +1260,8 @@ public boolean isPropertyTrimmingNeeded(PropertyName name) { new PropertyName("unitIncrement"); private final PropertyName upperBoundName = new PropertyName("upperBound"); + private final PropertyName useSystemMenuBarName = + new PropertyName("useSystemMenuBar"); private final PropertyName userAgentStylesheetName = new PropertyName("userAgentStylesheet"); private final PropertyName valignmentName = @@ -4471,6 +4473,11 @@ public boolean isPropertyTrimmingNeeded(PropertyName name) { true, /* readWrite */ 100.0, /* defaultValue */ new InspectorPath("Properties", "Specific", 98)); + private final ValuePropertyMetadata useSystemMenuBarPropertyMetadata = + new BooleanPropertyMetadata(useSystemMenuBarName, + true, /* readWrite */ + false, + new InspectorPath("Properties", "Node", 25)); private final ValuePropertyMetadata userAgentStylesheetPropertyMetadata = new StringPropertyMetadata( userAgentStylesheetName, @@ -5412,6 +5419,7 @@ private Metadata() { MenuBarMetadata.getProperties().add(accessibleRole_MENU_BAR_PropertyMetadata); MenuBarMetadata.getProperties().add(menusPropertyMetadata); MenuBarMetadata.getProperties().add(styleClass_c18_PropertyMetadata); + MenuBarMetadata.getProperties().add(useSystemMenuBarPropertyMetadata); MenuButtonMetadata.getProperties().add(accessibleRole_MENU_BUTTON_PropertyMetadata); MenuButtonMetadata.getProperties().add(focusTraversable_true_PropertyMetadata); @@ -6270,7 +6278,6 @@ private Metadata() { hiddenProperties.add(new PropertyName("typeSelector")); hiddenProperties.add(new PropertyName("undoable")); hiddenProperties.add(new PropertyName("userData")); - hiddenProperties.add(new PropertyName("useSystemMenuBar")); hiddenProperties.add(new PropertyName("valueChanging")); hiddenProperties.add(new PropertyName("valueConverter")); hiddenProperties.add(new PropertyName("valueFactory")); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/util/ClipboardDecoder.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/util/ClipboardDecoder.java index 773870704..3f6c26dbd 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/util/ClipboardDecoder.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/metadata/util/ClipboardDecoder.java @@ -1,4 +1,5 @@ -/* +/* + * Copyright (c) 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -34,6 +35,7 @@ import com.oracle.javafx.scenebuilder.kit.fxom.FXOMArchive; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMNodes; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject; import java.io.File; @@ -86,7 +88,7 @@ public List decode(FXOMDocument targetDocument) { final ClassLoader classLoader = targetDocument.getClassLoader(); final ResourceBundle resources = targetDocument.getResources(); final FXOMDocument transientDoc - = new FXOMDocument(fxmlText, location, classLoader, resources); + = new FXOMDocument(fxmlText, location, classLoader, resources, FXOMDocumentSwitch.NORMALIZED); result = Arrays.asList(transientDoc.getFxomRoot()); } catch(IOException x) { result = null; diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java index 409d6e885..fa0000c13 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Gluon and/or its affiliates. + * Copyright (c) 2016, 2022, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -38,6 +38,7 @@ import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.Theme; import com.oracle.javafx.scenebuilder.kit.editor.panel.util.AbstractWindowController; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.i18n.I18N; import com.oracle.javafx.scenebuilder.kit.util.MathUtils; @@ -214,7 +215,8 @@ public void openDialog() { clone = new FXOMDocument(fxomDocument.getFxmlText(false), fxomDocument.getLocation(), fxomDocument.getClassLoader(), - fxomDocument.getResources()); + fxomDocument.getResources(), + FXOMDocumentSwitch.FOR_PREVIEW, FXOMDocumentSwitch.NORMALIZED); clone.setSampleDataEnabled(fxomDocument.isSampleDataEnabled()); } catch (IOException ex) { throw new RuntimeException("Bug in PreviewWindowController::openDialog", ex); //NOI18N @@ -280,7 +282,8 @@ public void run() { clone = new FXOMDocument(fxomDocument.getFxmlText(false), fxomDocument.getLocation(), fxomDocument.getClassLoader(), - fxomDocument.getResources()); + fxomDocument.getResources(), + FXOMDocumentSwitch.FOR_PREVIEW); clone.setSampleDataEnabled(fxomDocument.isSampleDataEnabled()); } catch (IOException ex) { throw new RuntimeException("Bug in PreviewWindowController::requestUpdate", ex); //NOI18N diff --git a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerTest.java b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerTest.java new file mode 100644 index 000000000..698110ee1 --- /dev/null +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022, Gluon and/or its affiliates. + * All rights reserved. Use is subject to license terms. + * + * This file is available and licensed under the following license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of Oracle Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.oracle.javafx.scenebuilder.kit.fxom; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.nio.file.Files; + +import org.junit.Test; + +import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.OS; + +public class FXMLPropertiesDisablerTest { + + private FXMLPropertiesDisabler classUnderTest; + + @Test + public void that_property_value_is_set_to_false_on_MacOS() throws Exception { + classUnderTest = new FXMLPropertiesDisabler(OS.MAC); + String fxmlText = readResourceText("ContainerWithMenuSystemMenuBarEnabled.fxml"); + assertTrue("ensures that test resource is correct", + fxmlText.contains("")); + String modfiedFxmlText = classUnderTest.disableProperties(fxmlText); + assertTrue(modfiedFxmlText.contains("")); + } + + @Test + public void that_property_value_is_not_modified_on_Windows() throws Exception { + classUnderTest = new FXMLPropertiesDisabler(OS.WINDOWS); + String fxmlText = readResourceText("ContainerWithMenuSystemMenuBarEnabled.fxml"); + assertTrue("ensures that test resource is correct", + fxmlText.contains("")); + String modfiedFxmlText = classUnderTest.disableProperties(fxmlText); + assertTrue(modfiedFxmlText.contains("")); + } + + @Test + public void that_property_value_is_not_modified_on_LINUX() throws Exception { + classUnderTest = new FXMLPropertiesDisabler(OS.LINUX); + String fxmlText = readResourceText("ContainerWithMenuSystemMenuBarEnabled.fxml"); + assertTrue("ensures that test resource is correct", + fxmlText.contains("")); + String modfiedFxmlText = classUnderTest.disableProperties(fxmlText); + assertTrue(modfiedFxmlText.contains("")); + } + + private String readResourceText(String resourceName) throws Exception { + File fxmlFileName = new File(getClass().getResource(resourceName).toURI()); + return Files.readString(fxmlFileName.toPath()); + } +} diff --git a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerVariationsTest.java b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerVariationsTest.java new file mode 100644 index 000000000..612d0d93b --- /dev/null +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerVariationsTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022, Gluon and/or its affiliates. + * All rights reserved. Use is subject to license terms. + * + * This file is available and licensed under the following license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of Oracle Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.oracle.javafx.scenebuilder.kit.fxom; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.OS; + +@RunWith(Parameterized.class) +public class FXMLPropertiesDisablerVariationsTest { + + @Parameters(name = "{index}: fxml({0})={1}") + public static List data() { + return Arrays.asList(new String[][] { + { "1", "MAC", "", + ""}, + + { "2", "MAC","", + ""}, + + { "3", "MAC","", + ""}, + + { "4", "MAC","", + ""}, + + { "5", "WINDOWS","", + ""}, + + { "6", "LINUX", "", + ""}, + }); + } + + private String id; + private OS os; + private String input; + private String expected; + + public FXMLPropertiesDisablerVariationsTest(String id, String osName, String input, String expected) { + this.id = id; + this.input = input; + this.expected = expected; + this.os = OS.valueOf(osName); + } + + @Test + public void that_property_is_disabled_when_required() { + FXMLPropertiesDisabler classUnderTest = new FXMLPropertiesDisabler(os); + String modified = classUnderTest.disableProperties(input); + assertEquals(id, expected, modified); + } +} diff --git a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java index 89a66838e..df36c170d 100644 --- a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Gluon and/or its affiliates. + * Copyright (c) 2021, 2022, Gluon and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -36,28 +36,143 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; +import java.io.File; import java.io.IOException; import java.net.URL; +import java.nio.file.Files; +import java.util.ResourceBundle; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.xml.sax.SAXParseException; import com.oracle.javafx.scenebuilder.kit.JfxInitializer; +import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.OS; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import javafx.application.Platform; import javafx.fxml.FXMLLoader; +import javafx.scene.control.MenuBar; public class FXOMDocumentTest { - @Before - public void init() { + private FXOMDocument classUnderTest; + + private String fxmlName; + private URL fxmlUrl; + private String fxmlText; + private ClassLoader loader; + private ResourceBundle resourceBundle; + + @BeforeClass + public static void init() { JfxInitializer.initialize(); } + @Before + public void prepareTest() throws Exception { + fxmlName = "ContainerWithMenuSystemMenuBarEnabled.fxml"; + fxmlUrl = getResourceUrl(fxmlName); + fxmlText = readResourceText(fxmlName); + loader = this.getClass().getClassLoader(); + resourceBundle = null; + } + + @Test + public void that_FOR_PREVIEW_useSystemMenuBarProperty_is_enabled() throws Exception { + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle, FXOMDocumentSwitch.FOR_PREVIEW); + + FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); + + assertTrue(fxomObject.getSceneGraphObject() instanceof MenuBar); + assertTrue("for preview, useSystemMenu is expected to be enabled", + ((MenuBar) fxomObject.getSceneGraphObject()).useSystemMenuBarProperty().get()); + + String generatedFxml = classUnderTest.getFxmlText(false); + assertTrue(generatedFxml.contains("useSystemMenuBar=\"true\"")); + } + + @Test + public void that_useSystemMenuBarProperty_is_disabled_on_MacOS() throws Exception { + assumeTrue("MacOS", OS.get() == OS.MAC); + + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); + + FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); + + assertTrue(fxomObject.getSceneGraphObject() instanceof MenuBar); + assertFalse("for preview, useSystemMenu is expected to be enabled", + ((MenuBar) fxomObject.getSceneGraphObject()).useSystemMenuBarProperty().get()); + + String generatedFxml = classUnderTest.getFxmlText(false); + assertTrue(generatedFxml.contains("useSystemMenuBar=\"true\"")); + } + + @Test + public void that_useSystemMenuBarProperty_not_modified_on_Linux_and_Windows() throws Exception { + assumeTrue("Windows or Linux", Set.of(OS.LINUX, OS.WINDOWS).contains(OS.get())); + + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); + + FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); + + assertTrue(fxomObject.getSceneGraphObject() instanceof MenuBar); + assertTrue("for preview, useSystemMenu is expected to be enabled", + ((MenuBar) fxomObject.getSceneGraphObject()).useSystemMenuBarProperty().get()); + + String generatedFxml = classUnderTest.getFxmlText(false); + assertTrue(generatedFxml.contains("useSystemMenuBar=\"true\"")); + } + + @Test + public void that_normalization_is_applied_only_when_NORMALIZED_is_set() throws Exception { + fxmlText = readResourceText("NonNormalizedAccordion.fxml"); + fxmlUrl = getResourceUrl("NonNormalizedAccordion.fxml"); + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle, FXOMDocumentSwitch.NORMALIZED); + + String generatedFxml = extractContentsOfFirstChildrenTag(classUnderTest.getFxmlText(false)); + String expectedFxml = extractContentsOfFirstChildrenTag(readResourceText("NormalizedAccordion.fxml")); + assertEquals(expectedFxml, generatedFxml); + } + + @Test + public void that_normalization_is_disabled_when_NORMALIZED_is_not_set() throws Exception { + fxmlText = readResourceText("NonNormalizedAccordion.fxml"); + fxmlUrl = getResourceUrl("NonNormalizedAccordion.fxml"); + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); + + String generatedFxml = extractContentsOfFirstChildrenTag(classUnderTest.getFxmlText(false)); + String expectedFxml = extractContentsOfFirstChildrenTag(readResourceText("NonNormalizedAccordion.fxml")); + assertEquals(expectedFxml, generatedFxml); + } + + private String readResourceText(String resourceName) throws Exception { + File fxmlFileName = new File(getResourceUrl(resourceName).toURI()); + return useOnlyNewLine(Files.readString(fxmlFileName.toPath())); + } + + private URL getResourceUrl(String resourceName) { + return getClass().getResource(resourceName); + } + + private String useOnlyNewLine(String source) { + return source.replace("\r\n", "\n"); + } + + private String extractContentsOfFirstChildrenTag(String source) { + String openingTag = ""; + String closingTag = ""; + int open = source.indexOf(openingTag); + int close = source.lastIndexOf(closingTag) + closingTag.length(); + return source.substring(open, close); + } + @Test public void that_IOException_is_thrown_in_case_FXMLLoader_error() throws Exception { URL resource = getClass().getResource("BrokenByUserData.fxml"); @@ -90,8 +205,9 @@ public void that_exception_in_case_of_broken_XML_is_captured() throws Exception public void that_no_exception_is_created_with_empty_FXML() throws Exception { URL resource = getClass().getResource("Empty.fxml"); String fxmlText = ""; - boolean normalizeFxom = false; - FXOMDocument classUnderTest = new FXOMDocument(fxmlText, resource, null, null, normalizeFxom); + + // FXOM will only apply normalization when FXOMDocumentSwitch.NORMALIZED is set + FXOMDocument classUnderTest = new FXOMDocument(fxmlText, resource, null, null); assertNotNull(classUnderTest); } @@ -147,7 +263,8 @@ public void that_fxml_with_defines_loads_without_error_without_normalization() t URL resource = getClass().getResource("DynamicScreenSize.fxml"); String validFxmlText = FXOMDocument.readContentFromURL(resource); - FXOMDocument classUnderTest = waitFor(() -> new FXOMDocument(validFxmlText, resource, null, null, false)); + // Non-normalizing by default + FXOMDocument classUnderTest = waitFor(() -> new FXOMDocument(validFxmlText, resource, null, null)); String beforeNormalization = classUnderTest.getFxmlText(false); assertFalse(beforeNormalization.isBlank()); } @@ -158,7 +275,7 @@ public void that_missing_imports_during_defines_resolution_cause_exception() thr String validFxmlText = FXOMDocument.readContentFromURL(resource); Throwable t = assertThrows(Throwable.class, - () -> waitFor(() -> new FXOMDocument(validFxmlText, resource, null, null, true /* normalization enabled */))); + () -> waitFor(() -> new FXOMDocument(validFxmlText, resource, null, null, FXOMDocumentSwitch.NORMALIZED))); if (t.getCause() != null) { t = t.getCause(); @@ -167,7 +284,7 @@ public void that_missing_imports_during_defines_resolution_cause_exception() thr assertEquals(IllegalStateException.class, t.getClass()); assertTrue(t.getMessage().contains("Bug in FXOMRefresher")); } - + private T waitFor(Callable callable) throws Exception { FutureTask task = new FutureTask(callable); if (Platform.isFxApplicationThread()) { diff --git a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMSaverUpdateImportInstructionsTest.java b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMSaverUpdateImportInstructionsTest.java index 3e8be788b..a7fb7eab2 100644 --- a/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMSaverUpdateImportInstructionsTest.java +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMSaverUpdateImportInstructionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2021, Gluon and/or its affiliates. + * Copyright (c) 2016, 2022, Gluon and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -47,6 +47,7 @@ import java.util.TreeSet; import com.oracle.javafx.scenebuilder.kit.JfxInitializer; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.fxom.glue.GlueCharacters; import org.junit.BeforeClass; import org.junit.Rule; @@ -282,7 +283,7 @@ private void setupFXOMDocument(Path fxmlTesterFile) { URL location = fxmlTesterFile.toFile().toURI().toURL(); String fxmlString = getFxmlAsString(fxmlTesterFile); - fxomDocument = new FXOMDocument(fxmlString, location, null, null); + fxomDocument = new FXOMDocument(fxmlString, location, null, null, FXOMDocumentSwitch.NORMALIZED); } catch (IOException e) { e.printStackTrace(); } diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenuSystemMenuBarEnabled.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenuSystemMenuBarEnabled.fxml new file mode 100644 index 000000000..18d50646c --- /dev/null +++ b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenuSystemMenuBarEnabled.fxml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalizedAccordion.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalizedAccordion.fxml new file mode 100644 index 000000000..a62bb711c --- /dev/null +++ b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalizedAccordion.fxml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NormalizedAccordion.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NormalizedAccordion.fxml new file mode 100644 index 000000000..2650d2f95 --- /dev/null +++ b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NormalizedAccordion.fxml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + +