uicontrol string and value property can be [] 69/13769/2
Antoine ELIAS [Mon, 17 Feb 2014 17:37:18 +0000 (18:37 +0100)]
Change-Id: I8fd702321ab7eaa04a57ba007f3fcf15f99e4d63

scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/uicontrol/Uicontrol.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/uicontrol/listbox/ListBox.java
scilab/modules/gui/src/cpp/GetUicontrolString.cpp
scilab/modules/gui/src/cpp/SetUicontrolString.cpp
scilab/modules/gui/src/cpp/SetUicontrolValue.cpp
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/listbox/SwingScilabListBox.java

index dbbcf50..cdd9338 100644 (file)
@@ -14,8 +14,8 @@
 
 package org.scilab.modules.graphic_objects.uicontrol;
 
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_GRID__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_PADDING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT_SET__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
@@ -1045,7 +1045,14 @@ public class Uicontrol extends GraphicObject {
     public UpdateStatus setString(String[] string) {
         if (this.style == UicontrolStyle.LISTBOX || this.style == UicontrolStyle.POPUPMENU) {
             /* String can be set using a|b|c|d */
-            if (string.length == 1 & string[0].contains(STRING_SEPARATOR)) {
+            if (string.length == 0) {
+                if (this.string.length == 0) {
+                    return UpdateStatus.NoChange;
+                }
+
+                this.string = string;
+                return UpdateStatus.Success;
+            } else if (string.length == 1 && string[0].contains(STRING_SEPARATOR)) {
                 StringTokenizer strTok = new StringTokenizer(string[0], STRING_SEPARATOR);
                 String[] stringTab = new String[strTok.countTokens()];
                 while (strTok.hasMoreTokens()) {
@@ -1055,6 +1062,7 @@ public class Uicontrol extends GraphicObject {
                 return UpdateStatus.Success;
             }
         }
+
         this.string = string;
         return UpdateStatus.Success;
     }
index f2c073f..0cb236c 100644 (file)
@@ -31,11 +31,7 @@ public class ListBox extends Uicontrol {
     public ListBox() {
         super();
         setStyle(__GO_UI_LISTBOX__);
-
-        // Default value is the min value
-        Double[] value = new Double[1];
-        value[0] = getMin();
-        setUiValue(value);
+        setUiValue(new Double[] {});
 
         if (Console.getConsole().getUseDeprecatedLF()) {
             setRelief(RELIEF_FLAT);
@@ -53,4 +49,7 @@ public class ListBox extends Uicontrol {
         }
     }
 
+    public UpdateStatus setUiValue(Double[] value) {
+        return super.setUiValue(value);
+    }
 }
index 38132cc..c9b2278 100644 (file)
@@ -29,10 +29,16 @@ int GetUicontrolString(void* _pvCtx, int iObjUID)
 
     getGraphicObjectProperty(iObjUID, __GO_UI_STRING_SIZE__, jni_int, (void **) &piNbStrings);
     getGraphicObjectProperty(iObjUID, __GO_UI_STRING__, jni_string_vector, (void **) &pstString);
-
     if (pstString != NULL)
     {
-        return sciReturnStringMatrix(_pvCtx, pstString, 1, iNbStrings);
+        if (iNbStrings == 0)
+        {
+            return sciReturnEmptyMatrix(_pvCtx);
+        }
+        else
+        {
+            return sciReturnStringMatrix(_pvCtx, pstString, 1, iNbStrings);
+        }
     }
     else
     {
index 17568ca..4b10030 100644 (file)
@@ -32,6 +32,13 @@ int SetUicontrolString(void* _pvCtx, int iObjUID, void* _pvData, int valueType,
         return SET_PROPERTY_ERROR;
     }
 
+    //[]
+    if (valueType == sci_matrix && nbRow == 0 && nbCol == 0)
+    {
+        status = setGraphicObjectProperty(iObjUID, __GO_UI_STRING__, (char**)NULL, jni_string_vector, 0);
+        return SET_PROPERTY_ERROR;
+    }
+
     // Label must be a character string
     if (valueType != sci_strings)
     {
index 396f427..b0b32e4 100644 (file)
@@ -120,6 +120,24 @@ int SetUicontrolValue(void* _pvCtx, int iObjUID, void* _pvData, int valueType, i
 
     if (objectStyle == __GO_UI_POPUPMENU__ || objectStyle == __GO_UI_LISTBOX__)
     {
+        int iDataSize = 0;
+        int* piDataSize = & iDataSize;
+        getGraphicObjectProperty(iObjUID, __GO_UI_STRING_SIZE__, jni_int, (void**)&piDataSize);
+        if (piDataSize == NULL)
+        {
+            Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "Value");
+            return SET_PROPERTY_ERROR;
+        }
+
+        for (int i = 0 ; i < valueSize ; i++)
+        {
+            if (truncatedValue[i] < 0 || truncatedValue[i] > iDataSize)
+            {
+                Scierror(999, _("'%s' value must be between 0 and %d.\n"), "Value", iDataSize);
+                return SET_PROPERTY_ERROR;
+            }
+        }
+
         status = setGraphicObjectProperty(iObjUID, __GO_UI_VALUE__, truncatedValue, jni_double_vector, valueSize);
     }
     else
index da49d85..a26d394 100644 (file)
@@ -521,10 +521,7 @@ public final class SwingViewWidget {
                     intValue[k] = doubleValue[k].intValue();
                 }
 
-                if (uiControl instanceof SwingScilabListBox) {
-                    // Update selected items in the listbox
-                    ((SwingScilabListBox) uiControl).setSelectedIndices(intValue);
-                } else if (uiControl instanceof SwingScilabPopupMenu) {
+                if (uiControl instanceof SwingScilabPopupMenu) {
                     // Update selected items in the popupmenu
                     ((SwingScilabPopupMenu) uiControl).setUserSelectedIndex(intValue[0]);
                 } else if (uiControl instanceof SwingScilabCheckBox) {
index c41c2d2..7fe1ebd 100644 (file)
@@ -450,19 +450,19 @@ public class SwingScilabEditBox extends JScrollPane implements SwingViewObject,
     public void update(int property, Object value) {
         switch (property) {
             case __GO_UI_MAX__ : {
-                Double columns = (Double)value;
-                Graphics g = textPane.getGraphics();
-                Integer width = 50;
-                if (g != null) {
-                    width = textPane.getGraphics().getFontMetrics(textPane.getFont()).charWidth('m');
-                }
-                Integer totalWidth = columns.intValue() * width;
-                Dimension current = textPane.getPreferredSize();
-                System.out.println("current : " + current.toString());
-                current.width = totalWidth;
-                textPane.setPreferredSize(current);
-                current = textPane.getPreferredSize();
-                System.out.println("new : " + current.toString());
+                //                Double columns = (Double)value;
+                //                Graphics g = textPane.getGraphics();
+                //                Integer width = 50;
+                //                if (g != null) {
+                //                    width = textPane.getGraphics().getFontMetrics(textPane.getFont()).charWidth('m');
+                //                }
+                //                Integer totalWidth = columns.intValue() * width;
+                //                Dimension current = textPane.getPreferredSize();
+                //                System.out.println("current : " + current.toString());
+                //                current.width = totalWidth;
+                //                textPane.setPreferredSize(current);
+                //                current = textPane.getPreferredSize();
+                //                System.out.println("new : " + current.toString());
                 break;
             }
 
index d228669..2419917 100644 (file)
@@ -81,6 +81,8 @@ public class SwingScilabListBox extends JScrollPane implements SwingViewObject,
                 for (int i = 0; i < getList().getSelectedIndices().length; i++) {
                     scilabIndices[i] = (double) javaIndices[i] + 1;
                 }
+
+                System.out.println("scilabIndices : " + scilabIndices.length);
                 GraphicController.getController().setProperty(uid, __GO_UI_VALUE__, scilabIndices);
                 if (e.getButton() == MouseEvent.BUTTON1 && callback != null) {
                     callback.actionPerformed(null);
@@ -514,7 +516,21 @@ public class SwingScilabListBox extends JScrollPane implements SwingViewObject,
      * @param value property value
      */
     public void update(int property, Object value) {
-        SwingViewWidget.update(this, property, value);
+        switch (property) {
+            case __GO_UI_VALUE__ : {
+                Double[] indexes = (Double[])value;
+                int[] index = new int[indexes.length];
+                for (int i = 0 ; i < indexes.length ; i++) {
+                    index[i] = indexes[i].intValue();
+                }
+                setSelectedIndices(index);
+                break;
+            }
+
+            default : {
+                SwingViewWidget.update(this, property, value);
+            }
+        }
     }
 
     public void resetBackground() {