use backgroundcolor [-2 -2 -2] for transparence 57/14057/2
Antoine ELIAS [Tue, 18 Mar 2014 11:05:34 +0000 (12:05 +0100)]
Change-Id: Iad34653cc0b92564be16e16798a9487c142db115

scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/GOBuilder.java
scilab/modules/gui/src/c/checkColorRange.c
scilab/modules/gui/src/java/org/scilab/modules/gui/SwingViewWidget.java

index 30d6593..6f30e44 100644 (file)
@@ -1,11 +1,10 @@
 package org.scilab.modules.graphic_objects.xmlloader;
 
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_IMAGE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACKTYPE__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOREGROUNDCOLOR__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACK__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CLOSEREQUESTFCN__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_DOCKABLE__;
@@ -39,6 +38,7 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTNAME__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTSIZE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTWEIGHT__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOREGROUNDCOLOR__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_COLOR__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_HIGHLIGHT_IN__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__;
@@ -188,7 +188,7 @@ public class GOBuilder {
     public static Integer axesBuilder(GraphicController controller, Attributes attributes) {
         Integer axes = GraphicController.getController().askObject(Type.AXES);
         String id = attributes.getValue("id");
-        if(id != null) {
+        if (id != null) {
             controller.setProperty(axes, __GO_TAG__, id);
         }
         return axes;
@@ -291,6 +291,8 @@ public class GOBuilder {
 
 
             //font properties
+
+            //fontname
             item = xmlAttributes.get("font-name");
             if (item != null) {
                 controller.setProperty(uic, __GO_UI_FONTNAME__, item);
@@ -301,6 +303,7 @@ public class GOBuilder {
                 controller.setProperty(uic, __GO_UI_FONTNAME__, item);
             }
 
+            //fontsize
             item = xmlAttributes.get("font-size");
             if (item != null) {
                 controller.setProperty(uic, __GO_UI_FONTSIZE__, Double.parseDouble(item));
@@ -311,6 +314,34 @@ public class GOBuilder {
                 controller.setProperty(uic, __GO_UI_FONTSIZE__, Double.parseDouble(item));
             }
 
+            //units and position
+            String[] units = null;
+            item = xmlAttributes.get("units");
+            if (item != null) {
+                units = item.split("[,;]");
+            }
+
+            //position, take care of units values
+            item = xmlAttributes.get("position");
+            if (item != null) {
+                Double[] pos = new Double[4];
+                Double[] parentSize = new Double[] {934.0, 511.0};
+                String[] strPos = item.split("[,;]");
+                for (int i = 0 ; i < strPos.length ; i++) {
+                    pos[i] = Double.parseDouble(strPos[i]);
+                    if (units != null && units[i].equals("n")) {
+                        //convert %age to pixel
+                        pos[i] = parentSize[i % 2] * pos[i];
+                    }
+                }
+
+                controller.setProperty(uic,  __GO_POSITION__, pos);
+            }
+
+            item = xmlAttributes.get("opaque");
+            if (item != null && (item.equals("false") || item.equals("off"))) {
+                controller.setProperty(uic, __GO_UI_BACKGROUNDCOLOR__, new Double[] { -2.0, -2.0, -2.0});
+            }
 
             if (layout != LayoutType.NONE) {
                 item = xmlAttributes.get("constraint");
@@ -325,7 +356,7 @@ public class GOBuilder {
                         Integer[] preferredsize = new Integer[] { -1, -1};
                         item = xmlAttributes.get("preferred-size");
                         if (item != null) {
-                            String[] pref = item.split(",");
+                            String[] pref = item.split("[,;]");
                             for (int i = 0; i < pref.length && i < 4; i++) {
                                 preferredsize[i] = Integer.parseInt(pref[i]);
                             }
@@ -355,7 +386,7 @@ public class GOBuilder {
                         Integer[] preferredsize = new Integer[] { -1, -1};
                         item = xmlAttributes.get("preferred-size");
                         if (item != null) {
-                            String[] pref = item.split(",");
+                            String[] pref = item.split("[,;]");
                             for (int i = 0; i < pref.length && i < 4; i++) {
                                 preferredsize[i] = Integer.parseInt(pref[i]);
                             }
@@ -375,7 +406,7 @@ public class GOBuilder {
                 // insets -> marging
                 String insets = XmlTools.getFromMap(map, "insets", "0,0,0,0");
                 Double[] margins = new Double[] { 0.0, 0.0, 0.0, 0.0 };
-                String[] inset = insets.split(",");
+                String[] inset = insets.split("[,;]");
                 for (int i = 0; i < inset.length && i < 4; i++) {
                     margins[i] = Double.parseDouble(inset[i]);
                 }
index cdbdbf1..8912787 100644 (file)
@@ -21,7 +21,12 @@ static int checkColorComponent(double c)
 /*--------------------------------------------------------------------------*/
 int checkColorRange(double r, double g, double b)
 {
-    if (r == -1 && g == -1 && b == -1)
+    if (r == -1 && g == -1 && b == -1) //default laf
+    {
+        return 1;
+    }
+
+    if (r == -2 && g == -2 && b == -2) //transparence
     {
         return 1;
     }
index 1719df8..5e23bed 100644 (file)
@@ -37,6 +37,8 @@ import java.awt.Color;
 import java.awt.Component;
 import java.awt.Font;
 
+import javax.swing.JComponent;
+
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.graphic_objects.graphicObject.CallBack;
 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
@@ -82,15 +84,19 @@ public final class SwingViewWidget {
         switch (property) {
             case __GO_UI_BACKGROUNDCOLOR__: {
                 Double[] allColors = ((Double[]) value);
-                if (allColors[0] != -1) {
+                if (allColors[0] == -1) {
+                    // Do not set BackgroundColor for widgets
+                    // rely on Look and Feel
+                    ((JComponent) uiControl).setOpaque(true);
+                    uiControl.resetBackground();
+                } else if (allColors[0] == -2) {
+                    ((JComponent) uiControl).setOpaque(false);
+                } else {
+                    ((JComponent) uiControl).setOpaque(true);
                     uiControl.setBackground(new Color(
                                                 (int) (allColors[0] * COLORS_COEFF),
                                                 (int) (allColors[1] * COLORS_COEFF),
                                                 (int) (allColors[2] * COLORS_COEFF)));
-                } else {
-                    // Do not set BackgroundColor for widgets
-                    // rely on Look and Feel
-                    uiControl.resetBackground();
                 }
                 break;
             }