changeset 7589:af217a8598ef

[SCENEBUILDER] Fix for DTL-6789: Inspector might ensure values for hValue / vValue on ScrollPane are within bounds
author Jerome Cambon
date Mon, 28 Jul 2014 10:34:17 +0200
parents 1942db1e52a9
children df28c1bdf2e1
files apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/InspectorPanelController.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/editors/BoundedDoubleEditor.java apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/editors/Editor.java
diffstat 3 files changed, 80 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/InspectorPanelController.java	Fri Jul 25 11:18:02 2014 -0700
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/InspectorPanelController.java	Mon Jul 28 10:34:17 2014 +0200
@@ -1361,13 +1361,13 @@
             // Double editors
             DoublePropertyMetadata doublePropMeta = (DoublePropertyMetadata) propMeta;
             DoubleKind kind = doublePropMeta.getKind();
-            if ((kind == DoubleKind.COORDINATE)
+            if ((kind == DoubleKind.OPACITY) || (kind == DoubleKind.PROGRESS) || isBoundedByProperties(propMeta)) {
+                propertyEditor = makePropertyEditor(BoundedDoubleEditor.class, propMeta);
+            } else if ((kind == DoubleKind.COORDINATE)
                     || (kind == DoubleKind.USE_COMPUTED_SIZE) || (kind == DoubleKind.USE_PREF_SIZE)
                     || (kind == DoubleKind.NULLABLE_COORDINATE)) {
                 // We may have constants to add
                 propertyEditor = makePropertyEditor(DoubleEditor.class, propMeta);
-            } else if ((kind == DoubleKind.OPACITY) || (kind == DoubleKind.PROGRESS)) {
-                propertyEditor = makePropertyEditor(BoundedDoubleEditor.class, propMeta);
             } else if (kind == DoubleKind.ANGLE) {
                 propertyEditor = makePropertyEditor(RotateEditor.class, propMeta);
             } else {
@@ -1754,9 +1754,9 @@
             assert propMeta instanceof DoublePropertyMetadata;
             DoublePropertyMetadata doublePropMeta = (DoublePropertyMetadata) propMeta;
             if (propertyEditor != null) {
-                ((BoundedDoubleEditor) propertyEditor).reset(propMeta, selectedClasses, getConstants(doublePropMeta));
+                ((BoundedDoubleEditor) propertyEditor).reset(propMeta, selectedClasses, getSelectedInstances(), getConstants(doublePropMeta));
             } else {
-                propertyEditor = new BoundedDoubleEditor(propMeta, selectedClasses, getConstants(doublePropMeta));
+                propertyEditor = new BoundedDoubleEditor(propMeta, selectedClasses, getSelectedInstances(), getConstants(doublePropMeta));
             }
         } else if (editorClass == RotateEditor.class) {
             if (propertyEditor != null) {
@@ -2046,6 +2046,15 @@
         return selectionState.getCommonParentClass();
     }
 
+    private boolean isBoundedByProperties(ValuePropertyMetadata propMeta) {
+        // Only ScrollPane.hValue and ScrollPane.vValue for now
+        if (propMeta.getName().toString().equals(Editor.hValuePropName) 
+                || propMeta.getName().toString().equals(Editor.vValuePropName)) {
+            return true;
+        }
+        return false;
+    }
+    
     /*
      *   This class represents the selection state: 
      *   - the selected instances, 
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/editors/BoundedDoubleEditor.java	Fri Jul 25 11:18:02 2014 -0700
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/editors/BoundedDoubleEditor.java	Mon Jul 28 10:34:17 2014 +0200
@@ -31,10 +31,14 @@
  */
 package com.oracle.javafx.scenebuilder.kit.editor.panel.inspector.editors;
 
+import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
+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.DoublePropertyMetadata;
+import com.oracle.javafx.scenebuilder.kit.metadata.util.PropertyName;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -89,10 +93,11 @@
         initialize();
     }
 
-    public BoundedDoubleEditor(ValuePropertyMetadata propMeta, Set<Class<?>> selectedClasses, Map<String, Object> constantsMap) {
+    public BoundedDoubleEditor(ValuePropertyMetadata propMeta, Set<Class<?>> selectedClasses, Set<FXOMInstance> selectedInstances, Map<String, Object> constantsMap) {
         super(propMeta, selectedClasses, new ArrayList<>(constantsMap.keySet()), AutoSuggestEditor.Type.DOUBLE);
         this.constants = constantsMap;
         initialize();
+        handleSpecificCases(propMeta, selectedInstances);
     }
 
     // Method to please FindBugs
@@ -223,10 +228,11 @@
         getTextField().setText(EditorUtils.valAsStr(value));
     }
 
-    public void reset(ValuePropertyMetadata propMeta, Set<Class<?>> selectedClasses,
+    public void reset(ValuePropertyMetadata propMeta, Set<Class<?>> selectedClasses, Set<FXOMInstance> selectedInstances,
             Map<String, Object> constants) {
         super.reset(propMeta, selectedClasses, new ArrayList<>(constants.keySet()));
         this.constants = constants;
+        handleSpecificCases(propMeta, selectedInstances);
         configureSlider(propMeta);
     }
 
@@ -244,7 +250,13 @@
                     || (kind == DoublePropertyMetadata.DoubleKind.PROGRESS)) {
                 min = 0;
                 max = 1;
+            }
+            if (max <= 1) {
                 roundingFactor = 100; // 2 decimals
+            } else if (max <= 10) {
+                roundingFactor = 10; // 1 decimal
+            } else {
+                roundingFactor = 1; // no decimal
             }
         }
         slider.setMin(min);
@@ -256,4 +268,48 @@
     public void requestFocus() {
         EditorUtils.doNextFrame(() -> getTextField().requestFocus());
     }
+    
+    private void handleSpecificCases(ValuePropertyMetadata propMeta, Set<FXOMInstance> selectedInstances) {
+        // Specific case for ScrollPane hValue/vValue, that have their bounds
+        // related to properties (hMin/hMax, vMin/Vmax)
+        // Since we only have one case of this, the generic case
+        // (bounds=properties) has not been implemented.
+        // (to avoid to add complexity for a single case)
+        String[] scrollBarPropsArray = { Editor.hValuePropName, Editor.vValuePropName };
+        String[] scrollBarHprops = { Editor.hMinPropName, Editor.hMaxPropName };
+        String[] scrollBarVprops = { Editor.vMinPropName, Editor.vMaxPropName };
+        List<String> scrollBarProps = Arrays.asList(scrollBarPropsArray);
+        if (!scrollBarProps.contains(propMeta.getName().toString())) {
+            return;
+        }
+        String[] minMaxProps;
+        if (propMeta.getName().toString().equals(Editor.hValuePropName)) {
+            minMaxProps = scrollBarHprops;
+        } else {
+            minMaxProps = scrollBarVprops;
+        }
+
+        for (String minMaxProp : minMaxProps) {
+            // Set min and max
+            Object propValue = null;
+            boolean different = false;
+            for (FXOMInstance instance : selectedInstances) {
+                Object valueCurr = Metadata.getMetadata().queryValueProperty(instance, new PropertyName(minMaxProp))
+                        .getValueInSceneGraphObject(instance);
+                if (propValue != null && valueCurr != propValue) {
+                    different = true;
+                    break;
+                }
+                propValue = valueCurr;
+            }
+            if (!different) {
+                assert propValue instanceof Double;
+                if (minMaxProp.contains("min")) { //NOI18N
+                    this.min = (Double) propValue;
+                } else {
+                    this.max = (Double) propValue;
+                }
+            }
+        }
+    }
 }
--- a/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/editors/Editor.java	Fri Jul 25 11:18:02 2014 -0700
+++ b/apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/editor/panel/inspector/editors/Editor.java	Mon Jul 28 10:34:17 2014 +0200
@@ -46,6 +46,14 @@
     public static final String rightAnchorPropName = "AnchorPane.rightAnchor";
     public static final String bottomAnchorPropName = "AnchorPane.bottomAnchor";
     public static final String leftAnchorPropName = "AnchorPane.leftAnchor";
+    
+    // ScrollPane scroll bar min and max
+    public static final String hValuePropName = "hvalue";
+    public static final String hMinPropName = "hmin";
+    public static final String hMaxPropName = "hmax";
+    public static final String vValuePropName = "vvalue";
+    public static final String vMinPropName = "vmin";
+    public static final String vMaxPropName = "vmax";
 
     public static final String INDETERMINATE_STR = "-"; //NOI18N