UIW: fix bug in normalized position 32/13332/2
Calixte DENIZET [Fri, 6 Dec 2013 14:46:12 +0000 (15:46 +0100)]
Change-Id: I4b0e968e8c8bcc20a54f6710ad88e6bec1c10871

scilab/modules/gui/src/java/org/scilab/modules/gui/uiwidget/StringConverters.java
scilab/modules/gui/src/java/org/scilab/modules/gui/uiwidget/UIComponent.java
scilab/modules/gui/src/java/org/scilab/modules/gui/uiwidget/components/NoLayout.java

index ef8cd92..dea7eef 100644 (file)
@@ -664,7 +664,7 @@ public final class StringConverters {
                 String[] toks = str.split("[ ,;]");
                 for (int i = 0; i < toks.length && i < 4; i++) {
                     try {
-                        d[i] = (int) Double.parseDouble(toks[i]);
+                        d[i] = Double.parseDouble(toks[i]);
                     } catch (NumberFormatException ee) {
                         d[i] = 0;
                     }
index 3ebf17c..f837e8d 100644 (file)
@@ -2615,6 +2615,14 @@ public abstract class UIComponent {
                 setNoLayoutConstraint(ScilabTypeConverters.getObjectFromValue(Rectangle2D.Double.class, (ScilabType) attributes.get("position")));
             }
             uselessAttrs.remove("position");
+            if (uselessAttrs.contains("units")) {
+                if (attributes instanceof StringMap) {
+                    setUnits(StringConverters.getObjectFromValue(String[].class, (String) attributes.get("units")));
+                } else {
+                    setUnits(ScilabTypeConverters.getObjectFromValue(String[].class, (ScilabType) attributes.get("units")));
+                }
+                uselessAttrs.remove("units");
+            }
         }
 
         setAttributesAndStyle(attributes, uselessAttrs);
index d0b78d9..ed939e4 100644 (file)
@@ -130,18 +130,6 @@ public class NoLayout implements LayoutManager2 {
                             break;
                     }
 
-                    switch (constraint.unit[1]) {
-                        case UNIT_NORMALIZED:
-                            rr.y = (int) (rp.height * (1 - correct(constraint.bounds.height) - correct(constraint.bounds.y)));
-                            break;
-                        case UNIT_POINTS:
-                            rr.y = (int) (rp.height - (constraint.bounds.y + constraint.bounds.height) * scale);
-                            break;
-                        default:
-                            rr.y = (int) (rp.height - constraint.bounds.y - constraint.bounds.height);
-                            break;
-                    }
-
                     switch (constraint.unit[2]) {
                         case UNIT_NORMALIZED:
                             rr.width = (int) (correct(constraint.bounds.width) * rp.width);
@@ -166,6 +154,18 @@ public class NoLayout implements LayoutManager2 {
                             break;
                     }
 
+                    switch (constraint.unit[1]) {
+                        case UNIT_NORMALIZED:
+                            rr.y = (int) (rp.height * (1 - correct(constraint.bounds.y))) - rr.height;
+                            break;
+                        case UNIT_POINTS:
+                            rr.y = (int) (rp.height - constraint.bounds.y * scale) - rr.height;
+                            break;
+                        default:
+                            rr.y = (int) (rp.height - constraint.bounds.y) - rr.height;
+                            break;
+                    }
+
                     if (!c.getBounds().equals(rr)) {
                         c.setBounds(rr);
                         /*if (bounds.width != rr.width || bounds .height != rr.height) {
@@ -250,7 +250,7 @@ public class NoLayout implements LayoutManager2 {
 
 
         public String toString() {
-            return "NoLayoutConstraint:" + bounds;
+            return "NoLayoutConstraint:" + bounds + " units:" + unit[0] + ";" + unit[1] + ";" + unit[2] + ";" + unit[3];
         }
     }
 }