From 0fc2a788d868dd45789ef26c9879dc7869a1bcb3 Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Tue, 7 Sep 2021 14:51:13 +0200 Subject: [PATCH 01/43] Draft of an idea for issue-404. --- .../scenebuilder/kit/fxom/FXOMDocument.java | 27 ++++++++++++------- .../scenebuilder/kit/fxom/FXOMRefresher.java | 5 ++-- .../kit/preview/PreviewWindowController.java | 9 ++++--- 3 files changed, 26 insertions(+), 15 deletions(-) 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..f17d27857 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 @@ -44,6 +44,7 @@ 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; @@ -80,16 +81,23 @@ public class FXOMDocument { private List> initialDeclaredClasses; - public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, ResourceBundle resources, boolean normalize) throws IOException { + 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; + if (Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { + fxmlTextToLoad = fxmlText.replace("useSystemMenuBar=\"true\"", + "useSystemMenuBar=\"false\""); + } final FXOMLoader loader = new FXOMLoader(this); - loader.load(fxmlText); - if (normalize) { + loader.load(fxmlTextToLoad); + + if (!Set.of(switches).contains(FXOMDocumentSwitch.NON_NORMALIZED)) { final FXOMNormalizer normalizer = new FXOMNormalizer(this); normalizer.normalize(); } @@ -102,13 +110,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 +445,9 @@ public static interface SceneGraphHolder { public void fxomDocumentWillRefreshSceneGraph(FXOMDocument fxomDocument); public void fxomDocumentDidRefreshSceneGraph(FXOMDocument fxomDocument); } + + public enum FXOMDocumentSwitch { + NON_NORMALIZED, + FOR_PREVIEW; + } } 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..53a039c86 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, 2021, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * @@ -32,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.metadata.Metadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.ValuePropertyMetadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.value.DoubleArrayPropertyMetadata; @@ -65,7 +66,7 @@ public void refresh(FXOMDocument document) { document.getLocation(), document.getClassLoader(), document.getResources(), - false /* normalized */); + FXOMDocumentSwitch.NON_NORMALIZED); 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/preview/PreviewWindowController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java index 409d6e885..1de97cb4c 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, 2019, 2021, 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); 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 From a94233f2ea4d5c5523a9351a9be96c7e84b36bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Tue, 7 Sep 2021 15:13:09 +0200 Subject: [PATCH 02/43] Moved the FXML modification code into a separate class. Corrected the expression which checks if the WYSIWYG adjustment for preview function shall be used or not. --- .../kit/fxom/FXMLPropertiesDisabler.java | 30 +++++++++++++++++++ .../scenebuilder/kit/fxom/FXOMDocument.java | 6 ++-- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java 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..442bd3063 --- /dev/null +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java @@ -0,0 +1,30 @@ +package com.oracle.javafx.scenebuilder.kit.fxom; + +class FXMLPropertiesDisabler { + + /** + * + * On MacOS, when loading a FXML with a menu bar where useSystemMenuBarProperty() + * is enabled, the menu in the FXML will hide the menu of SceneBuilder. + * In this case, SceneBuilder 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 SceneBuilder 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. + * + */ + public String disableNonWysiwygProperties(String fxmlText) { + return fxmlText.replace("useSystemMenuBar=\"true\"", + "useSystemMenuBar=\"false\""); + } + +} 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 f17d27857..8d854af41 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 @@ -90,9 +90,9 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso if (this.glue.getRootElement() != null) { String fxmlTextToLoad = fxmlText; - if (Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { - fxmlTextToLoad = fxmlText.replace("useSystemMenuBar=\"true\"", - "useSystemMenuBar=\"false\""); + if (!Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { + final FXMLPropertiesDisabler FXMLPropertiesDisabler = new FXMLPropertiesDisabler(); + fxmlTextToLoad = FXMLPropertiesDisabler.disableNonWysiwygProperties(fxmlText); } final FXOMLoader loader = new FXOMLoader(this); loader.load(fxmlTextToLoad); From a88229cab9164c5a833f2cb05bfe2bc9c8b7336e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Tue, 7 Sep 2021 15:15:19 +0200 Subject: [PATCH 03/43] Header updated. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8d854af41..3be62354b 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, 2019, 2021, Gluon and/or its affiliates. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * From 9e5138349c215bff1f74508d90e50593ae5dc81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Tue, 7 Sep 2021 15:22:41 +0200 Subject: [PATCH 04/43] Formatting reworked. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3be62354b..024c5a230 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 @@ -81,7 +81,7 @@ public class FXOMDocument { private List> initialDeclaredClasses; - public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, ResourceBundle resources, FXOMDocumentSwitch ... switches) throws IOException { + 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; From 1cbe93af86468f88843c4e2f7377bc3979f467c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Tue, 7 Sep 2021 15:24:18 +0200 Subject: [PATCH 05/43] Header added. --- .../kit/fxom/FXMLPropertiesDisabler.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 index 442bd3063..ab9dbd38c 100644 --- 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 @@ -1,3 +1,34 @@ +/* + * Copyright (c) 2021, 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; class FXMLPropertiesDisabler { From 719522131b61f86fca880866a425d49d3d017395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Tue, 7 Sep 2021 15:24:34 +0200 Subject: [PATCH 06/43] Formatting --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java index eeae82a97..470d95446 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java @@ -287,7 +287,7 @@ public void readPropertyAttribute(String name, Class staticClass, String fxml } else if (currentTransientNode instanceof TransientProperty) { final TransientProperty transientProperty = (TransientProperty) currentTransientNode; transientProperty.getCollectedProperties().add(fxomProperty); - } else if(currentTransientNode instanceof TransientIntrinsic) { + } else if(currentTransientNode instanceof TransientIntrinsic) { final TransientIntrinsic transientIntrinsic = (TransientIntrinsic) currentTransientNode; transientIntrinsic.getProperties().add(fxomProperty); } From 401c6f4c413092786498835fa8f13696fbad867d Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Tue, 7 Sep 2021 18:00:50 +0200 Subject: [PATCH 07/43] Added tests for changes in FXOMDocument. --- .../kit/fxom/FXMLPropertiesDisabler.java | 2 +- .../scenebuilder/kit/fxom/FXOMDocument.java | 2 +- .../kit/fxom/FXMLPropertiesDisablerTest.java | 61 ++++++++ .../kit/fxom/FXOMDocumentTest.java | 134 ++++++++++++++++++ ...ontainerWithMenu_SystemMenuBarEnabled.fxml | 33 +++++ .../kit/fxom/NonNormalized_Accordion.fxml | 27 ++++ .../kit/fxom/Normalized_Accordion.fxml | 24 ++++ 7 files changed, 281 insertions(+), 2 deletions(-) create mode 100644 kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerTest.java create mode 100644 kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java create mode 100644 kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenu_SystemMenuBarEnabled.fxml create mode 100644 kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalized_Accordion.fxml create mode 100644 kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/Normalized_Accordion.fxml 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 index ab9dbd38c..538042575 100644 --- 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 @@ -53,7 +53,7 @@ class FXMLPropertiesDisabler { * @return FXML source with all properties disabled (=false) where WYSIWYG editing is not suitable. * */ - public String disableNonWysiwygProperties(String fxmlText) { + public String disableUseSystemMenuBarProperty(String fxmlText) { return fxmlText.replace("useSystemMenuBar=\"true\"", "useSystemMenuBar=\"false\""); } 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 024c5a230..8a3653088 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 @@ -92,7 +92,7 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso String fxmlTextToLoad = fxmlText; if (!Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { final FXMLPropertiesDisabler FXMLPropertiesDisabler = new FXMLPropertiesDisabler(); - fxmlTextToLoad = FXMLPropertiesDisabler.disableNonWysiwygProperties(fxmlText); + fxmlTextToLoad = FXMLPropertiesDisabler.disableUseSystemMenuBarProperty(fxmlText); } final FXOMLoader loader = new FXOMLoader(this); loader.load(fxmlTextToLoad); 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..bc8951374 --- /dev/null +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021, 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; + +public class FXMLPropertiesDisablerTest { + + private FXMLPropertiesDisabler classUnderTest = new FXMLPropertiesDisabler(); + + @Test + public void that_property_value_is_set_to_false() throws Exception { + String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); + assertTrue("ensures that test resource is correct", + fxmlText.contains("")); + + String modfiedFxmlText = classUnderTest.disableUseSystemMenuBarProperty(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/FXOMDocumentTest.java b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java new file mode 100644 index 000000000..aac888be6 --- /dev/null +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2021, 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 static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.net.URL; +import java.nio.file.Files; +import java.util.ResourceBundle; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.oracle.javafx.scenebuilder.kit.JfxInitializer; +import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; + +import javafx.scene.control.MenuBar; + +public class FXOMDocumentTest { + + 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 = "ContainerWithMenu_SystemMenuBarEnabled.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_by_default_useSystemMenuBarProperty_is_disabled() throws Exception { + 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_normalization_is_applied_by_default() throws Exception { + fxmlText = readResourceText("NonNormalized_Accordion.fxml"); + fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); + + String generatedFxml = classUnderTest.getFxmlText(false).replace("\n", System.lineSeparator()); + String expectedFxml = readResourceText("Normalized_Accordion.fxml"); + assertEquals(expectedFxml, generatedFxml); + } + + @Test + public void that_normalization_is_disabled_when_created_with_NON_NORMALIZED() throws Exception { + fxmlText = readResourceText("NonNormalized_Accordion.fxml"); + fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle, FXOMDocumentSwitch.NON_NORMALIZED); + + String generatedFxml = classUnderTest.getFxmlText(false).replace("\n", System.lineSeparator()); + String expectedFxml = readResourceText("NonNormalized_Accordion.fxml").replace("\n", System.lineSeparator()); + assertEquals(expectedFxml, generatedFxml); + } + + private String readResourceText(String resourceName) throws Exception { + File fxmlFileName = new File(getResourceUrl(resourceName).toURI()); + return Files.readString(fxmlFileName.toPath()); + } + + private URL getResourceUrl(String resourceName) { + return getClass().getResource(resourceName); + } +} diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenu_SystemMenuBarEnabled.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenu_SystemMenuBarEnabled.fxml new file mode 100644 index 000000000..18d50646c --- /dev/null +++ b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenu_SystemMenuBarEnabled.fxml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalized_Accordion.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalized_Accordion.fxml new file mode 100644 index 000000000..a62bb711c --- /dev/null +++ b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalized_Accordion.fxml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/Normalized_Accordion.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/Normalized_Accordion.fxml new file mode 100644 index 000000000..2650d2f95 --- /dev/null +++ b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/Normalized_Accordion.fxml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + From bc22b834c96690940bc52e4e45779ab9e8670128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 5 Jan 2022 02:34:48 +0100 Subject: [PATCH 08/43] FXLMPropertiesDiesabler generalized. Spelling mistakes corrected. Javadoc added. --- .../kit/fxom/FXMLPropertiesDisabler.java | 64 ++++++++++++++++--- .../scenebuilder/kit/fxom/FXOMDocument.java | 38 +++++++++-- .../scenebuilder/kit/fxom/FXOMLoader.java | 2 +- .../kit/fxom/FXMLPropertiesDisablerTest.java | 52 ++++++++++++--- .../kit/fxom/FXOMDocumentTest.java | 22 +++++-- 5 files changed, 149 insertions(+), 29 deletions(-) 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 index 538042575..0752370f2 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Gluon and/or its affiliates. + * 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: @@ -31,16 +31,38 @@ */ package com.oracle.javafx.scenebuilder.kit.fxom; -class FXMLPropertiesDisabler { +import java.util.Locale; +import java.util.Objects; +class FXMLPropertiesDisabler { + private final OperatingSystem os; + public FXMLPropertiesDisabler() { + this(OperatingSystem.get()); + } + public FXMLPropertiesDisabler(OperatingSystem 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 SceneBuilder. - * In this case, SceneBuilder becomes unusable. + * 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 SceneBuilder menu bar will remain + * 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 @@ -51,11 +73,33 @@ class FXMLPropertiesDisabler { * * @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 disableUseSystemMenuBarProperty(String fxmlText) { - return fxmlText.replace("useSystemMenuBar=\"true\"", - "useSystemMenuBar=\"false\""); + private String disableUseSystemMenuBarProperty(String fxmlText) { + Objects.requireNonNull(fxmlText, "fxmlText must not be null"); + if (OperatingSystem.MACOS.equals(os)) { + return fxmlText.replace("useSystemMenuBar=\"true\"", + "useSystemMenuBar=\"false\""); + } + return fxmlText; + } + + enum OperatingSystem { + MACOS, + WINDOWS, + LINUX; + public static OperatingSystem get() { + String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT); + if (osName.contains("linux")) { + return OperatingSystem.LINUX; + } + if (osName.contains("mac")) { + return OperatingSystem.MACOS; + } + if (osName.contains("windows")) { + return OperatingSystem.WINDOWS; + } + throw new UnsupportedOperationException("Unknown operating system platform!"); + } } - } 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 8a3653088..069b865bf 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, 2021, 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. * @@ -81,6 +81,20 @@ public class FXOMDocument { private List> initialDeclaredClasses; + /** + * 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. + * + * @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. disabling 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; @@ -88,15 +102,13 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso this.resources = resources; initialDeclaredClasses = new ArrayList<>(); if (this.glue.getRootElement() != null) { - String fxmlTextToLoad = fxmlText; if (!Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { - final FXMLPropertiesDisabler FXMLPropertiesDisabler = new FXMLPropertiesDisabler(); - fxmlTextToLoad = FXMLPropertiesDisabler.disableUseSystemMenuBarProperty(fxmlText); + final FXMLPropertiesDisabler fxmlPropertiesDisabler = new FXMLPropertiesDisabler(); + fxmlTextToLoad = fxmlPropertiesDisabler.disableProperties(fxmlText); } final FXOMLoader loader = new FXOMLoader(this); loader.load(fxmlTextToLoad); - if (!Set.of(switches).contains(FXOMDocumentSwitch.NON_NORMALIZED)) { final FXOMNormalizer normalizer = new FXOMNormalizer(this); normalizer.normalize(); @@ -446,8 +458,24 @@ public static interface SceneGraphHolder { 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. + * This enum replaces the previously used boolean arguments in the {@link FXOMDocument} constructor. + */ public enum FXOMDocumentSwitch { + /** + * If this switch is defined, the {@link FXOMDocument} will not be normalized (see {@link FXOMNormalizer}). + */ NON_NORMALIZED, + + /** + * When this flag is present during {@link FXOMDocument} creation, + * the {@link FXMLPropertiesDisabler} will be used to prepare the FXML source in a way, + * so that settings defined in the FXML will not interfere Scene Builders 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/FXOMLoader.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java index 470d95446..72260912e 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java @@ -287,7 +287,7 @@ public void readPropertyAttribute(String name, Class staticClass, String fxml } else if (currentTransientNode instanceof TransientProperty) { final TransientProperty transientProperty = (TransientProperty) currentTransientNode; transientProperty.getCollectedProperties().add(fxomProperty); - } else if(currentTransientNode instanceof TransientIntrinsic) { + } else if (currentTransientNode instanceof TransientIntrinsic) { final TransientIntrinsic transientIntrinsic = (TransientIntrinsic) currentTransientNode; transientIntrinsic.getProperties().add(fxomProperty); } 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 index bc8951374..4e802783e 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Gluon and/or its affiliates. + * 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: @@ -31,6 +31,7 @@ */ package com.oracle.javafx.scenebuilder.kit.fxom; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; @@ -38,19 +39,31 @@ import org.junit.Test; +import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform; +import com.oracle.javafx.scenebuilder.kit.fxom.FXMLPropertiesDisabler.OperatingSystem; + public class FXMLPropertiesDisablerTest { private FXMLPropertiesDisabler classUnderTest = new FXMLPropertiesDisabler(); - + @Test - public void that_property_value_is_set_to_false() throws Exception { + public void that_property_value_is_set_to_false_on_MacOS() throws Exception { + classUnderTest = new FXMLPropertiesDisabler(OperatingSystem.MACOS); String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", - fxmlText.contains("")); - - String modfiedFxmlText = classUnderTest.disableUseSystemMenuBarProperty(fxmlText); - - assertTrue(modfiedFxmlText.contains("")); + 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(OperatingSystem.WINDOWS); + String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.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 { @@ -58,4 +71,27 @@ private String readResourceText(String resourceName) throws Exception { return Files.readString(fxmlFileName.toPath()); } + @Test + public void that_MacOS_is_detected_properly() { + if (EditorPlatform.IS_MAC) { + OperatingSystem os = OperatingSystem.get(); + assertEquals(OperatingSystem.MACOS, os); + } + } + + @Test + public void that_Windows_is_detected_properly() { + if (EditorPlatform.IS_WINDOWS) { + OperatingSystem os = OperatingSystem.get(); + assertEquals(OperatingSystem.WINDOWS, os); + } + } + + @Test + public void that_Linux_is_detected_properly() { + if (EditorPlatform.IS_LINUX) { + OperatingSystem os = OperatingSystem.get(); + assertEquals(OperatingSystem.LINUX, os); + } + } } 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 aac888be6..e88f7a3cd 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 @@ -107,8 +107,8 @@ public void that_normalization_is_applied_by_default() throws Exception { fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); - String generatedFxml = classUnderTest.getFxmlText(false).replace("\n", System.lineSeparator()); - String expectedFxml = readResourceText("Normalized_Accordion.fxml"); + String generatedFxml = extractContentsOfFirstChildrenTag(classUnderTest.getFxmlText(false)); + String expectedFxml = extractContentsOfFirstChildrenTag(readResourceText("Normalized_Accordion.fxml")); assertEquals(expectedFxml, generatedFxml); } @@ -118,17 +118,29 @@ public void that_normalization_is_disabled_when_created_with_NON_NORMALIZED() th fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle, FXOMDocumentSwitch.NON_NORMALIZED); - String generatedFxml = classUnderTest.getFxmlText(false).replace("\n", System.lineSeparator()); - String expectedFxml = readResourceText("NonNormalized_Accordion.fxml").replace("\n", System.lineSeparator()); + String generatedFxml = extractContentsOfFirstChildrenTag(classUnderTest.getFxmlText(false)); + String expectedFxml = extractContentsOfFirstChildrenTag(readResourceText("NonNormalized_Accordion.fxml")); assertEquals(expectedFxml, generatedFxml); } private String readResourceText(String resourceName) throws Exception { File fxmlFileName = new File(getResourceUrl(resourceName).toURI()); - return Files.readString(fxmlFileName.toPath()); + 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); + } } From e356320d903447bb096735e6d663cb170aa9e747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 5 Jan 2022 02:50:04 +0100 Subject: [PATCH 09/43] Updated OS specific test. --- .../kit/fxom/FXOMDocumentTest.java | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) 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 e88f7a3cd..49f7e5cf6 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 @@ -39,12 +39,14 @@ import java.net.URL; import java.nio.file.Files; import java.util.ResourceBundle; +import java.util.Set; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import com.oracle.javafx.scenebuilder.kit.JfxInitializer; +import com.oracle.javafx.scenebuilder.kit.fxom.FXMLPropertiesDisabler.OperatingSystem; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import javafx.scene.control.MenuBar; @@ -88,19 +90,40 @@ public void that_FOR_PREVIEW_useSystemMenuBarProperty_is_enabled() throws Except } @Test - public void that_by_default_useSystemMenuBarProperty_is_disabled() throws Exception { - 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\"")); + public void that_useSystemMenuBarProperty_is_disabled_on_MacOS() throws Exception { + OperatingSystem os = OperatingSystem.get(); + if (os.equals(OperatingSystem.MACOS)) { + 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_modifie_on_Linux_and_Windows() throws Exception { + OperatingSystem os = OperatingSystem.get(); + if (Set.of(OperatingSystem.LINUX, OperatingSystem.WINDOWS).contains(os)) { + 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_by_default() throws Exception { fxmlText = readResourceText("NonNormalized_Accordion.fxml"); From 074da204722d02703fc4fb9fb11f9fd67fe8f0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 5 Jan 2022 03:03:48 +0100 Subject: [PATCH 10/43] Added javadoc. --- .../javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java | 5 +++++ 1 file changed, 5 insertions(+) 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 index 0752370f2..f490eabd9 100644 --- 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 @@ -88,6 +88,11 @@ enum OperatingSystem { MACOS, WINDOWS, LINUX; + /** + * Obtains the operating system type from system property os.name. + * @return {@link OperatingSystem} + * @throws UnsupportedOperationException in case of an unknown operating system + */ public static OperatingSystem get() { String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT); if (osName.contains("linux")) { From 043da8c5ec146970ab51fd98a34211a549bbb067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 5 Jan 2022 03:17:34 +0100 Subject: [PATCH 11/43] Formatting. --- .../scenebuilder/kit/fxom/FXMLPropertiesDisabler.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 index f490eabd9..afd8e7dec 100644 --- 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 @@ -88,11 +88,12 @@ enum OperatingSystem { MACOS, WINDOWS, LINUX; - /** - * Obtains the operating system type from system property os.name. - * @return {@link OperatingSystem} - * @throws UnsupportedOperationException in case of an unknown operating system - */ + /** + * Obtains the operating system type from system property os.name. + * + * @return {@link OperatingSystem} + * @throws UnsupportedOperationException in case of an unknown operating system + */ public static OperatingSystem get() { String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT); if (osName.contains("linux")) { From 925490dd1845d175bc78c9d56513a73858bd96ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 5 Jan 2022 03:20:52 +0100 Subject: [PATCH 12/43] Applied checkstyle formatting. --- .../javafx/scenebuilder/kit/fxom/FXOMInstance.java | 6 +++--- .../javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java | 3 ++- .../oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java | 4 ++-- .../javafx/scenebuilder/kit/fxom/FXOMObject.java | 10 +++------- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java index 8ace788fb..8f679a59d 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -246,7 +246,7 @@ private void collectGlueElementPropertiesT(GlueElement element, Set> re if (element == null) { return; } - if (! element.getChildren().isEmpty()) { + if (!element.getChildren().isEmpty()) { for (GlueElement e : element.getChildren()) { collectGlueElementPropertiesT(e, result); } @@ -255,7 +255,7 @@ private void collectGlueElementPropertiesT(GlueElement element, Set> re if (clazz != null) { for (Class c : fxomDocument.getInitialDeclaredClasses()) { if (c.getCanonicalName().equals(clazz) || c.getSimpleName().equals(clazz)) { - if (! result.contains(c)) { + if (!result.contains(c)) { result.add(c); } break; diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java index 6f78629b4..baa2464ac 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java @@ -57,7 +57,8 @@ public enum Type { private Object sourceSceneGraphObject; - FXOMIntrinsic(FXOMDocument document, GlueElement glueElement, Object targetSceneGraphObject, List properties) { + FXOMIntrinsic(FXOMDocument document, GlueElement glueElement, Object targetSceneGraphObject, + List properties) { super(document, glueElement, null); this.sourceSceneGraphObject = targetSceneGraphObject; for (FXOMProperty p : properties) { 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..331f5f8aa 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 @@ -720,7 +720,7 @@ private static FXOMDocument makeFxomDocumentFromImageURL( fitWidth = 0; fitHeight = 0; } else { - final double widthScale = fitSize / imageSize; + final double widthScale = fitSize / imageSize; final double heightScale = fitSize / imageHeight; final double scale = Math.min(widthScale, heightScale); fitWidth = Math.floor(imageWidth * scale); @@ -784,7 +784,7 @@ private static FXOMDocument makeFxomDocumentFromMedia( fitWidth = 0; fitHeight = 0; } else { - final double widthScale = fitSize / mediaSize; + final double widthScale = fitSize / mediaSize; final double heightScale = fitSize / mediaHeight; final double scale = Math.min(widthScale, heightScale); fitWidth = Math.floor(mediaWidth * scale); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java index 662c3ede5..bb35bf5ed 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java @@ -289,14 +289,12 @@ public void moveBeforeSibling(FXOMObject sibling) { public Scene getScene() { final Scene result; - if (sceneGraphObject instanceof Node) { final Node sceneGraphNode = (Node) sceneGraphObject; result = sceneGraphNode.getScene(); - } else { + } else { result = null; - } - + } return result; } @@ -688,13 +686,11 @@ protected void changeFxomDocument(FXOMDocument destination) { assert destination != null; assert destination != getFxomDocument(); assert destination.getGlue() == glueElement.getDocument(); - assert (parentProperty == null) || (destination == parentProperty.getFxomDocument()); + assert (parentProperty == null) || (destination == parentProperty.getFxomDocument()); assert (parentCollection == null) || (destination == parentCollection.getFxomDocument()); - super.changeFxomDocument(destination); } - /* * Object */ From b074e421f6c7cb860ce1e001544f3de6c23b8665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Sun, 9 Jan 2022 09:54:15 +0100 Subject: [PATCH 13/43] Formatting corrected. --- .../scenebuilder/kit/fxom/FXMLPropertiesDisabler.java | 6 +++++- .../oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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 index afd8e7dec..d5e3780c7 100644 --- 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 @@ -35,13 +35,17 @@ import java.util.Objects; class FXMLPropertiesDisabler { + private final OperatingSystem os; + public FXMLPropertiesDisabler() { this(OperatingSystem.get()); } + public FXMLPropertiesDisabler(OperatingSystem os) { this.os = Objects.requireNonNull(os); } + /** * In some cases, during FXML Loading, certain properties must be disabled. * This method modifies the FXML source accordingly. @@ -55,7 +59,7 @@ public String disableProperties(String fxmlText) { 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. 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 069b865bf..09db8ae5c 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 @@ -462,7 +462,7 @@ public static interface SceneGraphHolder { * 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. - * This enum replaces the previously used boolean arguments in the {@link FXOMDocument} constructor. + * Replaces the previously used boolean arguments in the {@link FXOMDocument} constructor. */ public enum FXOMDocumentSwitch { /** From c70fd943ab6d9c82c235a41ca392c1f369a867b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Sun, 9 Jan 2022 16:54:23 +0100 Subject: [PATCH 14/43] Removed the Operating System enum. --- .../kit/fxom/FXMLPropertiesDisabler.java | 42 ++++--------------- .../scenebuilder/kit/fxom/FXOMDocument.java | 3 +- .../kit/fxom/FXMLPropertiesDisablerTest.java | 36 +++------------- .../kit/fxom/FXOMDocumentTest.java | 13 +++--- 4 files changed, 21 insertions(+), 73 deletions(-) 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 index d5e3780c7..bc66cf8eb 100644 --- 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 @@ -31,19 +31,18 @@ */ package com.oracle.javafx.scenebuilder.kit.fxom; -import java.util.Locale; import java.util.Objects; class FXMLPropertiesDisabler { - - private final OperatingSystem os; - public FXMLPropertiesDisabler() { - this(OperatingSystem.get()); - } + private final boolean isMacOS; - public FXMLPropertiesDisabler(OperatingSystem os) { - this.os = Objects.requireNonNull(os); + /** + * + * @param isMacOS true when used platform is MacOS + */ + public FXMLPropertiesDisabler(boolean isMacOS) { + this.isMacOS = isMacOS; } /** @@ -81,35 +80,10 @@ public String disableProperties(String fxmlText) { */ private String disableUseSystemMenuBarProperty(String fxmlText) { Objects.requireNonNull(fxmlText, "fxmlText must not be null"); - if (OperatingSystem.MACOS.equals(os)) { + if (isMacOS) { return fxmlText.replace("useSystemMenuBar=\"true\"", "useSystemMenuBar=\"false\""); } return fxmlText; } - - enum OperatingSystem { - MACOS, - WINDOWS, - LINUX; - /** - * Obtains the operating system type from system property os.name. - * - * @return {@link OperatingSystem} - * @throws UnsupportedOperationException in case of an unknown operating system - */ - public static OperatingSystem get() { - String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT); - if (osName.contains("linux")) { - return OperatingSystem.LINUX; - } - if (osName.contains("mac")) { - return OperatingSystem.MACOS; - } - if (osName.contains("windows")) { - return OperatingSystem.WINDOWS; - } - throw new UnsupportedOperationException("Unknown operating system platform!"); - } - } } 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 09db8ae5c..ce3e86985 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 @@ -104,7 +104,8 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso if (this.glue.getRootElement() != null) { String fxmlTextToLoad = fxmlText; if (!Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { - final FXMLPropertiesDisabler fxmlPropertiesDisabler = new FXMLPropertiesDisabler(); + boolean isMacOS = EditorPlatform.IS_MAC; + final FXMLPropertiesDisabler fxmlPropertiesDisabler = new FXMLPropertiesDisabler(isMacOS); fxmlTextToLoad = fxmlPropertiesDisabler.disableProperties(fxmlText); } final FXOMLoader loader = new FXOMLoader(this); 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 index 4e802783e..be9263359 100644 --- 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 @@ -31,7 +31,6 @@ */ package com.oracle.javafx.scenebuilder.kit.fxom; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; @@ -39,16 +38,14 @@ import org.junit.Test; -import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform; -import com.oracle.javafx.scenebuilder.kit.fxom.FXMLPropertiesDisabler.OperatingSystem; - public class FXMLPropertiesDisablerTest { - private FXMLPropertiesDisabler classUnderTest = new FXMLPropertiesDisabler(); + private FXMLPropertiesDisabler classUnderTest; @Test public void that_property_value_is_set_to_false_on_MacOS() throws Exception { - classUnderTest = new FXMLPropertiesDisabler(OperatingSystem.MACOS); + boolean isMacOS = true; + classUnderTest = new FXMLPropertiesDisabler(isMacOS); String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", fxmlText.contains("")); @@ -58,7 +55,8 @@ public void that_property_value_is_set_to_false_on_MacOS() throws Exception { @Test public void that_property_value_is_not_modified_on_Windows() throws Exception { - classUnderTest = new FXMLPropertiesDisabler(OperatingSystem.WINDOWS); + boolean isMacOS = false; + classUnderTest = new FXMLPropertiesDisabler(isMacOS); String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", fxmlText.contains("")); @@ -70,28 +68,4 @@ private String readResourceText(String resourceName) throws Exception { File fxmlFileName = new File(getClass().getResource(resourceName).toURI()); return Files.readString(fxmlFileName.toPath()); } - - @Test - public void that_MacOS_is_detected_properly() { - if (EditorPlatform.IS_MAC) { - OperatingSystem os = OperatingSystem.get(); - assertEquals(OperatingSystem.MACOS, os); - } - } - - @Test - public void that_Windows_is_detected_properly() { - if (EditorPlatform.IS_WINDOWS) { - OperatingSystem os = OperatingSystem.get(); - assertEquals(OperatingSystem.WINDOWS, os); - } - } - - @Test - public void that_Linux_is_detected_properly() { - if (EditorPlatform.IS_LINUX) { - OperatingSystem os = OperatingSystem.get(); - assertEquals(OperatingSystem.LINUX, os); - } - } } 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 49f7e5cf6..af367bbf1 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 @@ -39,14 +39,13 @@ import java.net.URL; import java.nio.file.Files; import java.util.ResourceBundle; -import java.util.Set; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import com.oracle.javafx.scenebuilder.kit.JfxInitializer; -import com.oracle.javafx.scenebuilder.kit.fxom.FXMLPropertiesDisabler.OperatingSystem; +import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import javafx.scene.control.MenuBar; @@ -91,8 +90,8 @@ public void that_FOR_PREVIEW_useSystemMenuBarProperty_is_enabled() throws Except @Test public void that_useSystemMenuBarProperty_is_disabled_on_MacOS() throws Exception { - OperatingSystem os = OperatingSystem.get(); - if (os.equals(OperatingSystem.MACOS)) { + boolean isMacOS = EditorPlatform.IS_MAC; + if (isMacOS) { classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); @@ -107,9 +106,9 @@ public void that_useSystemMenuBarProperty_is_disabled_on_MacOS() throws Exceptio } @Test - public void that_useSystemMenuBarProperty_not_modifie_on_Linux_and_Windows() throws Exception { - OperatingSystem os = OperatingSystem.get(); - if (Set.of(OperatingSystem.LINUX, OperatingSystem.WINDOWS).contains(os)) { + public void that_useSystemMenuBarProperty_not_modified_on_Linux_and_Windows() throws Exception { + boolean isWinOrLinux = EditorPlatform.IS_WINDOWS | EditorPlatform.IS_LINUX; + if (isWinOrLinux) { classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); From 333c73d027c235250ff994623efa1bd133ab6167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Sun, 9 Jan 2022 17:06:00 +0100 Subject: [PATCH 15/43] Removed the NON_NORMALIZED FXOMDocumenzSwitch. Previously, normalization was the default behavior, now normalization is only applied when the switch is present. --- .../scenebuilder/kit/fxom/FXOMDocument.java | 12 ++-- .../scenebuilder/kit/fxom/FXOMRefresher.java | 4 +- .../kit/preview/PreviewWindowController.java | 2 +- .../kit/fxom/FXOMDocumentTest.java | 60 +++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) 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 ce3e86985..edebe7530 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 @@ -84,7 +84,9 @@ public class FXOMDocument { /** * 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. + * 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 @@ -92,7 +94,7 @@ public class FXOMDocument { * @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. disabling normalization) + * (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 { @@ -110,7 +112,7 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso } final FXOMLoader loader = new FXOMLoader(this); loader.load(fxmlTextToLoad); - if (!Set.of(switches).contains(FXOMDocumentSwitch.NON_NORMALIZED)) { + if (Set.of(switches).contains(FXOMDocumentSwitch.NORMALIZED)) { final FXOMNormalizer normalizer = new FXOMNormalizer(this); normalizer.normalize(); } @@ -467,9 +469,9 @@ public static interface SceneGraphHolder { */ public enum FXOMDocumentSwitch { /** - * If this switch is defined, the {@link FXOMDocument} will not be normalized (see {@link FXOMNormalizer}). + * If this switch is defined, the {@link FXOMDocument} will be normalized (see {@link FXOMNormalizer}). */ - NON_NORMALIZED, + NORMALIZED, /** * When this flag is present during {@link FXOMDocument} creation, 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 53a039c86..153cc3c7e 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 @@ -32,7 +32,6 @@ */ package com.oracle.javafx.scenebuilder.kit.fxom; -import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import com.oracle.javafx.scenebuilder.kit.metadata.Metadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.ValuePropertyMetadata; import com.oracle.javafx.scenebuilder.kit.metadata.property.value.DoubleArrayPropertyMetadata; @@ -65,8 +64,7 @@ public void refresh(FXOMDocument document) { = new FXOMDocument(fxmlText, document.getLocation(), document.getClassLoader(), - document.getResources(), - FXOMDocumentSwitch.NON_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/preview/PreviewWindowController.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java index 1de97cb4c..9d2dac318 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 @@ -216,7 +216,7 @@ public void openDialog() { fxomDocument.getLocation(), fxomDocument.getClassLoader(), fxomDocument.getResources(), - FXOMDocumentSwitch.FOR_PREVIEW); + FXOMDocumentSwitch.FOR_PREVIEW, FXOMDocumentSwitch.NORMALIZED); clone.setSampleDataEnabled(fxomDocument.isSampleDataEnabled()); } catch (IOException ex) { throw new RuntimeException("Bug in PreviewWindowController::openDialog", ex); //NOI18N 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 af367bbf1..50211e501 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 @@ -90,44 +90,44 @@ public void that_FOR_PREVIEW_useSystemMenuBarProperty_is_enabled() throws Except @Test public void that_useSystemMenuBarProperty_is_disabled_on_MacOS() throws Exception { - boolean isMacOS = EditorPlatform.IS_MAC; - if (isMacOS) { - 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\"")); - } + boolean isMacOS = EditorPlatform.IS_MAC; + if (isMacOS) { + 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 { - boolean isWinOrLinux = EditorPlatform.IS_WINDOWS | EditorPlatform.IS_LINUX; - if (isWinOrLinux) { - 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\"")); - } + boolean isWinOrLinux = EditorPlatform.IS_WINDOWS | EditorPlatform.IS_LINUX; + if (isWinOrLinux) { + 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_by_default() throws Exception { + public void that_normalization_is_applied_only_when_NORMALIZED_is_set() throws Exception { fxmlText = readResourceText("NonNormalized_Accordion.fxml"); fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); - classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle, FXOMDocumentSwitch.NORMALIZED); String generatedFxml = extractContentsOfFirstChildrenTag(classUnderTest.getFxmlText(false)); String expectedFxml = extractContentsOfFirstChildrenTag(readResourceText("Normalized_Accordion.fxml")); @@ -135,10 +135,10 @@ public void that_normalization_is_applied_by_default() throws Exception { } @Test - public void that_normalization_is_disabled_when_created_with_NON_NORMALIZED() throws Exception { + public void that_normalization_is_disabled_when_NORMALIZED_is_not_set() throws Exception { fxmlText = readResourceText("NonNormalized_Accordion.fxml"); fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); - classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle, FXOMDocumentSwitch.NON_NORMALIZED); + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); String generatedFxml = extractContentsOfFirstChildrenTag(classUnderTest.getFxmlText(false)); String expectedFxml = extractContentsOfFirstChildrenTag(readResourceText("NonNormalized_Accordion.fxml")); From 55c8cd02108d74684286e6ae931d0b416e1c1d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Sun, 9 Jan 2022 17:15:41 +0100 Subject: [PATCH 16/43] Javadoc rework. --- .../javafx/scenebuilder/kit/fxom/FXOMDocument.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 edebe7530..088c0c2f7 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 @@ -465,19 +465,19 @@ public static interface SceneGraphHolder { * 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. - * Replaces the previously used boolean arguments in the {@link FXOMDocument} constructor. */ public enum FXOMDocumentSwitch { /** - * If this switch is defined, the {@link FXOMDocument} will be normalized (see {@link FXOMNormalizer}). + * 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 prepare the FXML source in a way, - * so that settings defined in the FXML will not interfere Scene Builders configuration. - * One possible example here is the option to use the MacOS system menu bar. + * 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; } From d82aee6264e8c8c070de3fa3f71561708cceecc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Wed, 12 Jan 2022 23:30:51 +0100 Subject: [PATCH 17/43] Javadoc added. --- .../javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 index bc66cf8eb..90b089e55 100644 --- 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 @@ -33,12 +33,15 @@ import java.util.Objects; +/** + * Modifies FXML to be loaded so that properties in the FXML will not interfere + * with Scene Builder. + */ class FXMLPropertiesDisabler { private final boolean isMacOS; /** - * * @param isMacOS true when used platform is MacOS */ public FXMLPropertiesDisabler(boolean isMacOS) { From 1adc6a544c86326221e2db13846fa28ede7f12a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 14:39:52 +0100 Subject: [PATCH 18/43] Introduced OS name enum. --- .../javafx/scenebuilder/kit/editor/EditorPlatform.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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..ef1067162 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 @@ -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 From ee6c66cb873fbb17e0c81a1780dfbe571738e818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 14:56:09 +0100 Subject: [PATCH 19/43] Reworked test to consider new OS enum. --- .../kit/fxom/FXMLPropertiesDisabler.java | 20 ++++++++++++++----- .../scenebuilder/kit/fxom/FXOMDocument.java | 4 ++-- .../kit/fxom/FXMLPropertiesDisablerTest.java | 8 ++++---- 3 files changed, 21 insertions(+), 11 deletions(-) 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 index 90b089e55..cdd1ab123 100644 --- 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 @@ -33,19 +33,29 @@ 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 boolean isMacOS; + private final OS os; + + /** + * Creates a new FXMLPropertiesDisable which is aware of the platform and can + * according to required platform behavior. + */ + public FXMLPropertiesDisabler() { + this.os = OS.get(); + } /** - * @param isMacOS true when used platform is MacOS + * @param os Operating system where Scene Builder is executed */ - public FXMLPropertiesDisabler(boolean isMacOS) { - this.isMacOS = isMacOS; + FXMLPropertiesDisabler(OS os) { + this.os = Objects.requireNonNull(os); } /** @@ -83,7 +93,7 @@ public String disableProperties(String fxmlText) { */ private String disableUseSystemMenuBarProperty(String fxmlText) { Objects.requireNonNull(fxmlText, "fxmlText must not be null"); - if (isMacOS) { + if (OS.MAC == os) { return fxmlText.replace("useSystemMenuBar=\"true\"", "useSystemMenuBar=\"false\""); } 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 088c0c2f7..625b48ab1 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 @@ -47,6 +47,7 @@ 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; @@ -106,8 +107,7 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso if (this.glue.getRootElement() != null) { String fxmlTextToLoad = fxmlText; if (!Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { - boolean isMacOS = EditorPlatform.IS_MAC; - final FXMLPropertiesDisabler fxmlPropertiesDisabler = new FXMLPropertiesDisabler(isMacOS); + final FXMLPropertiesDisabler fxmlPropertiesDisabler = new FXMLPropertiesDisabler(); fxmlTextToLoad = fxmlPropertiesDisabler.disableProperties(fxmlText); } final FXOMLoader loader = new FXOMLoader(this); 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 index be9263359..6c3073443 100644 --- 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 @@ -38,14 +38,15 @@ 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 { - boolean isMacOS = true; - classUnderTest = new FXMLPropertiesDisabler(isMacOS); + classUnderTest = new FXMLPropertiesDisabler(OS.MAC); String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", fxmlText.contains("")); @@ -55,8 +56,7 @@ public void that_property_value_is_set_to_false_on_MacOS() throws Exception { @Test public void that_property_value_is_not_modified_on_Windows() throws Exception { - boolean isMacOS = false; - classUnderTest = new FXMLPropertiesDisabler(isMacOS); + classUnderTest = new FXMLPropertiesDisabler(OS.WINDOWS); String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", fxmlText.contains("")); From e1db7b68d5005c1ca9e7fa9432ae25cbba29b14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 14:58:59 +0100 Subject: [PATCH 20/43] Fixed typo. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java index 8f679a59d..de1aad02b 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: From fc4106ab1cb41e414ea129a6b6fed3ad6c78d95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 14:59:34 +0100 Subject: [PATCH 21/43] Copyright updated. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java index baa2464ac..192e8c1ca 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. + * Copyright (c) 2012, 2022, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: From 44baa62a8799fdfcf5eb8169a9e69a49a817ef47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 15:02:25 +0100 Subject: [PATCH 22/43] Reverted formatting changes. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java index 9e548d83f..0fa6dcaf7 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMLoader.java @@ -312,7 +312,7 @@ public void readPropertyAttribute(String name, Class staticClass, String fxml } else if (currentTransientNode instanceof TransientProperty) { final TransientProperty transientProperty = (TransientProperty) currentTransientNode; transientProperty.getCollectedProperties().add(fxomProperty); - } else if (currentTransientNode instanceof TransientIntrinsic) { + } else if(currentTransientNode instanceof TransientIntrinsic) { final TransientIntrinsic transientIntrinsic = (TransientIntrinsic) currentTransientNode; transientIntrinsic.getProperties().add(fxomProperty); } From afd72f7a4a1d03ec03e202aa882e02d34ba7f102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 15:07:33 +0100 Subject: [PATCH 23/43] Header updated. Merge errors fixed. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java | 2 +- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMRefresher.java | 2 +- .../scenebuilder/kit/preview/PreviewWindowController.java | 2 +- .../oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) 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 331f5f8aa..d635539e1 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,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. + * Copyright (c) 2012, 2022, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: 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 153cc3c7e..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, 2021, 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. * 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 9d2dac318..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, 2021, 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. * 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 6a26afeb0..fb65db151 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,6 +1,5 @@ /* -<<<<<<< HEAD - * Copyright (c) 2021, Gluon and/or its affiliates. + * 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: From b36f01d2438297967433aed3f4cf73288a2cf71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 15:27:34 +0100 Subject: [PATCH 24/43] Spaces removed --- .../scenebuilder/kit/fxom/FXMLPropertiesDisablerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 6c3073443..1573f7757 100644 --- 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 @@ -53,7 +53,7 @@ public void that_property_value_is_set_to_false_on_MacOS() throws Exception { 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); From 98d9b57bd5116f1e01b3147b03fa3bd4d0c7645e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 15:29:07 +0100 Subject: [PATCH 25/43] Replaced platform checks with JUnit Assumptions. --- .../kit/fxom/FXOMDocumentTest.java | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) 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 fb65db151..1df6bb621 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 @@ -36,12 +36,14 @@ 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; @@ -51,7 +53,7 @@ import org.xml.sax.SAXParseException; import com.oracle.javafx.scenebuilder.kit.JfxInitializer; -import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform; +import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.OS; import com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.FXOMDocumentSwitch; import javafx.application.Platform; @@ -98,39 +100,36 @@ public void that_FOR_PREVIEW_useSystemMenuBarProperty_is_enabled() throws Except @Test public void that_useSystemMenuBarProperty_is_disabled_on_MacOS() throws Exception { - boolean isMacOS = EditorPlatform.IS_MAC; - if (isMacOS) { - classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); + assumeTrue("MacOS", OS.get() == OS.MAC); + + classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); - FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); + FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); - assertTrue(fxomObject.getSceneGraphObject() instanceof MenuBar); - assertFalse("for preview, useSystemMenu is expected to be enabled", - ((MenuBar) fxomObject.getSceneGraphObject()).useSystemMenuBarProperty().get()); + 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\"")); - } + String generatedFxml = classUnderTest.getFxmlText(false); + assertTrue(generatedFxml.contains("useSystemMenuBar=\"true\"")); } - + @Test public void that_useSystemMenuBarProperty_not_modified_on_Linux_and_Windows() throws Exception { - boolean isWinOrLinux = EditorPlatform.IS_WINDOWS | EditorPlatform.IS_LINUX; - if (isWinOrLinux) { - classUnderTest = new FXOMDocument(fxmlText, fxmlUrl, loader, resourceBundle); + 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"); + FXOMObject fxomObject = classUnderTest.searchWithFxId("theMenuBar"); - assertTrue(fxomObject.getSceneGraphObject() instanceof MenuBar); - assertTrue("for preview, useSystemMenu is expected to be enabled", - ((MenuBar) fxomObject.getSceneGraphObject()).useSystemMenuBarProperty().get()); + 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\"")); - } + 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("NonNormalized_Accordion.fxml"); @@ -161,7 +160,7 @@ private String readResourceText(String resourceName) throws Exception { private URL getResourceUrl(String resourceName) { return getClass().getResource(resourceName); } - + private String useOnlyNewLine(String source) { return source.replace("\r\n", "\n"); } @@ -285,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()) { From 6d3453a1d08570a064ac8febab51c78a48f368ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 15:31:03 +0100 Subject: [PATCH 26/43] Header update --- .../oracle/javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1df6bb621..6e4153118 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: From dfbeca1b42acacfe2babad924a6e6a16aac16595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 15:36:14 +0100 Subject: [PATCH 27/43] Reverted changes. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java index de1aad02b..8ace788fb 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMInstance.java @@ -246,7 +246,7 @@ private void collectGlueElementPropertiesT(GlueElement element, Set> re if (element == null) { return; } - if (!element.getChildren().isEmpty()) { + if (! element.getChildren().isEmpty()) { for (GlueElement e : element.getChildren()) { collectGlueElementPropertiesT(e, result); } @@ -255,7 +255,7 @@ private void collectGlueElementPropertiesT(GlueElement element, Set> re if (clazz != null) { for (Class c : fxomDocument.getInitialDeclaredClasses()) { if (c.getCanonicalName().equals(clazz) || c.getSimpleName().equals(clazz)) { - if (!result.contains(c)) { + if (! result.contains(c)) { result.add(c); } break; From b9fd009af6ca4f226f04b211525fbddef0ba4f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 15:39:31 +0100 Subject: [PATCH 28/43] Added test. --- .../kit/fxom/FXMLPropertiesDisablerTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 index 1573f7757..0cb043366 100644 --- 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 @@ -64,6 +64,16 @@ public void that_property_value_is_not_modified_on_Windows() throws Exception { assertTrue(modfiedFxmlText.contains("")); } + @Test + public void that_property_value_is_not_modified_on_LINUX() throws Exception { + classUnderTest = new FXMLPropertiesDisabler(OS.LINUX); + String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.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()); From 1bfe40b26642733af92736646081f4003c1a242a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 17:56:58 +0100 Subject: [PATCH 29/43] FXMLPropertiesDisabler now uses an approach with a regular expression to perform the replacement. Added a parameterized test accordingly. --- .../kit/fxom/FXMLPropertiesDisabler.java | 13 ++- .../FXMLPropertiesDisablerVariationsTest.java | 97 +++++++++++++++++++ 2 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerVariationsTest.java 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 index cdd1ab123..79edaec76 100644 --- 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 @@ -94,8 +94,17 @@ public String disableProperties(String fxmlText) { private String disableUseSystemMenuBarProperty(String fxmlText) { Objects.requireNonNull(fxmlText, "fxmlText must not be null"); if (OS.MAC == os) { - return fxmlText.replace("useSystemMenuBar=\"true\"", - "useSystemMenuBar=\"false\""); + /* + * 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/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..755e63a3a --- /dev/null +++ b/kit/src/test/java/com/oracle/javafx/scenebuilder/kit/fxom/FXMLPropertiesDisablerVariationsTest.java @@ -0,0 +1,97 @@ +/* + * 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); + } +} From e61fd4c4e08a97cc3c985eb5b31b2617eb6302bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 18:17:07 +0100 Subject: [PATCH 30/43] Enabled useSystemMenuBar as an inspectable for MenuBar. --- .../javafx/scenebuilder/kit/metadata/Metadata.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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..8820046fd 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 = @@ -4470,7 +4472,12 @@ public boolean isPropertyTrimmingNeeded(PropertyName name) { com.oracle.javafx.scenebuilder.kit.metadata.property.value.DoublePropertyMetadata.DoubleKind.COORDINATE, true, /* readWrite */ 100.0, /* defaultValue */ - new InspectorPath("Properties", "Specific", 98)); + new InspectorPath("Properties", "Specific", 10)); + private final ValuePropertyMetadata useSystemMenuBarNamePropertyMetadata = + new BooleanPropertyMetadata(useSystemMenuBarName, + true, /* readWrite */ + false, + new InspectorPath("Properties", "Specific", 70)); 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(useSystemMenuBarNamePropertyMetadata); MenuButtonMetadata.getProperties().add(accessibleRole_MENU_BUTTON_PropertyMetadata); MenuButtonMetadata.getProperties().add(focusTraversable_true_PropertyMetadata); From 93a8a40f667a8316200988c0468d88810b221aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 20:15:06 +0100 Subject: [PATCH 31/43] Header updated. --- .../oracle/javafx/scenebuilder/kit/editor/EditorPlatform.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ef1067162..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. * From 1a723d77e94041a4b3fbfe0caaf38744d12f1606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 20:17:36 +0100 Subject: [PATCH 32/43] refactor: constructor chained --- .../javafx/scenebuilder/kit/fxom/FXMLPropertiesDisabler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 79edaec76..45833d07c 100644 --- 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 @@ -48,7 +48,7 @@ class FXMLPropertiesDisabler { * according to required platform behavior. */ public FXMLPropertiesDisabler() { - this.os = OS.get(); + this(OS.get()); } /** From 0e244b9128a82d87aedd10c44abfa9e7ae9419de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 20:19:03 +0100 Subject: [PATCH 33/43] feat+refactor: useSystemMenuProperty to be treated as node property, renamed property meta data instance accordingly --- .../oracle/javafx/scenebuilder/kit/metadata/Metadata.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 8820046fd..464f095f7 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 @@ -4473,11 +4473,11 @@ public boolean isPropertyTrimmingNeeded(PropertyName name) { true, /* readWrite */ 100.0, /* defaultValue */ new InspectorPath("Properties", "Specific", 10)); - private final ValuePropertyMetadata useSystemMenuBarNamePropertyMetadata = + private final ValuePropertyMetadata useSystemMenuBarPropertyMetadata = new BooleanPropertyMetadata(useSystemMenuBarName, true, /* readWrite */ false, - new InspectorPath("Properties", "Specific", 70)); + new InspectorPath("Properties", "Node", 25)); private final ValuePropertyMetadata userAgentStylesheetPropertyMetadata = new StringPropertyMetadata( userAgentStylesheetName, @@ -5419,7 +5419,7 @@ private Metadata() { MenuBarMetadata.getProperties().add(accessibleRole_MENU_BAR_PropertyMetadata); MenuBarMetadata.getProperties().add(menusPropertyMetadata); MenuBarMetadata.getProperties().add(styleClass_c18_PropertyMetadata); - MenuBarMetadata.getProperties().add(useSystemMenuBarNamePropertyMetadata); + MenuBarMetadata.getProperties().add(useSystemMenuBarPropertyMetadata); MenuButtonMetadata.getProperties().add(accessibleRole_MENU_BUTTON_PropertyMetadata); MenuButtonMetadata.getProperties().add(focusTraversable_true_PropertyMetadata); From 3b4c5bc7acf8fdc70fd02aaa277785964ec72c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 20:23:45 +0100 Subject: [PATCH 34/43] feat: removed "useSystemMenuBar" from hidden properties --- .../com/oracle/javafx/scenebuilder/kit/metadata/Metadata.java | 1 - 1 file changed, 1 deletion(-) 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 464f095f7..876f53afb 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 @@ -6278,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")); From 97512d53bfba927770b6a778d6bc51675d0db710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 20:24:56 +0100 Subject: [PATCH 35/43] refactor: removed empty lines between fields --- .../kit/fxom/FXMLPropertiesDisablerVariationsTest.java | 3 --- 1 file changed, 3 deletions(-) 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 index 755e63a3a..612d0d93b 100644 --- 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 @@ -74,11 +74,8 @@ public static List data() { } private String id; - private OS os; - private String input; - private String expected; public FXMLPropertiesDisablerVariationsTest(String id, String osName, String input, String expected) { From 82b285bbff34f40fd695fd38ad6ebf83ae890bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Thu, 13 Jan 2022 20:26:17 +0100 Subject: [PATCH 36/43] refator: removed underscore in test file name --- .../scenebuilder/kit/fxom/FXMLPropertiesDisablerTest.java | 6 +++--- .../javafx/scenebuilder/kit/fxom/FXOMDocumentTest.java | 2 +- ...bled.fxml => ContainerWithMenuSystemMenuBarEnabled.fxml} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/{ContainerWithMenu_SystemMenuBarEnabled.fxml => ContainerWithMenuSystemMenuBarEnabled.fxml} (100%) 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 index 0cb043366..698110ee1 100644 --- 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 @@ -47,7 +47,7 @@ public class FXMLPropertiesDisablerTest { @Test public void that_property_value_is_set_to_false_on_MacOS() throws Exception { classUnderTest = new FXMLPropertiesDisabler(OS.MAC); - String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); + String fxmlText = readResourceText("ContainerWithMenuSystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", fxmlText.contains("")); String modfiedFxmlText = classUnderTest.disableProperties(fxmlText); @@ -57,7 +57,7 @@ public void that_property_value_is_set_to_false_on_MacOS() throws Exception { @Test public void that_property_value_is_not_modified_on_Windows() throws Exception { classUnderTest = new FXMLPropertiesDisabler(OS.WINDOWS); - String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); + String fxmlText = readResourceText("ContainerWithMenuSystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", fxmlText.contains("")); String modfiedFxmlText = classUnderTest.disableProperties(fxmlText); @@ -67,7 +67,7 @@ public void that_property_value_is_not_modified_on_Windows() throws Exception { @Test public void that_property_value_is_not_modified_on_LINUX() throws Exception { classUnderTest = new FXMLPropertiesDisabler(OS.LINUX); - String fxmlText = readResourceText("ContainerWithMenu_SystemMenuBarEnabled.fxml"); + String fxmlText = readResourceText("ContainerWithMenuSystemMenuBarEnabled.fxml"); assertTrue("ensures that test resource is correct", fxmlText.contains("")); String modfiedFxmlText = classUnderTest.disableProperties(fxmlText); 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 6e4153118..f92aa4a84 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 @@ -77,7 +77,7 @@ public static void init() { @Before public void prepareTest() throws Exception { - fxmlName = "ContainerWithMenu_SystemMenuBarEnabled.fxml"; + fxmlName = "ContainerWithMenuSystemMenuBarEnabled.fxml"; fxmlUrl = getResourceUrl(fxmlName); fxmlText = readResourceText(fxmlName); loader = this.getClass().getClassLoader(); diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenu_SystemMenuBarEnabled.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenuSystemMenuBarEnabled.fxml similarity index 100% rename from kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenu_SystemMenuBarEnabled.fxml rename to kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/ContainerWithMenuSystemMenuBarEnabled.fxml From f6c34ad6fc45ecd9019007e8595829bb878d2ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Fri, 14 Jan 2022 08:40:15 +0100 Subject: [PATCH 37/43] Javadoc cleanup --- .../scenebuilder/kit/fxom/FXMLPropertiesDisabler.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 index 45833d07c..6833edb82 100644 --- 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 @@ -44,15 +44,20 @@ class FXMLPropertiesDisabler { private final OS os; /** - * Creates a new FXMLPropertiesDisable which is aware of the platform and can - * according to required platform behavior. + * 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()); } /** - * @param os Operating system where Scene Builder is executed + * 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); From 18006655976dcbddeaf7c118c4042687f8992682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Fri, 14 Jan 2022 08:42:49 +0100 Subject: [PATCH 38/43] Reverted formatting changes. --- .../javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java | 5 ++--- .../oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java | 6 +++--- .../javafx/scenebuilder/kit/fxom/FXOMObject.java | 10 +++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java index 192e8c1ca..6f78629b4 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMIntrinsic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -57,8 +57,7 @@ public enum Type { private Object sourceSceneGraphObject; - FXOMIntrinsic(FXOMDocument document, GlueElement glueElement, Object targetSceneGraphObject, - List properties) { + FXOMIntrinsic(FXOMDocument document, GlueElement glueElement, Object targetSceneGraphObject, List properties) { super(document, glueElement, null); this.sourceSceneGraphObject = targetSceneGraphObject; for (FXOMProperty p : properties) { 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 d635539e1..1da228dc7 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,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -720,7 +720,7 @@ private static FXOMDocument makeFxomDocumentFromImageURL( fitWidth = 0; fitHeight = 0; } else { - final double widthScale = fitSize / imageSize; + final double widthScale = fitSize / imageSize; final double heightScale = fitSize / imageHeight; final double scale = Math.min(widthScale, heightScale); fitWidth = Math.floor(imageWidth * scale); @@ -784,7 +784,7 @@ private static FXOMDocument makeFxomDocumentFromMedia( fitWidth = 0; fitHeight = 0; } else { - final double widthScale = fitSize / mediaSize; + final double widthScale = fitSize / mediaSize; final double heightScale = fitSize / mediaHeight; final double scale = Math.min(widthScale, heightScale); fitWidth = Math.floor(mediaWidth * scale); diff --git a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java index bb35bf5ed..662c3ede5 100644 --- a/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java +++ b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMObject.java @@ -289,12 +289,14 @@ public void moveBeforeSibling(FXOMObject sibling) { public Scene getScene() { final Scene result; + if (sceneGraphObject instanceof Node) { final Node sceneGraphNode = (Node) sceneGraphObject; result = sceneGraphNode.getScene(); - } else { + } else { result = null; - } + } + return result; } @@ -686,11 +688,13 @@ protected void changeFxomDocument(FXOMDocument destination) { assert destination != null; assert destination != getFxomDocument(); assert destination.getGlue() == glueElement.getDocument(); - assert (parentProperty == null) || (destination == parentProperty.getFxomDocument()); + assert (parentProperty == null) || (destination == parentProperty.getFxomDocument()); assert (parentCollection == null) || (destination == parentCollection.getFxomDocument()); + super.changeFxomDocument(destination); } + /* * Object */ From dfb4f192cd2e31c6cbd48d7990365e287a6ddc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Fri, 14 Jan 2022 08:47:01 +0100 Subject: [PATCH 39/43] Reverted accidental modification of inspector path setting --- .../com/oracle/javafx/scenebuilder/kit/metadata/Metadata.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 876f53afb..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 @@ -4472,7 +4472,7 @@ public boolean isPropertyTrimmingNeeded(PropertyName name) { com.oracle.javafx.scenebuilder.kit.metadata.property.value.DoublePropertyMetadata.DoubleKind.COORDINATE, true, /* readWrite */ 100.0, /* defaultValue */ - new InspectorPath("Properties", "Specific", 10)); + new InspectorPath("Properties", "Specific", 98)); private final ValuePropertyMetadata useSystemMenuBarPropertyMetadata = new BooleanPropertyMetadata(useSystemMenuBarName, true, /* readWrite */ From da9738a019dcdd8496a3dabe1b339a096cd80df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Fri, 14 Jan 2022 08:49:52 +0100 Subject: [PATCH 40/43] Removed underscore from test file names. --- .../scenebuilder/kit/fxom/FXOMDocumentTest.java | 12 ++++++------ ...ed_Accordion.fxml => NonNormalizedAccordion.fxml} | 0 ...lized_Accordion.fxml => NormalizedAccordion.fxml} | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/{NonNormalized_Accordion.fxml => NonNormalizedAccordion.fxml} (100%) rename kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/{Normalized_Accordion.fxml => NormalizedAccordion.fxml} (100%) 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 f92aa4a84..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 @@ -132,23 +132,23 @@ public void that_useSystemMenuBarProperty_not_modified_on_Linux_and_Windows() th @Test public void that_normalization_is_applied_only_when_NORMALIZED_is_set() throws Exception { - fxmlText = readResourceText("NonNormalized_Accordion.fxml"); - fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); + 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("Normalized_Accordion.fxml")); + 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("NonNormalized_Accordion.fxml"); - fxmlUrl = getResourceUrl("NonNormalized_Accordion.fxml"); + 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("NonNormalized_Accordion.fxml")); + String expectedFxml = extractContentsOfFirstChildrenTag(readResourceText("NonNormalizedAccordion.fxml")); assertEquals(expectedFxml, generatedFxml); } diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalized_Accordion.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalizedAccordion.fxml similarity index 100% rename from kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalized_Accordion.fxml rename to kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NonNormalizedAccordion.fxml diff --git a/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/Normalized_Accordion.fxml b/kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NormalizedAccordion.fxml similarity index 100% rename from kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/Normalized_Accordion.fxml rename to kit/src/test/resources/com/oracle/javafx/scenebuilder/kit/fxom/NormalizedAccordion.fxml From afa27e0d92f80ae0b350c268a6255b7d78bfd832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20L=C3=B6ffler?= Date: Fri, 14 Jan 2022 09:54:07 +0100 Subject: [PATCH 41/43] All FXOMDocument constructor calls updated in order to use the NORMALIZED flag if needed. --- .../scenebuilder/kit/editor/EditorController.java | 5 +++-- .../kit/editor/job/AddContextMenuToSelectionJob.java | 5 ++++- .../kit/editor/job/AddTooltipToSelectionJob.java | 5 ++++- .../editor/panel/library/ImportWindowController.java | 6 ++++-- .../editor/panel/library/LibraryPanelController.java | 5 +++-- .../javafx/scenebuilder/kit/fxom/FXOMArchive.java | 7 +++++-- .../oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java | 10 +++++++--- .../javafx/scenebuilder/kit/library/LibraryItem.java | 6 ++++-- .../kit/metadata/util/ClipboardDecoder.java | 6 ++++-- .../fxom/FXOMSaverUpdateImportInstructionsTest.java | 5 +++-- 10 files changed, 41 insertions(+), 19 deletions(-) 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/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/FXOMArchive.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java index f9c3d0505..9aa07552e 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) 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/FXOMNodes.java b/kit/src/main/java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java index 1da228dc7..5e97c9af2 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) 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. * @@ -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/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/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/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(); } From fadf87af84e2741f57b94fa2fd6551de8f777cdb Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Sun, 16 Jan 2022 20:59:29 +0100 Subject: [PATCH 42/43] Corrected license headers. --- .../com/oracle/javafx/scenebuilder/kit/fxom/FXOMArchive.java | 2 +- .../java/com/oracle/javafx/scenebuilder/kit/fxom/FXOMNodes.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 9aa07552e..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) 2022, 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. * 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 5e97c9af2..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,5 +1,5 @@ /* - * Copyright (c) 2017, 2022, Gluon and/or its affiliates. + * 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. * From bc8ef4a5c7130f1f89bbe9d5bf47d5074be318d3 Mon Sep 17 00:00:00 2001 From: Oliver-Loeffler Date: Sun, 16 Jan 2022 21:01:44 +0100 Subject: [PATCH 43/43] Set of switches is now defined once. --- .../oracle/javafx/scenebuilder/kit/fxom/FXOMDocument.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 625b48ab1..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 @@ -106,13 +106,14 @@ public FXOMDocument(String fxmlText, URL location, ClassLoader classLoader, Reso initialDeclaredClasses = new ArrayList<>(); if (this.glue.getRootElement() != null) { String fxmlTextToLoad = fxmlText; - if (!Set.of(switches).contains(FXOMDocumentSwitch.FOR_PREVIEW)) { + 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(fxmlTextToLoad); - if (Set.of(switches).contains(FXOMDocumentSwitch.NORMALIZED)) { + if (availableSwitches.contains(FXOMDocumentSwitch.NORMALIZED)) { final FXOMNormalizer normalizer = new FXOMNormalizer(this); normalizer.normalize(); }