fix normalized position in frame and border layout padding in figure 39/14139/2
Antoine ELIAS [Wed, 26 Mar 2014 13:51:27 +0000 (14:51 +0100)]
Change-Id: I1cc01a2f4447ca4729d90041e5e64875f8e54d52

scilab/modules/gui/src/java/org/scilab/modules/gui/SwingViewWidget.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabFrame.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabCommonPanel.java
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/UnitsConverter.java

index 5e23bed..925734a 100644 (file)
@@ -274,7 +274,7 @@ public final class SwingViewWidget {
             }
             case __GO_PARENT__:
                 /* Update position */
-                SwingViewWidget.update(uiControl, __GO_POSITION__, controller.getProperty(uid, __GO_POSITION__));
+                ((SwingViewObject)uiControl).update(__GO_POSITION__, controller.getProperty(uid, __GO_POSITION__));
                 break;
             default:
                 break;
index 6474adf..ad55126 100644 (file)
@@ -128,27 +128,30 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
                         // Position property not yet set
                         return;
                     }
+
                     UicontrolUnits unitsProperty = UnitsConverter.stringToUnitsEnum((String) GraphicController.getController().getProperty(uid, GraphicObjectProperties.__GO_UI_UNITS__));
-                    newPosition[0] = UnitsConverter.convertFromPixel(getPosition().getX(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
-                    newPosition[1] = UnitsConverter.convertFromPixel(getPosition().getY(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
-                    newPosition[2] = UnitsConverter.convertFromPixel(getWidth(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
-                    newPosition[3] = UnitsConverter.convertFromPixel(getHeight(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
-                    positions[2] = newPosition[2];
-                    positions[3] = newPosition[3];
-                    invalidate();
-                    if (getParent() != null && getParent().getLayout() == null) {
-                        GraphicController.getController().setProperty(getId(), GraphicObjectProperties.__GO_POSITION__, newPosition);
-                    } else {
-                        GraphicController.getController().setProperty(getId(), GraphicObjectProperties.__GO_POSITION__, positions);
+
+                    //normalized values are always good
+                    if (unitsProperty != UicontrolUnits.NORMALIZED) {
+                        newPosition[0] = UnitsConverter.convertFromPixel(getPosition().getX(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
+                        newPosition[1] = UnitsConverter.convertFromPixel(getPosition().getY(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
+                        newPosition[2] = UnitsConverter.convertFromPixel(getWidth(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
+                        newPosition[3] = UnitsConverter.convertFromPixel(getHeight(), unitsProperty, (SwingScilabFrame) SwingView.getFromId(uid), true);
+                        positions[2] = newPosition[2];
+                        positions[3] = newPosition[3];
+                        if (getParent() != null && getParent().getLayout() == null) {
+                            GraphicController.getController().setProperty(getId(), GraphicObjectProperties.__GO_POSITION__, newPosition);
+                        } else {
+                            GraphicController.getController().setProperty(getId(), GraphicObjectProperties.__GO_POSITION__, positions);
+                        }
                     }
                 }
 
                 if (hasLayout == false) {
                     for (Component comp : getComponents()) {
                         if (comp instanceof Widget) {
-                            Widget widget = (Widget) comp;
                             SwingViewObject obj = (SwingViewObject) comp;
-                            SwingViewWidget.update(widget, __GO_POSITION__, GraphicController.getController().getProperty(obj.getId(), __GO_POSITION__));
+                            obj.update(__GO_POSITION__, GraphicController.getController().getProperty(obj.getId(), __GO_POSITION__));
                         }
                     }
                 }
@@ -858,7 +861,7 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
             }
             case __GO_POSITION__: {
                 SwingViewWidget.updatePosition(this, uid, value);
-                revalidate();
+                validate();
                 doLayout();
                 break;
             }
index 1efb650..4d12acf 100644 (file)
@@ -217,7 +217,6 @@ public class SwingScilabCommonPanel {
                     case BORDER: {
                         Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_BORDER_OPT_PADDING__);
                         component.getWidgetPane().setLayout(new BorderLayout(padding[0], padding[1]));
-                        component.getWidgetPane().setLayout(new BorderLayout());
                         component.setHasLayout(true);
                         break;
                     }
@@ -281,7 +280,6 @@ public class SwingScilabCommonPanel {
 
                 Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_BORDER_OPT_PADDING__);
                 component.getWidgetPane().setLayout(new BorderLayout(padding[0], padding[1]));
-                component.getWidgetPane().setLayout(new BorderLayout());
                 break;
             }
             case __GO_UI_ICON__: {
index a4191fb..f98bde0 100644 (file)
@@ -18,6 +18,9 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
 
+import java.awt.Component;
+import java.awt.Dimension;
+
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.gui.SwingViewObject;
 import org.scilab.modules.gui.bridge.CallScilabBridge;
@@ -71,55 +74,33 @@ public final class UnitsConverter {
     public static double convertFromPoint(double value, UicontrolUnits newUnit, Widget uicontrol, boolean widthAsRef) {
         int refSize = 0;
 
-        Integer parentId = null;
-        int parentType = -1;
-
         SwingViewObject uicontrolAsView = (SwingViewObject) uicontrol;
         int widgetType = (Integer) GraphicController.getController().getProperty(uicontrolAsView.getId(), __GO_TYPE__);
 
         /* Get the component height from java */
         if (widgetType == __GO_FIGURE__) { /* Figure */
-            if (widthAsRef) {
-                refSize = (int) CallScilabBridge.getScreenWidth();
-            } else {
-                refSize = (int) CallScilabBridge.getScreenHeight();
-            }
             newUnit = UicontrolUnits.PIXELS;
-        } else { /* Uicontrol */
-            parentId = (Integer) GraphicController.getController().getProperty(uicontrolAsView.getId(), __GO_PARENT__);
-            if (parentId == null && newUnit == UicontrolUnits.NORMALIZED) { /* Parent not yet set */
-                return 0.0;
-            }
-            parentType = (Integer) GraphicController.getController().getProperty(parentId, __GO_TYPE__);
         }
 
         switch (newUnit) {
             case POINTS:
                 return value;
             case NORMALIZED:
-                if (parentType == __GO_FIGURE__) { /* Figure */
-                    Integer[] parentSize = (Integer[]) GraphicController.getController().getProperty(parentId, __GO_AXES_SIZE__);
-                    if (widthAsRef) {
-                        refSize = parentSize[0].intValue();
-                    } else {
-                        refSize = parentSize[1].intValue();
-                    }
-                } else { /* Frame */
-                    Double[] parentSize = (Double[]) GraphicController.getController().getProperty(parentId, __GO_POSITION__);
-
-                    if (widthAsRef) {
-                        refSize = parentSize[2].intValue();
-                    } else {
-                        refSize = parentSize[3].intValue();
-                    }
+                Component comp = (Component)uicontrol;
+                Dimension dims = comp.getParent().getSize();
+                if (widthAsRef) {
+                    refSize = dims.width;
+                } else {
+                    refSize = dims.height;
                 }
+
                 return value / (refSize * POINT_PER_INCH / CallScilabBridge.getScreenResolution());
             case INCHES:
                 return value / POINT_PER_INCH;
             case CENTIMETERS:
                 return value * CM_PER_INCH / POINT_PER_INCH;
             case PIXELS:
-                return value * CallScilabBridge.getScreenResolution() / POINT_PER_INCH + 1;
+                return value * CallScilabBridge.getScreenResolution() / POINT_PER_INCH;
             default:
                 return 0.0;
         }
@@ -128,49 +109,24 @@ public final class UnitsConverter {
     public static double convertToPoint(double value, UicontrolUnits oldUnit, Widget uicontrol, boolean widthAsRef) {
         int refSize = 0;
 
-        Integer parentId = null;
-        Integer parentType = null;
-
         SwingViewObject uicontrolAsView = (SwingViewObject) uicontrol;
         int widgetType = (Integer) GraphicController.getController().getProperty(uicontrolAsView.getId(), __GO_TYPE__);
 
         /* Get the component height from java */
-        if (widgetType == __GO_FIGURE__) { /* Figure */
-            /* The parent is the screen */
-            if (widthAsRef)    {
-                refSize = (int) CallScilabBridge.getScreenWidth();
-            } else {
-                refSize = (int) CallScilabBridge.getScreenHeight();
-            }
+        if (widgetType == __GO_FIGURE__) { // Figure
             oldUnit = UicontrolUnits.PIXELS;
-        } else { /* Uicontrol */
-            parentId = (Integer) GraphicController.getController().getProperty(uicontrolAsView.getId(), __GO_PARENT__);
-            if ((parentId == null || parentId.equals("")) && oldUnit == UicontrolUnits.NORMALIZED) { /* Parent not yet set */
-                return 0;
-            }
-            parentType = (Integer) GraphicController.getController().getProperty(parentId, __GO_TYPE__);
         }
 
         switch (oldUnit) {
             case POINTS:
                 return (int) value;
             case NORMALIZED:
-                if (parentType == __GO_FIGURE__) { /* Figure */
-                    Integer[] parentSize = (Integer[]) GraphicController.getController().getProperty(parentId, __GO_AXES_SIZE__);
-
-                    if (widthAsRef) {
-                        refSize = parentSize[0].intValue();
-                    } else {
-                        refSize = parentSize[1].intValue();
-                    }
-                } else { /* Frame */
-                    Double[] parentSize = (Double[]) GraphicController.getController().getProperty(parentId, __GO_POSITION__);
-
-                    if (widthAsRef) {
-                        refSize = parentSize[2].intValue();
-                    } else {
-                        refSize = parentSize[3].intValue();
-                    }
+                Component comp = (Component)uicontrol;
+                Dimension dims = comp.getParent().getSize();
+                if (widthAsRef) {
+                    refSize = dims.width;
+                } else {
+                    refSize = dims.height;
                 }
                 return (value * refSize * POINT_PER_INCH / CallScilabBridge.getScreenResolution());
             case INCHES: