Author: psmith
Date: Thu Dec  1 21:58:49 2005
New Revision: 351606

URL: http://svn.apache.org/viewcvs?rev=351606&view=rev
Log:
Added an icon to the ZeroConf plugin's tab when it detects a discovered device.

Modified:
    
logging/chainsaw/trunk/zeroconf/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java

Modified: 
logging/chainsaw/trunk/zeroconf/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java
URL: 
http://svn.apache.org/viewcvs/logging/chainsaw/trunk/zeroconf/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java?rev=351606&r1=351605&r2=351606&view=diff
==============================================================================
--- 
logging/chainsaw/trunk/zeroconf/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java
 (original)
+++ 
logging/chainsaw/trunk/zeroconf/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java
 Thu Dec  1 21:58:49 2005
@@ -23,6 +23,7 @@
 import javax.swing.AbstractAction;
 import javax.swing.BorderFactory;
 import javax.swing.DefaultListModel;
+import javax.swing.Icon;
 import javax.swing.ImageIcon;
 import javax.swing.JCheckBox;
 import javax.swing.JFrame;
@@ -35,6 +36,7 @@
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollBar;
 import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
 import javax.swing.JToolBar;
 import javax.swing.ListCellRenderer;
 import javax.swing.ListModel;
@@ -86,6 +88,8 @@
 
     private static final Logger LOG = Logger.getLogger(ZeroConfPlugin.class);
 
+    private static final Icon DEVICE_DISCOVERED_ICON = new 
ImageIcon(ChainsawIcons.ANIM_RADIO_TOWER);
+
     private ModifiableListModel discoveredDevices = new ModifiableListModel();
 
     private final JList listBox = new JList(discoveredDevices);
@@ -193,6 +197,35 @@
             }
         }else {
             this.preferenceModel = new ZeroConfPreferenceModel();
+        }
+        
+        discoveredDevices.addListDataListener(new ListDataListener() {
+
+            public void intervalAdded(ListDataEvent e) {
+                setIconIfNeeded();
+            }
+
+            public void intervalRemoved(ListDataEvent e) {
+                setIconIfNeeded();
+            }
+
+            public void contentsChanged(ListDataEvent e) {
+                setIconIfNeeded();
+            }});
+    }
+    
+    /**
+     * Sets the icon of this parent container (a JTabbedPane, we hope
+     *
+     */
+    private void setIconIfNeeded() {
+        Container container = this.getParent();
+        if(container instanceof JTabbedPane) {
+            JTabbedPane tabbedPane = (JTabbedPane) container;
+            Icon icon = 
discoveredDevices.getSize()==0?null:DEVICE_DISCOVERED_ICON;
+            tabbedPane.setIconAt(tabbedPane.indexOfTab(getName()), icon);
+        }else {
+            LOG.warn("Parent is not a TabbedPane, not setting icon: " + 
container.getClass().getName());
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to