add management of layer in SwingView 57/13657/4
Antoine ELIAS [Tue, 4 Feb 2014 15:12:10 +0000 (16:12 +0100)]
Change-Id: Id4ffb4e66e58a1e1e8ce7ed85c18bcf3ea56008b

scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicObject/GraphicObject.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/uicontrol/layer/Layer.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XmlLoader.java
scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java
scilab/modules/gui/src/java/org/scilab/modules/gui/SwingViewWidget.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/editbox/SwingScilabEditBox.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabFrame.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabLayer.java [new file with mode: 0644]
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/slider/SwingScilabScroll.java
scilab/modules/gui/tests/unit_tests/layer.dia.ref [new file with mode: 0644]
scilab/modules/gui/tests/unit_tests/layer.tst [new file with mode: 0644]

index bb7cea5..fe63411 100644 (file)
@@ -679,6 +679,10 @@ public abstract class GraphicObject implements Cloneable {
      * @return TODO
      */
     public UpdateStatus setVisible(Boolean visible) {
+        if (this.visible == visible) {
+            return UpdateStatus.NoChange;
+        }
+
         this.visible = visible;
         return UpdateStatus.Success;
     }
index 25eb85a..95fc28f 100644 (file)
@@ -125,6 +125,7 @@ public class XmlLoader extends DefaultHandler {
         /** sdsdf*/
         nameToGO.put("UITextarea", __GO_UI_PUSHBUTTON__);
         nameToGO.put("UIScilabPlot", __GO_UI_PUSHBUTTON__);
+        nameToGO.put("UIComboColor", __GO_UI_POPUPMENU__);
 
     }
 
index d187269..881b704 100644 (file)
@@ -104,6 +104,7 @@ import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
 import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
+import org.scilab.modules.gui.bridge.frame.SwingScilabLayer;
 import org.scilab.modules.gui.bridge.label.SwingScilabLabel;
 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
 import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
@@ -394,19 +395,19 @@ public final class SwingView implements GraphicView {
                 menuBar.setVisible(figure.getMenubarVisible());
                 tab.setMenuBar(menuBar);
                 window.addMenuBar(menuBar);
-                
+
                 /* TOOLBAR */
                 ToolBar toolbar = ScilabToolBar.createToolBar();
                 toolbar.setVisible(figure.getToolbarVisible());
                 tab.setToolBar(toolbar);
                 window.addToolBar(toolbar);
-                
+
                 /* INFOBAR */
                 TextBox infoBar = ScilabTextBox.createTextBox();
                 infoBar.setVisible(figure.getInfobarVisible());
                 tab.setInfoBar(infoBar);
                 window.addInfoBar(infoBar);
-                
+
                 if (figure.getDockable()) {
                     DockingManager.dock((SwingScilabDockablePanel) tab, window.getDockingPort());
                     ActiveDockableTracker.requestDockableActivation((SwingScilabDockablePanel) tab);
@@ -431,10 +432,8 @@ public final class SwingView implements GraphicView {
                 tab.update(__GO_POSITION__, GraphicController.getController().getProperty(id, __GO_POSITION__));
                 // TODO set other default properties
 
+                window.setVisible(figure.getVisible());
                 window.pack();
-                if (!figure.getDockable()) {
-                    window.setVisible(figure.getVisible());
-                }
                 return tab;
             case Axes:
                 SwingScilabCanvas axes = new SwingScilabCanvas(null);
@@ -533,8 +532,7 @@ public final class SwingView implements GraphicView {
                 //TabGroup.update(property, value);
                 return TabGroup;
             case Layer:
-                SwingScilabFrame layer = new SwingScilabFrame();
-                layer.setLayout(new CardLayout());
+                SwingScilabLayer layer = new SwingScilabLayer();
                 layer.setId(id);
                 return layer;
             default:
@@ -881,13 +879,13 @@ public final class SwingView implements GraphicView {
                 updatedObject.addChild(childId);
 
                 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
-                
+
                 /* Add an Axes */
                 if (childType == __GO_AXES__) {
                     SwingViewObject canvas = allObjects.get(childId).getValue();
                     ((SwingScilabPanel) updatedComponent).addMember(canvas);
                 }
-                
+
                 /* Add an uicontrol */
                 if (childType == __GO_UICONTROL__) {
                     SwingViewObject uiContol = allObjects.get(childId).getValue();
@@ -1017,7 +1015,6 @@ public final class SwingView implements GraphicView {
      */
     private void updateLayerChildren(TypedObject updatedObject, Integer[] newChildren) {
         Container updatedComponent = (SwingScilabFrame) updatedObject.getValue();
-        boolean needRevalidate = false;
 
         // Add new children
         for (Integer childId : newChildren) {
@@ -1030,8 +1027,10 @@ public final class SwingView implements GraphicView {
 
                 /* Add an uicontrol */
                 if (childType == __GO_UICONTROL__) {
-                    ((SwingScilabFrame) updatedComponent).add((Component) allObjects.get(childId).getValue(), Integer.toString(allObjects.get(childId).getValue().getId()));
-                    needRevalidate = true;
+                    int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
+                    if (childStyle == __GO_UI_FRAME__) {
+                        ((SwingScilabLayer) updatedComponent).addMember((SwingScilabFrame) allObjects.get(childId).getValue());
+                    }
                 }
             }
         }
@@ -1050,14 +1049,13 @@ public final class SwingView implements GraphicView {
 
                 /* Remove an uicontrol */
                 if (childType == __GO_UICONTROL__) {
-                    updatedComponent.remove((Component) allObjects.get(childId).getValue());
-                    needRevalidate = true;
+                    int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
+                    if (childStyle == __GO_UI_FRAME__) {
+                        ((SwingScilabLayer) updatedComponent).removeMember((SwingScilabFrame) allObjects.get(childId).getValue());
+                    }
                 }
             }
         }
-        if (needRevalidate && updatedComponent != null) {
-            ((JPanel) updatedComponent).revalidate();
-        }
     }
 
     /**
index 055d085..7f95c20 100644 (file)
@@ -24,6 +24,7 @@ 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_STYLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TAG__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BACKGROUNDCOLOR__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTANGLE__;
@@ -49,6 +50,8 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_USER_DATA__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VALID__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LAYER__;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -65,6 +68,7 @@ import org.scilab.modules.graphic_objects.utils.LayoutType;
 import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
+import org.scilab.modules.gui.bridge.frame.SwingScilabLayer;
 import org.scilab.modules.gui.bridge.groupmanager.GroupManager;
 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
 import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
@@ -82,6 +86,8 @@ import org.scilab.modules.gui.utils.UnitsConverter;
 import org.scilab.modules.gui.utils.UnitsConverter.UicontrolUnits;
 import org.scilab.modules.gui.widget.Widget;
 
+import com.sun.org.apache.bcel.internal.generic.AllocationInstruction;
+
 /**
  * @author Bruno JOFRET
  * @author Vincent COUVERT
@@ -189,7 +195,11 @@ public final class SwingViewWidget {
 
                         font = new Font(name, font.getStyle(), font.getSize());
 
-                        uiControl.setFont(font);
+                        if (uiControl instanceof SwingScilabEditBox) {
+                            ((SwingScilabEditBox)uiControl).setEditFont(font);
+                        } else {
+                            uiControl.setFont(font);
+                        }
                     }
                 }
                 break;
@@ -542,6 +552,10 @@ public final class SwingViewWidget {
                     shear[1] = imageParams[3];
                     ((SwingScilabUiImage) uiControl).setShear(shear);
                     ((SwingScilabUiImage) uiControl).setRotate(imageParams[4]);
+                } else if (uiControl instanceof SwingScilabLayer) {
+                    SwingScilabLayer layer = (SwingScilabLayer)uiControl;
+                    //if intValue[0] is out of bounds, do not update view but let "wrong" value in model
+                    layer.setActiveLayer(intValue[0]);
                 }
                 break;
             case __GO_UI_VERTICALALIGNMENT__ : {
@@ -551,9 +565,35 @@ public final class SwingViewWidget {
                 }
                 break;
             }
-            case __GO_VISIBLE__ :
-                uiControl.setVisible(((Boolean) value).booleanValue());
+            case __GO_VISIBLE__ : {
+                boolean needUpdate = true;
+                if (uiControl instanceof SwingScilabFrame) {
+                    SwingScilabFrame frame = (SwingScilabFrame) uiControl;
+                    Integer parent = (Integer) controller.getProperty(frame.getId(), __GO_PARENT__);
+                    if (parent != 0) {
+                        Integer type = (Integer) controller.getProperty(parent, __GO_TYPE__);
+                        if (type == __GO_UICONTROL__) {
+                            Integer style = (Integer) controller.getProperty(parent, __GO_STYLE__);
+                            if (style == __GO_UI_LAYER__) {
+                                //no no no don't touch visible on layer children !
+                                Boolean visible = (Boolean)value;
+                                SwingScilabLayer layer = (SwingScilabLayer) SwingView.getFromId(parent);
+                                Boolean isActive = layer.isLayerActive(frame);
+                                if (isActive != visible ) {
+                                    controller.setProperty(frame.getId(), __GO_VISIBLE__, isActive);
+                                }
+
+                                needUpdate = false;
+                            }
+                        }
+                    }
+                }
+
+                if (needUpdate) {
+                    uiControl.setVisible(((Boolean) value).booleanValue());
+                }
                 break;
+            }
             case __GO_PARENT__:
                 /* Update position */
                 SwingViewWidget.update(uiControl, __GO_POSITION__, controller.getProperty(uid, __GO_POSITION__));
index 58e84c1..e65e4bf 100644 (file)
@@ -14,7 +14,6 @@
 
 package org.scilab.modules.gui.bridge.editbox;
 
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
 
 import java.awt.Color;
@@ -43,8 +42,8 @@ import javax.swing.text.StyledEditorKit;
 import javax.swing.text.View;
 import javax.swing.text.ViewFactory;
 
+import org.scilab.modules.graphic_objects.console.Console;
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
-import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorderType;
 import org.scilab.modules.gui.SwingView;
 import org.scilab.modules.gui.SwingViewObject;
 import org.scilab.modules.gui.SwingViewWidget;
@@ -109,8 +108,8 @@ public class SwingScilabEditBox extends JScrollPane implements SwingViewObject,
                     offsets[i] += offset;
                 }
             } else {
-                // TOP_ALIGNEMENT or other 
-                // default behaviour : do nothing special 
+                // TOP_ALIGNEMENT or other
+                // default behaviour : do nothing special
             }
         }
     }
@@ -174,7 +173,10 @@ public class SwingScilabEditBox extends JScrollPane implements SwingViewObject,
         InputMap map = textPane.getInputMap();
         enterKeyAction = map.get(enterKey);
 
-        StyleConstants.setAlignment(docAttributes, StyleConstants.ALIGN_CENTER);
+        if (Console.getConsole().getUseDeprecatedLF() == false) {
+            setEditFont(getFont());
+        }
+        //StyleConstants.setAlignment(docAttributes, StyleConstants.ALIGN_CENTER);
     }
 
     /**
@@ -405,8 +407,8 @@ public class SwingScilabEditBox extends JScrollPane implements SwingViewObject,
             StyleConstants.setBackground(docAttributes, bg);
         }
     }
-    
-    public void setFont(Font font) {
+
+    public void setEditFont(Font font) {
         super.setFont(font);
         if (textPane != null) {
             textPane.setFont(font);
index 8b27d75..04fe452 100644 (file)
@@ -15,7 +15,6 @@ package org.scilab.modules.gui.bridge.frame;
 
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
 
 import java.awt.BorderLayout;
@@ -31,7 +30,6 @@ import javax.swing.JPanel;
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
 import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
-import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorderType;
 import org.scilab.modules.gui.SwingView;
 import org.scilab.modules.gui.SwingViewObject;
 import org.scilab.modules.gui.SwingViewWidget;
diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabLayer.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabLayer.java
new file mode 100644 (file)
index 0000000..11ce7c5
--- /dev/null
@@ -0,0 +1,143 @@
+package org.scilab.modules.gui.bridge.frame;
+
+
+
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VALUE__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
+
+import java.awt.CardLayout;
+import java.awt.Component;
+import java.util.ArrayList;
+
+import org.scilab.modules.graphic_objects.graphicController.GraphicController;
+
+public class SwingScilabLayer extends SwingScilabFrame {
+    private static final long serialVersionUID = 9038916804095320758L;
+    private ArrayList<String> layerName = new ArrayList<String>();
+    private CardLayout layout = new CardLayout();
+
+    public SwingScilabLayer() {
+        super();
+        setLayout(layout);
+    }
+
+    public void addMember(SwingScilabFrame member) {
+        String name = member.getId().toString();
+        member.setName(name);
+        layerName.add(name);
+        add(member, name);
+        revalidate();
+        //active the first child
+        if (getActiveLayer() == -1) {
+            setActiveLayer(1);
+        }
+
+    }
+
+    public Integer getActiveLayer() {
+        SwingScilabFrame card = null;
+        for (Component comp : getComponents()) {
+            if (comp.isVisible() == true) {
+                card = (SwingScilabFrame) comp;
+                break;
+            }
+        }
+
+        if (card == null) {
+            return -1;
+        }
+
+        return layerName.indexOf(card.getName()) + 1;
+    }
+
+    private SwingScilabFrame getLayerFromIndex(Integer layer) {
+        if (layer < 1 || layer > getComponentCount()) {
+            return null;
+        }
+
+        return (SwingScilabFrame) getComponent(layer - 1);
+    }
+
+    private Integer getLayerIndex(SwingScilabFrame layer) {
+        for (int i = 0; i < getComponentCount(); i++) {
+            if (getComponent(i) == layer) {
+                return i + 1;
+            }
+        }
+
+        return -1;
+    }
+
+    public Boolean isLayerActive(Integer layer) {
+        return getActiveLayer() == layer;
+    }
+
+
+    public Boolean isLayerActive(SwingScilabFrame layer) {
+        Integer index = getLayerIndex(layer);
+        if (index == -1) {
+            return false;
+        }
+
+        return isLayerActive(index);
+    }
+
+
+    public void removeMember(SwingScilabFrame member) {
+        layerName.remove(member.getId().toString());
+        remove(member);
+        revalidate();
+
+        //update model with new index
+        Integer active = getActiveLayer();
+        if (active == -1) {
+            if (setActiveLayer(1)) {
+                active = 1;
+            }
+        }
+
+        //update model with new index
+        GraphicController.getController().setProperty(getId(),  __GO_UI_VALUE__, new Double[] {active.doubleValue()});
+    }
+
+    public boolean setActiveLayer(Integer layerPos) {
+        if (layerPos < 1 || layerPos > layerName.size()) {
+            return false;
+        }
+
+        Integer previous = getActiveLayer();
+        if (setActiveLayer(layerName.get(layerPos - 1)) == false) {
+            return false;
+        }
+
+        Integer next = getActiveLayer();
+        updateChildrenVisible(previous, next);
+        return true;
+    }
+
+    private boolean setActiveLayer(String layer) {
+        //check existing item
+        if (layerName.contains(layer)) {
+            layout.show(this, layer);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private void updateChildrenVisible(Integer previous, Integer next) {
+        SwingScilabFrame previousFrame = getLayerFromIndex(previous);
+        SwingScilabFrame nextFrame = getLayerFromIndex(next);
+
+        if (previousFrame != null) {
+            GraphicController.getController().setProperty(previousFrame.getId(), __GO_VISIBLE__, false);
+        }
+
+        if (nextFrame != null) {
+            GraphicController.getController().setProperty(nextFrame.getId(), __GO_VISIBLE__, true);
+        }
+
+        GraphicController.getController().setProperty(getId(),  __GO_UI_VALUE__, new Double[] {next.doubleValue()});
+
+    }
+}
index 0ce69e1..62a153a 100644 (file)
@@ -244,7 +244,6 @@ public class SwingScilabScroll extends JScrollBar implements SwingViewObject, Si
         setVisibleAmount(Math.max((int) ((MAXIMUM_VALUE - MINIMUM_VALUE) / space), MIN_KNOB_SIZE));
         setMaximum(oldMax + getVisibleAmount());
 
-        System.out.println("old major = " + (int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
         /* Put back the listener */
         addAdjustmentListener(adjustmentListener);
     }
@@ -260,7 +259,6 @@ public class SwingScilabScroll extends JScrollBar implements SwingViewObject, Si
         double userMin = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MIN__);
         double userMax = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MAX__);
         setUnitIncrement((int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
-        System.out.println("old minor = " + (int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
 
         /* Put back the listener */
         addAdjustmentListener(adjustmentListener);
diff --git a/scilab/modules/gui/tests/unit_tests/layer.dia.ref b/scilab/modules/gui/tests/unit_tests/layer.dia.ref
new file mode 100644 (file)
index 0000000..b1f8cc9
--- /dev/null
@@ -0,0 +1,55 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+function layer = create_layer(count)
+    c = get(0);c.usedeprecatedskin = "off"
+    f = figure("dockable", "off" ,"infobar_visible", "off", "toolbar_visible", "off", "menubar_visible", "off", "layout", "border")
+    f.figure_size = [300, 300];
+    //layer
+    layer = uicontrol(f, "style", "layer", "constraints", createConstraints("border", "center"));
+    for i = 1:count
+        fr1 = uicontrol(layer, "style", "frame");
+        fr1.layout_options = createLayoutOptions("border", [10, 10]);
+        fr1.layout = "border";
+        uicontrol(fr1, "string", "button " + string(i) + "1", "constraints", createConstraints("border", "top"));
+        uicontrol(fr1, "string", "button " + string(i) + "2", "constraints", createConstraints("border", "left"));
+        uicontrol(fr1, "string", "button " + string(i) + "3", "constraints", createConstraints("border", "center"));
+        uicontrol(fr1, "string", "button " + string(i) + "4", "constraints", createConstraints("border", "bottom"));
+        uicontrol(fr1, "string", "button " + string(i) + "5", "constraints", createConstraints("border", "right"));
+    end
+endfunction
+//1 layer
+layer = create_layer(1);
+visible1 = ['on'];
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible1);
+//4 layers
+delete(gcf());
+layer = create_layer(4);
+visible1 = ['off' 'off' 'off' 'on'];
+visible2 = ['off' 'off' 'on' 'off'];
+visible3 = ['off' 'on' 'off' 'off'];
+visible4 = ['on' 'off' 'off' 'off'];
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+assert_checkequal(layer.children.visible, visible2);
+layer.value = 3;
+assert_checkequal(layer.value, 3);
+assert_checkequal(layer.children.visible, visible3);
+layer.value = 4;
+assert_checkequal(layer.value, 4);
+assert_checkequal(layer.children.visible, visible4);
+layer.value = 10;
+assert_checkequal(layer.value, 10);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible4);
diff --git a/scilab/modules/gui/tests/unit_tests/layer.tst b/scilab/modules/gui/tests/unit_tests/layer.tst
new file mode 100644 (file)
index 0000000..29e5636
--- /dev/null
@@ -0,0 +1,69 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- TEST WITH GRAPHIC -->
+
+function layer = create_layer(count)
+    c = get(0);c.usedeprecatedskin = "off"
+    f = figure("dockable", "off" ,"infobar_visible", "off", "toolbar_visible", "off", "menubar_visible", "off", "layout", "border")
+    f.figure_size = [300, 300];
+
+    //layer
+    layer = uicontrol(f, "style", "layer", "constraints", createConstraints("border", "center"));
+
+    for i = 1:count
+        fr1 = uicontrol(layer, "style", "frame");
+        fr1.layout_options = createLayoutOptions("border", [10, 10]);
+        fr1.layout = "border";
+        uicontrol(fr1, "string", "button " + string(i) + "1", "constraints", createConstraints("border", "top"));
+        uicontrol(fr1, "string", "button " + string(i) + "2", "constraints", createConstraints("border", "left"));
+        uicontrol(fr1, "string", "button " + string(i) + "3", "constraints", createConstraints("border", "center"));
+        uicontrol(fr1, "string", "button " + string(i) + "4", "constraints", createConstraints("border", "bottom"));
+        uicontrol(fr1, "string", "button " + string(i) + "5", "constraints", createConstraints("border", "right"));
+    end
+endfunction
+
+//1 layer
+layer = create_layer(1);
+visible1 = ['on'];
+
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible1);
+
+//4 layers
+delete(gcf());
+layer = create_layer(4);
+
+visible1 = ['off' 'off' 'off' 'on'];
+visible2 = ['off' 'off' 'on' 'off'];
+visible3 = ['off' 'on' 'off' 'off'];
+visible4 = ['on' 'off' 'off' 'off'];
+
+assert_checkequal(layer.value, 1);
+assert_checkequal(layer.children.visible, visible1);
+
+layer.value = 2;
+assert_checkequal(layer.value, 2);
+assert_checkequal(layer.children.visible, visible2);
+
+layer.value = 3;
+assert_checkequal(layer.value, 3);
+assert_checkequal(layer.children.visible, visible3);
+
+layer.value = 4;
+assert_checkequal(layer.value, 4);
+assert_checkequal(layer.children.visible, visible4);
+
+layer.value = 10;
+assert_checkequal(layer.value, 10);
+//if value is out of bounds, nothing happen but value is normally set
+assert_checkequal(layer.children.visible, visible4);