changeset 8015:86b0f5599fad

[SCENEBUILDER] Content panel now uses SubScene (DTL-6797).
author Eric Le Ponner <eric.le.ponner@oracle.com>
date Tue, 09 Sep 2014 15:55:17 +0200
parents 926c9f860016
children 0f7bad358c85
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/AbstractDecoration.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanel.fxml apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/WorkspaceController.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/util/Deprecation.java
diffstat 5 files changed, 57 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/AbstractDecoration.java	Tue Sep 09 17:41:46 2014 +0400
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/AbstractDecoration.java	Tue Sep 09 15:55:17 2014 +0200
@@ -40,6 +40,7 @@
 import javafx.scene.Group;
 import javafx.scene.Node;
 import javafx.scene.Scene;
+import javafx.scene.SubScene;
 import javafx.scene.transform.NonInvertibleTransformException;
 import javafx.scene.transform.Transform;
 
@@ -138,13 +139,15 @@
     
     public Transform getSceneGraphObjectToDecorationTransform() {
         final Node proxy = getSceneGraphObjectProxy();
-        final Transform t1 = proxy.getLocalToSceneTransform();
+        final SubScene contentSubScene = contentPanelController.getContentSubScene();
+        final Transform t0 = proxy.getLocalToSceneTransform();
+        final Transform t1 = contentSubScene.getLocalToSceneTransform();
         final Transform t2 = getRootNode().getLocalToSceneTransform();
         final Transform result;
         
         try {
             final Transform i2 = t2.createInverse();
-            result = i2.createConcatenation(t1);
+            result = i2.createConcatenation(t1).createConcatenation(t0);
         } catch(NonInvertibleTransformException x) {
             throw new RuntimeException(x);
         }
@@ -191,11 +194,17 @@
     protected void startListeningToLocalToSceneTransform(Node node) {
         assert node != null;
         node.localToSceneTransformProperty().addListener(localToSceneTransformListener);
+        node.sceneProperty().addListener(sceneListener);
+        final SubScene contentSubScene = contentPanelController.getContentSubScene();
+        contentSubScene.localToSceneTransformProperty().addListener(localToSceneTransformListener);
     }
     
     protected void stopListeningToLocalToSceneTransform(Node node) {
         assert node != null;
         node.localToSceneTransformProperty().removeListener(localToSceneTransformListener);
+        node.sceneProperty().removeListener(sceneListener);
+        final SubScene contentSubScene = contentPanelController.getContentSubScene();
+        contentSubScene.localToSceneTransformProperty().removeListener(localToSceneTransformListener);
     }
     
     /*
@@ -226,5 +235,8 @@
         = (ov, v1, v2) -> layoutDecoration();
     
     private final ChangeListener<Transform> localToSceneTransformListener
-        = (ov, v1, v2) -> layoutDecoration();
+        = (ov, v1, v2) -> layoutDecoration(); 
+    
+    private final ChangeListener<Scene> sceneListener
+        = (ov, v1, v2) -> layoutDecoration(); 
 }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanel.fxml	Tue Sep 09 17:41:46 2014 +0400
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanel.fxml	Tue Sep 09 15:55:17 2014 +0200
@@ -47,15 +47,19 @@
       <children>
         <Group id="Group">
           <children>
-            <Group fx:id="scalingGroup" layoutX="-30.0" layoutY="-50.0">
+            <Group fx:id="scalingGroup">
               <children>
                 <Rectangle fx:id="extensionRect" arcHeight="5.0" arcWidth="5.0" fill="#ffc0cb00" height="200.0" layoutX="0.0" layoutY="0.0" mouseTransparent="false" stroke="TRANSPARENT" strokeType="INSIDE" width="200.0" />
                 <Label fx:id="backgroundPane" alignment="CENTER" layoutX="0.0" layoutY="0.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="-1.0" prefWidth="-1.0" style="" styleClass="stage-prompt" text="Label" textAlignment="CENTER" textFill="#9f9f9f" wrapText="true" />
-                <Group fx:id="contentGroup" layoutX="0.0" layoutY="0.0">
-                  <children>
-                    <Ellipse fill="DODGERBLUE" layoutX="0.0" layoutY="0.0" radiusX="140.0" radiusY="100.0" stroke="BLACK" strokeType="INSIDE" />
-                  </children>
-                </Group>
+                <SubScene fx:id="contentSubScene">
+                    <root>
+                        <Group fx:id="contentGroup" layoutX="0.0" layoutY="0.0">
+                          <children>
+                            <Ellipse fill="DODGERBLUE" layoutX="0.0" layoutY="0.0" radiusX="140.0" radiusY="100.0" stroke="BLACK" strokeType="INSIDE" />
+                          </children>
+                        </Group>
+                    </root>
+                </SubScene>
               </children>
             </Group>
           </children>
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java	Tue Sep 09 17:41:46 2014 +0400
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java	Tue Sep 09 15:55:17 2014 +0200
@@ -122,7 +122,7 @@
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
 import com.oracle.javafx.scenebuilder.kit.metadata.util.DesignHierarchyMask;
-import com.oracle.javafx.scenebuilder.kit.util.Deprecation;
+import javafx.scene.SubScene;
 
 /**
  * This class creates and controls the <b>Content Panel</b> of Scene Builder Kit.
@@ -136,6 +136,7 @@
     @FXML private Rectangle extensionRect;
     @FXML private Label backgroundPane;
     @FXML private Group scalingGroup;
+    @FXML private SubScene contentSubScene;
     @FXML private Group contentGroup;
     @FXML private Pane glassLayer;
     @FXML private Group outlineLayer;
@@ -613,6 +614,15 @@
 
     
     /**
+     * @treatAsPrivate Returns the sub scene holding the user scene graph.
+     * @return the sub scene holding the user scene graph.
+     */
+    public SubScene getContentSubScene() {
+        return contentSubScene;
+    }
+
+    
+    /**
      * Computes the transform that projects from local coordinates of a 
      * scene graph object to the rudder layer local coordinates.
      * @param sceneGraphObject a scene graph object
@@ -623,12 +633,13 @@
         assert sceneGraphObject.getScene() == rudderLayer.getScene();
         
         final Transform t1 = sceneGraphObject.getLocalToSceneTransform();
-        final Transform t2 = rudderLayer.getLocalToSceneTransform();
+        final Transform t2 = contentSubScene.getLocalToSceneTransform();
+        final Transform t3 = rudderLayer.getLocalToSceneTransform();
         final Transform result;
         
         try {
-            final Transform i2 = t2.createInverse();
-            result = i2.createConcatenation(t1);
+            final Transform i3 = t3.createInverse();
+            result = i3.createConcatenation(t2).createConcatenation(t1);
         } catch(NonInvertibleTransformException x) {
             throw new RuntimeException(x);
         }
@@ -803,10 +814,13 @@
         assert backgroundPane.getMinWidth() == Region.USE_PREF_SIZE;
         assert backgroundPane.getMinHeight() == Region.USE_PREF_SIZE;
         assert scalingGroup != null;
-        assert contentGroup != null;
+        assert contentSubScene != null;
+        assert contentSubScene.getLayoutX() == 0.0;
+        assert contentSubScene.getLayoutY() == 0.0;
+        assert contentSubScene.getParent() == scalingGroup;
+        assert contentGroup == contentSubScene.getRoot();
         assert contentGroup.getLayoutX() == 0.0;
         assert contentGroup.getLayoutY() == 0.0;
-        assert contentGroup.getParent() == scalingGroup;
         assert glassLayer != null;
         assert glassLayer.isMouseTransparent() == false;
         assert glassLayer.isFocusTraversable();
@@ -828,17 +842,14 @@
         handleLayer.setManaged(false);
         rudderLayer.setManaged(false);
         
-        // Replace plain group in "contentGroup" by a custom one
-        // which isolates the user scene graph from SB owned styling.
-        installStylingIsolationGroup();
-        
         // Remove fake content used to help design
         backgroundPane.setText(""); //NOI18N
         
         // Setup our workspace controller
         workspaceController.panelControllerDidLoadFxml(
                 scrollPane,
-                scalingGroup, 
+                scalingGroup,
+                contentSubScene,
                 contentGroup, 
                 backgroundPane, 
                 extensionRect);
@@ -1034,45 +1045,6 @@
         changeModeController(newModeController);
     }
     
-    private void installStylingIsolationGroup() {
-        assert contentGroup.getParent() == scalingGroup;
-        
-        /*
-         * To isolate user content styling from SB's own styling we 
-         * insert two custom groups between scalingGroup and contentGroup:
-         * 
-         * 1) original layout loaded from FXML:
-         * 
-         *      ...
-         *          scalingGroup
-         *              contentGroup
-         *                  ... (user content)
-         * 
-         * 2) layout with isolation groups:
-         * 
-         *      ... 
-         *          scalingGroup
-         *              isolationGroupA     # impl_getAllParentStylesheets() overriden
-         *                  isolationGroupB     # getStyleableParent() overriden 
-         *                      contentGroup
-         *                          ... (user content)
-         *
-         * isolationGroupA prevents styling from SB to apply to user content
-         * isolationGroupB enables user content to have its own theme (modena, caspian...)
-         */
-        
-        final Group isolationGroupA = Deprecation.makeStylingIsolationGroupA();
-        final Group isolationGroupB = Deprecation.makeStylingIsolationGroupB();
-
-        final int contentGroupIndex = scalingGroup.getChildren().indexOf(contentGroup);
-        assert contentGroupIndex != -1;
-        scalingGroup.getChildren().remove(contentGroup);
-        scalingGroup.getChildren().add(contentGroupIndex, isolationGroupA);
-        isolationGroupA.getChildren().add(isolationGroupB);
-        isolationGroupB.getChildren().add(contentGroup);
-    }
-    
-    
     /*
      * Private (outline layer)
      */
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/WorkspaceController.java	Tue Sep 09 17:41:46 2014 +0400
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/content/WorkspaceController.java	Tue Sep 09 15:55:17 2014 +0200
@@ -46,6 +46,7 @@
 import javafx.scene.Node;
 import javafx.scene.Parent;
 import javafx.scene.Scene;
+import javafx.scene.SubScene;
 import javafx.scene.control.Label;
 import javafx.scene.control.ScrollPane;
 import javafx.scene.layout.Region;
@@ -62,6 +63,7 @@
     
     private ScrollPane scrollPane;
     private Group scalingGroup;
+    private SubScene contentSubScene;
     private Group contentGroup;
     private Label backgroundPane;
     private Rectangle extensionRect;
@@ -72,16 +74,18 @@
     private FXOMDocument fxomDocument;
 
     public void panelControllerDidLoadFxml(ScrollPane scrollPane, 
-            Group scalingGroup, Group contentGroup, Label backgroundPane, 
+            Group scalingGroup, SubScene contentSubScene, Group contentGroup, Label backgroundPane, 
             Rectangle extensionRect) {
         assert scrollPane != null;
         assert backgroundPane != null;
         assert scalingGroup != null;
+        assert contentSubScene != null;
         assert contentGroup != null;
         assert extensionRect != null;
         
         this.scrollPane = scrollPane;
         this.scalingGroup = scalingGroup;
+        this.contentSubScene = contentSubScene;
         this.contentGroup = contentGroup;
         this.backgroundPane = backgroundPane;
         this.extensionRect = extensionRect;
@@ -146,14 +150,8 @@
     }
     
     public void setThemeStyleSheet(String themeStyleSheet) {
-        assert contentGroup.getParent() instanceof Group;
-        final Group isolationGroup = (Group) contentGroup.getParent();
-        assert isolationGroup.getStyleClass().contains("root");
-        
-        isolationGroup.getStylesheets().clear();
         assert themeStyleSheet != null;
-        isolationGroup.getStylesheets().add(themeStyleSheet);
-        isolationGroup.applyCss();
+        contentSubScene.setUserAgentStylesheet(themeStyleSheet);
     }
     
     public void setPreviewStyleSheets(List<String> previewStyleSheets) {
@@ -166,7 +164,7 @@
         if (scrollPane != null) {
             try {
                 if (applyCSS) {
-                    scrollPane.getContent().applyCss();
+                    contentSubScene.getRoot().applyCss();
                 }
                 scrollPane.layout();
                 layoutException = null;
@@ -387,6 +385,9 @@
         extensionRect.setY(extensionBounds.getMinY());
         extensionRect.setWidth(extensionBounds.getWidth());
         extensionRect.setHeight(extensionBounds.getHeight());
+        
+        contentSubScene.setWidth(contentGroup.getLayoutBounds().getWidth());
+        contentSubScene.setHeight(contentGroup.getLayoutBounds().getHeight());
     }
     
     private static Bounds computeUnclippedBounds(Node node) {
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/util/Deprecation.java	Tue Sep 09 17:41:46 2014 +0400
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/util/Deprecation.java	Tue Sep 09 15:55:17 2014 +0200
@@ -219,28 +219,6 @@
         tableColumn.impl_setReorderable(reordable);
     }
 
-    // RT-21247 : Promote impl_getAllParentStylesheets to public API
-    public static Group makeStylingIsolationGroupA() {
-        final Group result = new Group() {
-            @Override
-            public List<String> impl_getAllParentStylesheets() { return null; }
-        };
-
-        return result;
-    }
-
-    public static Group makeStylingIsolationGroupB() {
-        final Group result = new Group() {
-            @Override
-            public Styleable getStyleableParent() { return null; }
-        };
-
-        result.getStyleClass().add("root"); //NOI18N
-        result.getStylesheets().add(MODENA_STYLESHEET);
-
-        return result;
-    }
-
     // Returns the corresponding text css (.css) from a binary css (.bss)
     public static URL getThemeTextStylesheet(String binaryCssUrlStr) {
         String textCssUrlStr = binaryCssUrlStr.replaceAll(".bss", ".css"); //NOI18N