icon property of frame is used to set icon its tab icon 57/13957/2
Antoine ELIAS [Sat, 8 Mar 2014 09:52:28 +0000 (10:52 +0100)]
when current is disable, try to find first enable tab and selected it

Change-Id: Ifa29d5d15c8d07e020509889b15c0a5ca54d56fa

scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabFrame.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabTabGroup.java

index 2f60488..6a57da9 100644 (file)
@@ -14,8 +14,9 @@
 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_ICON__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
 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__;
@@ -817,6 +818,19 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
                 }
                 break;
             }
+            case __GO_UI_ICON__: {
+                // Update tab icon title
+                Container parent = getParent();
+                if (parent instanceof SwingScilabTabGroup) {
+                    SwingScilabTabGroup tab = (SwingScilabTabGroup) parent;
+                    int index = tab.indexOfComponent(this);
+                    if (index != -1) {
+                        tab.setIconAt(index, (String) value);
+                    }
+                }
+
+                break;
+            }
             case __GO_POSITION__: {
                 SwingViewWidget.updatePosition(this, uid, value);
                 revalidate();
index ec18603..c4237be 100644 (file)
@@ -33,8 +33,12 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Font;
+import java.io.File;
+import java.io.IOException;
 
+import javax.imageio.ImageIO;
 import javax.swing.Icon;
+import javax.swing.ImageIcon;
 import javax.swing.JLabel;
 import javax.swing.JTabbedPane;
 import javax.swing.UIManager;
@@ -42,6 +46,7 @@ import javax.swing.border.Border;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
+import org.scilab.modules.commons.gui.FindIconHelper;
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.graphic_objects.graphicObject.CallBack;
 import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
@@ -282,6 +287,17 @@ public class SwingScilabTabGroup extends JTabbedPane implements SwingViewObject,
         super.setEnabledAt(index, enabled);
         //update tab label to show enabled state
         getTabComponentAt(index).setEnabled(enabled);
+
+        //disable current selected tab, select another enable tab if possible
+        if (enabled == false && index == getSelectedIndex()) {
+            //looking first enable tab and select it.
+            for (int i = 0 ; i < getComponentCount() ; i++) {
+                if (getComponentAt(i).isEnabled()) {
+                    setSelectedIndex(i);
+                    break;
+                }
+            }
+        }
     }
 
     public void setEnabled(boolean status) {
@@ -389,4 +405,21 @@ public class SwingScilabTabGroup extends JTabbedPane implements SwingViewObject,
         getParent().remove(this);
         this.setVisible(false);
     }
+
+    public void setIconAt(int index, String iconFile) {
+        try {
+            File file = new File(iconFile);
+            if (file.exists() == false) {
+                String filename = FindIconHelper.findImage(iconFile);
+                file = new File(filename);
+            }
+
+            JLabel label = (JLabel)getTabComponentAt(index);
+            if (label != null) {
+                label.setIcon(new ImageIcon(ImageIO.read(file)));
+            }
+        } catch (IOException e) {
+            super.setIconAt(index, null);
+        }
+    }
 }