1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.pircbot;
21
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24
25 import javax.swing.SwingUtilities;
26
27 import org.xnap.event.StateEvent;
28 import org.xnap.event.StateListener;
29 import org.xnap.gui.table.DefaultTreeTableNode;
30 import org.xnap.gui.table.LeafTreeTableNode;
31 import org.xnap.gui.table.TreeTableNode;
32
33 /***
34 *
35 */
36 public class PircBotNetworkNode extends DefaultTreeTableNode
37 implements PropertyChangeListener, StateListener
38 {
39
40
41
42
43
44
45
46 /***
47 * Constructs a <code>TransferTreeTableNode</code>.
48 *
49 * @param model the table model
50 * @param name the name of the network
51 */
52 public PircBotNetworkNode(PircBotServerTableModel model, String name)
53 {
54 super(model, name);
55 }
56
57
58
59 public void add(PircBotServer server)
60 {
61 add(new LeafTreeTableNode(server));
62
63 server.addPropertyChangeListener(this);
64 server.addStateListener(this);
65 }
66
67 public void remove(PircBotServer server)
68 {
69 server.removePropertyChangeListener(this);
70 server.removeStateListener(this);
71
72 int index = getIndexOfChildByData(server);
73 removeChildAt(index);
74 }
75
76 public void removeAll()
77 {
78 while (getChildCount() > 0) {
79 remove((PircBotServer)((TreeTableNode)getChildAt(0)).getData());
80 }
81 }
82
83 public void propertyChange(final PropertyChangeEvent event)
84 {
85 Runnable runner = new Runnable()
86 {
87 public void run()
88 {
89 String p = event.getPropertyName();
90
91 int index = getIndexOfChildByData(event.getSource());
92 if (index != -1) {
93 if (p.equals("network")) {
94 PircBotServer s = (PircBotServer)event.getSource();
95 remove(s);
96 ((PircBotServerTableModel)getModel()).move(s);
97 }
98 else {
99 changedChildAt(index);
100 }
101 }
102 }
103 };
104 SwingUtilities.invokeLater(runner);
105 }
106
107 public void stateChanged(final StateEvent event)
108 {
109 Runnable runner = new Runnable()
110 {
111 public void run()
112 {
113 int index = getIndexOfChildByData(event.getSource());
114 if (index != -1) {
115 changedChildAt(index);
116 }
117 }
118 };
119 SwingUtilities.invokeLater(runner);
120 }
121
122 }