fix bug on set string property for popupmenu and listbox 74/13974/2
Antoine ELIAS [Tue, 11 Mar 2014 14:40:04 +0000 (15:40 +0100)]
Change-Id: I0145bf2f0dfaf236ad972935f4e4a59f2995fa5a

scilab/modules/commons/src/java/org/scilab/modules/commons/gui/FindIconHelper.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/listbox/SwingScilabListBox.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/popupmenu/SwingScilabPopupMenu.java

index 70251ff..8056a97 100644 (file)
@@ -24,7 +24,11 @@ public final class FindIconHelper {
      * @return the image icon path
      */
     public static String findIcon(final String icon) {
-        return findIcon(icon, "16x16");
+        return findIcon(icon, "16x16", true);
+    }
+
+    public static String findIcon(final String icon, boolean defaultValue) {
+        return findIcon(icon, "16x16", defaultValue);
     }
 
     /**
@@ -37,6 +41,10 @@ public final class FindIconHelper {
      * @return the loaded image icon
      */
     public static String findIcon(final String icon, final String size) {
+        return findIcon(icon, size, true);
+    }
+
+    public static String findIcon(final String icon, final String size, boolean defaultValue) {
         if (icon == null || icon.isEmpty()) {
             return null;
         }
@@ -50,7 +58,7 @@ public final class FindIconHelper {
         }
 
         final String fallback = lookupFallbackIcon(icon);
-        if (fallback == null) {
+        if (defaultValue && fallback == null) {
             LOG.warning("Unable to found icon: " + icon + '[' + size + ']');
             return System.getenv("SCI") + "/modules/gui/images/icons/16x16/status/error.png";
         }
@@ -229,6 +237,10 @@ public final class FindIconHelper {
     }
 
     public static String findImage(final String image) {
+        return findImage(image, true);
+    }
+
+    public static String findImage(final String image, boolean defaulValue) {
 
         File file = new File(ScilabCommonsUtils.getCorrectedPath(image));
         if (file.exists()) {
@@ -242,7 +254,7 @@ public final class FindIconHelper {
             }
         }
 
-        return findIcon(image);
+        return findIcon(image, defaulValue);
     }
 
     private static String lookupFallbackIcon(final String icon) {
index fffa761..d7fddec 100644 (file)
@@ -376,6 +376,7 @@ public class SwingScilabListBox extends JScrollPane implements SwingViewObject,
             //combocolor ?
             colorBox = true;
 
+            //first try to convert 2nd col to color
             if (colorRenderer == null) {
                 colorRenderer = new ListCellRenderer() {
                     public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
@@ -432,11 +433,25 @@ public class SwingScilabListBox extends JScrollPane implements SwingViewObject,
                 int iconOffset = text.length / 2;
                 try {
                     for (int i = 0; i < iconOffset; i++) {
-                        String iconFile = FindIconHelper.findIcon((text[iconOffset + i]));
-                        //add item in combobox
+                        String iconFile = FindIconHelper.findIcon((text[iconOffset + i]), false);
+                        if (iconFile == null) {
+                            model.clear();
+                            iconBox = false;
+                            colorBox = false;
+                            break;
+                        }
+
+                        //add item in listbox
                         File file = new File(iconFile);
                         if (file.exists() == false) {
-                            String filename = FindIconHelper.findImage(iconFile);
+                            String filename = FindIconHelper.findImage(iconFile, false);
+                            if (filename == null) {
+                                model.clear();
+                                iconBox = false;
+                                colorBox = false;
+                                break;
+                            }
+
                             file = new File(filename);
                         }
 
index ca020e3..c7bffff 100644 (file)
@@ -382,11 +382,25 @@ public class SwingScilabPopupMenu extends JComboBox implements SwingViewObject,
                 int iconOffset = text.length / 2;
                 try {
                     for (int i = 0; i < iconOffset; i++) {
-                        String iconFile = FindIconHelper.findIcon((text[iconOffset + i]));
+                        String iconFile = FindIconHelper.findIcon((text[iconOffset + i]), false);
+                        if (iconFile == null) {
+                            removeAllItems();
+                            iconBox = false;
+                            colorBox = false;
+                            break;
+                        }
+
                         //add item in combobox
                         File file = new File(iconFile);
                         if (file.exists() == false) {
-                            String filename = FindIconHelper.findImage(iconFile);
+                            String filename = FindIconHelper.findImage(iconFile, false);
+                            if (filename == null) {
+                                removeAllItems();
+                                iconBox = false;
+                                colorBox = false;
+                                break;
+                            }
+
                             file = new File(filename);
                         }