changeset 8035:4b422b9d2145

[SCENEBUILDER] Fix DTL-6779 : Wrap in and Unwrap commands should be available for DialogPane DTL-6863 : Wrap in and Unwrap commands should be available for TextFlow DTL-6864 : Unwrap command should be available for BorderPane and TabPane
author slions
date Thu, 11 Sep 2014 13:57:13 +0200
parents 4fd7ffb45afb
children 2abfc95e5ffd
files apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBar.fxml apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/AbstractWrapInJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/UnwrapJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/WrapInTextFlowJob.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/util/ContextMenuController.java
diffstat 7 files changed, 112 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBar.fxml	Thu Sep 11 12:16:47 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBar.fxml	Thu Sep 11 13:57:13 2014 +0200
@@ -203,6 +203,7 @@
                 <MenuItem fx:id="wrapInSplitPaneMenuItem" mnemonicParsing="false" text="SplitPane" />
                 <MenuItem fx:id="wrapInStackPaneMenuItem" mnemonicParsing="false" text="StackPane" />
                 <MenuItem fx:id="wrapInTabPaneMenuItem" mnemonicParsing="false" text="TabPane" />
+                <MenuItem fx:id="wrapInTextFlowMenuItem" mnemonicParsing="false" text="TextFlow" />
                 <MenuItem fx:id="wrapInTilePaneMenuItem" mnemonicParsing="false" text="TilePane" />
                 <MenuItem fx:id="wrapInTitledPaneMenuItem" mnemonicParsing="false" text="TitledPane" />
                 <MenuItem fx:id="wrapInToolBarMenuItem" mnemonicParsing="false" text="ToolBar" />
--- a/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java	Thu Sep 11 12:16:47 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java	Thu Sep 11 13:57:13 2014 +0200
@@ -296,6 +296,8 @@
     @FXML
     private MenuItem wrapInTabPaneMenuItem;
     @FXML
+    private MenuItem wrapInTextFlowMenuItem;
+    @FXML
     private MenuItem wrapInTilePaneMenuItem;
     @FXML
     private MenuItem wrapInTitledPaneMenuItem;
@@ -534,6 +536,7 @@
         assert wrapInSplitPaneMenuItem != null;
         assert wrapInStackPaneMenuItem != null;
         assert wrapInTabPaneMenuItem != null;
+        assert wrapInTextFlowMenuItem != null;
         assert wrapInTilePaneMenuItem != null;
         assert wrapInTitledPaneMenuItem != null;
         assert wrapInToolBarMenuItem != null;
@@ -923,6 +926,7 @@
         wrapInSplitPaneMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_SPLIT_PANE));
         wrapInStackPaneMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_STACK_PANE));
         wrapInTabPaneMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TAB_PANE));
+        wrapInTextFlowMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TEXT_FLOW));
         wrapInTilePaneMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TILE_PANE));
         wrapInTitledPaneMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TITLED_PANE));
         wrapInToolBarMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TOOL_BAR));
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java	Thu Sep 11 12:16:47 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/EditorController.java	Thu Sep 11 13:57:13 2014 +0200
@@ -193,6 +193,7 @@
         WRAP_IN_SPLIT_PANE,
         WRAP_IN_STACK_PANE,
         WRAP_IN_TAB_PANE,
+        WRAP_IN_TEXT_FLOW,
         WRAP_IN_TILE_PANE,
         WRAP_IN_TITLED_PANE,
         WRAP_IN_TOOL_BAR,
@@ -1103,6 +1104,10 @@
                 performWrap(javafx.scene.control.TabPane.class);
                 break;
             }
+            case WRAP_IN_TEXT_FLOW: {
+                performWrap(javafx.scene.text.TextFlow.class);
+                break;
+            }
             case WRAP_IN_TILE_PANE: {
                 performWrap(javafx.scene.layout.TilePane.class);
                 break;
@@ -1337,6 +1342,10 @@
                 result = canPerformWrap(javafx.scene.control.TabPane.class);
                 break;
             }
+            case WRAP_IN_TEXT_FLOW: {
+                result = canPerformWrap(javafx.scene.text.TextFlow.class);
+                break;
+            }
             case WRAP_IN_TILE_PANE: {
                 result = canPerformWrap(javafx.scene.layout.TilePane.class);
                 break;
@@ -1699,6 +1708,7 @@
             classesSupportingWrapping.add(javafx.scene.control.SplitPane.class);
             classesSupportingWrapping.add(javafx.scene.layout.StackPane.class);
             classesSupportingWrapping.add(javafx.scene.control.TabPane.class);
+            classesSupportingWrapping.add(javafx.scene.text.TextFlow.class);
             classesSupportingWrapping.add(javafx.scene.layout.TilePane.class);
             classesSupportingWrapping.add(javafx.scene.control.TitledPane.class);
             classesSupportingWrapping.add(javafx.scene.control.ToolBar.class);
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/AbstractWrapInJob.java	Thu Sep 11 12:16:47 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/AbstractWrapInJob.java	Thu Sep 11 13:57:13 2014 +0200
@@ -106,6 +106,8 @@
             job = new WrapInStackPaneJob(editorController);
         } else if (wrappingClass == javafx.scene.control.TabPane.class) {
             job = new WrapInTabPaneJob(editorController);
+        } else if (wrappingClass == javafx.scene.text.TextFlow.class) {
+            job = new WrapInTextFlowJob(editorController);
         } else if (wrappingClass == javafx.scene.layout.TilePane.class) {
             job = new WrapInTilePaneJob(editorController);
         } else if (wrappingClass == javafx.scene.control.TitledPane.class) {
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/UnwrapJob.java	Thu Sep 11 12:16:47 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/UnwrapJob.java	Thu Sep 11 13:57:13 2014 +0200
@@ -58,7 +58,6 @@
 import javafx.scene.control.DialogPane;
 import javafx.scene.control.TabPane;
 import javafx.scene.layout.BorderPane;
-import javafx.scene.text.TextFlow;
 
 /**
  * Main class used for the unwrap jobs.
@@ -90,23 +89,13 @@
             return false;
         }
         final FXOMInstance containerInstance = (FXOMInstance) container;
-        
+
         // Unresolved custom type
         if (container.getSceneGraphObject() == null) {
             return false;
         }
-        
-        // Cannot unwrap TabPane
-        if (TabPane.class.isAssignableFrom(containerInstance.getDeclaredClass())) {
-            return false;
-        }
-        // Cannot unwrap all Pane subclasses (ex : BorderPane, TextFlow and DialogPane)
-        if (BorderPane.class.isAssignableFrom(containerInstance.getDeclaredClass())
-                || TextFlow.class.isAssignableFrom(containerInstance.getDeclaredClass())
-                || DialogPane.class.isAssignableFrom(containerInstance.getDeclaredClass())) {
-            return false;
-        }
-        // Can unwrap classes supporting wrapping except TabPane + some Pane subclasses (see above)
+
+        // Can unwrap ALL classes supporting wrapping
         boolean isAssignableFrom = false;
         for (Class<?> clazz : EditorController.getClassesSupportingWrapping()) {
             isAssignableFrom |= clazz.isAssignableFrom(
@@ -117,7 +106,7 @@
         }
 
         // Retrieve the num of children of the container to unwrap
-        int childrenCount = getChildren(container).size();
+        int childrenCount = getChildren(containerInstance).size();
         // If the container to unwrap has no childen, it cannot be unwrapped
         if (childrenCount == 0) {
             return false;
@@ -143,7 +132,7 @@
             }
         }
     }
-    
+
     @Override
     protected List<Job> makeSubJobs() {
         final List<Job> result = new ArrayList<>();
@@ -319,32 +308,60 @@
         final Bounds oldContainerBounds = oldContainerNode.getLayoutBounds();
         final Point2D point = oldContainerNode.localToParent(
                 oldContainerBounds.getMinX(), oldContainerBounds.getMinY());
-
+        
         for (FXOMObject child : children) {
             assert child.getSceneGraphObject() instanceof Node;
+            
             final Node childNode = (Node) child.getSceneGraphObject();
-            double layoutX = point.getX() + childNode.getLayoutX();
-            double layoutY = point.getY() + childNode.getLayoutY();
+            final double currentLayoutX = childNode.getLayoutX();
+            final double currentLayoutY = childNode.getLayoutY();
+            
+            final Point2D nextLayoutXY = oldContainerNode.localToParent(
+                    currentLayoutX, currentLayoutY);
+            
             final ModifyObjectJob modifyLayoutX = WrapJobUtils.modifyObjectJob(
-                    (FXOMInstance) child, "layoutX", layoutX, getEditorController());
+                    (FXOMInstance) child, "layoutX", nextLayoutXY.getX(), getEditorController());
             jobs.add(modifyLayoutX);
             final ModifyObjectJob modifyLayoutY = WrapJobUtils.modifyObjectJob(
-                    (FXOMInstance) child, "layoutY", layoutY, getEditorController());
+                    (FXOMInstance) child, "layoutY", nextLayoutXY.getY(), getEditorController());
             jobs.add(modifyLayoutY);
         }
         return jobs;
     }
 
-    private List<FXOMObject> getChildren(final FXOMObject container) {
+    private List<FXOMObject> getChildren(final FXOMInstance container) {
         final DesignHierarchyMask mask = new DesignHierarchyMask(container);
         final List<FXOMObject> result = new ArrayList<>();
         if (mask.isAcceptingSubComponent()) {
-            result.addAll(mask.getSubComponents());
+            // TabPane => unwrap first Tab CONTENT
+            if (TabPane.class.isAssignableFrom(container.getDeclaredClass())) {
+                final List<FXOMObject> tabs = mask.getSubComponents();
+                if (tabs.size() >= 1) {
+                    final FXOMObject tab = tabs.get(0);
+                    final DesignHierarchyMask tabMask = new DesignHierarchyMask(tab);
+                    assert tabMask.isAcceptingAccessory(Accessory.CONTENT);
+                    if (tabMask.getAccessory(Accessory.CONTENT) != null) {
+                        result.add(tabMask.getAccessory(Accessory.CONTENT));
+                    }
+                }
+            } else {
+                result.addAll(mask.getSubComponents());
+            }
         } else {
-            assert mask.isAcceptingAccessory(Accessory.CONTENT);
-            final FXOMObject child = mask.getAccessory(Accessory.CONTENT);
-            if (child != null) {
-                result.add(child);
+            // BorderPane => unwrap CENTER accessory
+            if (mask.isAcceptingAccessory(Accessory.CENTER)
+                    && mask.getAccessory(Accessory.CENTER) != null) {
+                result.add(mask.getAccessory(Accessory.CENTER));
+            } 
+            // DialogPane => unwrap DP_CONTENT accessory
+            else if (mask.isAcceptingAccessory(Accessory.DP_CONTENT)
+                    && mask.getAccessory(Accessory.DP_CONTENT) != null) {
+                result.add(mask.getAccessory(Accessory.DP_CONTENT));
+            }
+            // ScrollPane => unwrap CONTENT accessory
+            else if (mask.isAcceptingAccessory(Accessory.CONTENT)
+                    && mask.getAccessory(Accessory.CONTENT) != null) {
+                result.add(mask.getAccessory(Accessory.CONTENT));
             }
         }
         return result;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/job/wrap/WrapInTextFlowJob.java	Thu Sep 11 13:57:13 2014 +0200
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 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:
+ *
+ * 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.editor.job.wrap;
+
+import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import javafx.scene.text.TextFlow;
+
+/**
+ * Job used to wrap selection in a TextFlow.
+ */
+public class WrapInTextFlowJob extends AbstractWrapInSubComponentJob {
+
+    public WrapInTextFlowJob(EditorController editorController) {
+        super(editorController);
+        newContainerClass = TextFlow.class;
+    }
+}
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/util/ContextMenuController.java	Thu Sep 11 12:16:47 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/util/ContextMenuController.java	Thu Sep 11 13:57:13 2014 +0200
@@ -90,6 +90,7 @@
     private MenuItem wrapInSplitPaneMenuItem;
     private MenuItem wrapInStackPaneMenuItem;
     private MenuItem wrapInTabPaneMenuItem;
+    private MenuItem wrapInTextFlowMenuItem;
     private MenuItem wrapInTilePaneMenuItem;
     private MenuItem wrapInTitledPaneMenuItem;
     private MenuItem wrapInToolBarMenuItem;
@@ -419,6 +420,9 @@
         wrapInTilePaneMenuItem = new MenuItem("TilePane");
         wrapInTilePaneMenuItem.setOnAction(onActionEventHandler);
         wrapInTilePaneMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TILE_PANE));
+        wrapInTextFlowMenuItem = new MenuItem("TextFlow");
+        wrapInTextFlowMenuItem.setOnAction(onActionEventHandler);
+        wrapInTextFlowMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TEXT_FLOW));
         wrapInTitledPaneMenuItem = new MenuItem("TitledPane");
         wrapInTitledPaneMenuItem.setOnAction(onActionEventHandler);
         wrapInTitledPaneMenuItem.setUserData(new EditActionController(EditAction.WRAP_IN_TITLED_PANE));
@@ -444,6 +448,7 @@
                 wrapInSplitPaneMenuItem,
                 wrapInStackPaneMenuItem,
                 wrapInTabPaneMenuItem,
+                wrapInTextFlowMenuItem,
                 wrapInTilePaneMenuItem,
                 wrapInTitledPaneMenuItem,
                 wrapInToolBarMenuItem,