|
@@ -35,6 +35,7 @@ import java.awt.event.MouseMotionListener;
|
35
|
35
|
import java.awt.event.MouseWheelEvent;
|
36
|
36
|
import java.awt.event.MouseWheelListener;
|
37
|
37
|
import java.util.Hashtable;
|
|
38
|
+
|
38
|
39
|
import javax.swing.JComponent;
|
39
|
40
|
import javax.swing.JMenuItem;
|
40
|
41
|
import javax.swing.JPopupMenu;
|
|
@@ -54,6 +55,7 @@ import javax.swing.tree.DefaultTreeModel;
|
54
|
55
|
import javax.swing.tree.ExpandVetoException;
|
55
|
56
|
import javax.swing.tree.TreePath;
|
56
|
57
|
import javax.swing.tree.TreeSelectionModel;
|
|
58
|
+
|
57
|
59
|
import uk.org.ownage.dmdirc.Channel;
|
58
|
60
|
import uk.org.ownage.dmdirc.Config;
|
59
|
61
|
import uk.org.ownage.dmdirc.FrameContainer;
|
|
@@ -65,86 +67,86 @@ import uk.org.ownage.dmdirc.logger.Logger;
|
65
|
67
|
import uk.org.ownage.dmdirc.ui.framemanager.FrameManager;
|
66
|
68
|
|
67
|
69
|
/**
|
68
|
|
- * Manages open windows in the application in a tree style view
|
|
70
|
+ * Manages open windows in the application in a tree style view.
|
69
|
71
|
*/
|
70
|
|
-public class TreeFrameManager implements FrameManager, TreeModelListener,
|
|
72
|
+public final class TreeFrameManager implements FrameManager, TreeModelListener,
|
71
|
73
|
TreeSelectionListener, TreeExpansionListener, TreeWillExpandListener,
|
72
|
74
|
MouseListener, ActionListener, MouseMotionListener, MouseWheelListener,
|
73
|
75
|
KeyListener {
|
74
|
76
|
|
75
|
77
|
/**
|
76
|
|
- * display tree
|
|
78
|
+ * display tree.
|
77
|
79
|
*/
|
78
|
80
|
private JTree tree;
|
79
|
81
|
|
80
|
82
|
/**
|
81
|
|
- * Scrollpane for the tree
|
|
83
|
+ * Scrollpane for the tree.
|
82
|
84
|
*/
|
83
|
85
|
private JScrollPane scrollPane;
|
84
|
86
|
|
85
|
87
|
/**
|
86
|
|
- * root node
|
|
88
|
+ * root node.
|
87
|
89
|
*/
|
88
|
90
|
private DefaultMutableTreeNode root;
|
89
|
91
|
|
90
|
92
|
/**
|
91
|
|
- * node renderer
|
|
93
|
+ * node renderer.
|
92
|
94
|
*/
|
93
|
95
|
private TreeViewTreeCellRenderer renderer;
|
94
|
96
|
|
95
|
97
|
/**
|
96
|
|
- * data model
|
|
98
|
+ * data model.
|
97
|
99
|
*/
|
98
|
100
|
private TreeViewModel model;
|
99
|
101
|
|
100
|
102
|
/**
|
101
|
|
- * node storage, used for adding and deleting nodes correctly
|
|
103
|
+ * node storage, used for adding and deleting nodes correctly.
|
102
|
104
|
*/
|
103
|
105
|
private Hashtable<FrameContainer, DefaultMutableTreeNode> nodes;
|
104
|
106
|
|
105
|
107
|
/**
|
106
|
|
- * stores colour associated with a node, cheap hack till i rewrite the model
|
|
108
|
+ * stores colour associated with a node, cheap hack till i rewrite the model.
|
107
|
109
|
*/
|
108
|
110
|
private Hashtable<FrameContainer, Color> nodeColours;
|
109
|
111
|
|
110
|
112
|
/**
|
111
|
113
|
* stores background colour associated with a node,
|
112
|
|
- * cheap hack till i rewrite the model
|
|
114
|
+ * cheap hack till i rewrite the model.
|
113
|
115
|
*/
|
114
|
116
|
private DefaultMutableTreeNode rolloverNode;
|
115
|
117
|
|
116
|
118
|
/**
|
117
|
|
- * popup menu for menu items on nodes
|
|
119
|
+ * popup menu for menu items on nodes.
|
118
|
120
|
*/
|
119
|
121
|
private JPopupMenu popup;
|
120
|
122
|
|
121
|
123
|
/**
|
122
|
|
- * close menu item used in popup menus
|
|
124
|
+ * close menu item used in popup menus.
|
123
|
125
|
*/
|
124
|
126
|
private JMenuItem closeMenuItem;
|
125
|
127
|
|
126
|
128
|
/**
|
127
|
|
- * The object that is currently selected
|
|
129
|
+ * The object that is currently selected.
|
128
|
130
|
*/
|
129
|
131
|
private FrameContainer selected;
|
130
|
132
|
|
131
|
133
|
/**
|
132
|
|
- *Parent component for the frame manager
|
|
134
|
+ *Parent component for the frame manager.
|
133
|
135
|
*/
|
134
|
136
|
private JComponent parent;
|
135
|
137
|
|
136
|
138
|
/**
|
137
|
|
- * whether the mouse button is currently pressed
|
|
139
|
+ * whether the mouse button is currently pressed.
|
138
|
140
|
*/
|
139
|
141
|
private boolean mouseClicked = true;
|
140
|
142
|
|
141
|
143
|
/**
|
142
|
|
- *node under right click operation
|
|
144
|
+ *node under right click operation.
|
143
|
145
|
*/
|
144
|
146
|
private DefaultMutableTreeNode popupNode;
|
145
|
147
|
|
146
|
148
|
/**
|
147
|
|
- * creates a new instance of the TreeFrameManager
|
|
149
|
+ * creates a new instance of the TreeFrameManager.
|
148
|
150
|
*/
|
149
|
151
|
public TreeFrameManager() {
|
150
|
152
|
nodes = new Hashtable<FrameContainer, DefaultMutableTreeNode>();
|
|
@@ -172,8 +174,8 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
172
|
174
|
}
|
173
|
175
|
/**
|
174
|
176
|
* Indicates whether this frame manager can be positioned vertically
|
175
|
|
- * (i.e., at the side of the screen)
|
176
|
|
- * @return True iff the frame manager can be positioned vertically
|
|
177
|
+ * (i.e., at the side of the screen).
|
|
178
|
+ * @return True iff the frame manager can be positioned vertically.
|
177
|
179
|
*/
|
178
|
180
|
public boolean canPositionVertically() {
|
179
|
181
|
return true;
|
|
@@ -181,18 +183,18 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
181
|
183
|
|
182
|
184
|
/**
|
183
|
185
|
* Indicates whether this frame manager can be positioned horizontally
|
184
|
|
- * (i.e., at the top or bottom of the screen)
|
185
|
|
- * @return True iff the frame manager can be positioned horizontally
|
|
186
|
+ * (i.e., at the top or bottom of the screen).
|
|
187
|
+ * @return True iff the frame manager can be positioned horizontally.
|
186
|
188
|
*/
|
187
|
189
|
public boolean canPositionHorizontally() {
|
188
|
190
|
return false;
|
189
|
191
|
}
|
190
|
192
|
|
191
|
193
|
/**
|
192
|
|
- * Indicates that there is a new active frame
|
193
|
|
- * @param source The object that now has focus
|
|
194
|
+ * Indicates that there is a new active frame.
|
|
195
|
+ * @param source The object that now has focus.
|
194
|
196
|
*/
|
195
|
|
- public void setSelected(FrameContainer source) {
|
|
197
|
+ public void setSelected(final FrameContainer source) {
|
196
|
198
|
selected = source;
|
197
|
199
|
SwingUtilities.invokeLater(new Runnable() {
|
198
|
200
|
public void run() {
|
|
@@ -202,16 +204,16 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
202
|
204
|
}
|
203
|
205
|
|
204
|
206
|
/**
|
205
|
|
- * Retrieves the currently selected object
|
206
|
|
- * @return The object that is currently selected
|
|
207
|
+ * Retrieves the currently selected object.
|
|
208
|
+ * @return The object that is currently selected.
|
207
|
209
|
*/
|
208
|
210
|
public FrameContainer getSelected() {
|
209
|
211
|
return selected;
|
210
|
212
|
}
|
211
|
213
|
|
212
|
214
|
/**
|
213
|
|
- * Retrieves the currently selected node
|
214
|
|
- * @return The node that is currently selected
|
|
215
|
+ * Retrieves the currently selected node.
|
|
216
|
+ * @return The node that is currently selected.
|
215
|
217
|
*/
|
216
|
218
|
public DefaultMutableTreeNode getSelectedNode() {
|
217
|
219
|
return nodes.get(selected);
|
|
@@ -219,11 +221,11 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
219
|
221
|
|
220
|
222
|
/**
|
221
|
223
|
* Shows an event notification to the user by colouring the corresponding
|
222
|
|
- * element to the source a specific colour
|
223
|
|
- * @param source The object requesting notification
|
224
|
|
- * @param colour The colour that should be used to indicate the notification
|
|
224
|
+ * element to the source a specific colour.
|
|
225
|
+ * @param source The object requesting notification.
|
|
226
|
+ * @param colour The colour that should be used to indicate the notification.
|
225
|
227
|
*/
|
226
|
|
- public void showNotification(FrameContainer source, Color colour) {
|
|
228
|
+ public void showNotification(final FrameContainer source, final Color colour) {
|
227
|
229
|
if (nodeColours != null) {
|
228
|
230
|
nodeColours.put(source, colour);
|
229
|
231
|
SwingUtilities.invokeLater(new Runnable() {
|
|
@@ -235,10 +237,10 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
235
|
237
|
}
|
236
|
238
|
|
237
|
239
|
/**
|
238
|
|
- * Sets the rollover node and repaints the tree
|
239
|
|
- * @param node rollover node
|
|
240
|
+ * Sets the rollover node and repaints the tree.
|
|
241
|
+ * @param node rollover node.
|
240
|
242
|
*/
|
241
|
|
- public void showRollover(DefaultMutableTreeNode node) {
|
|
243
|
+ public void showRollover(final DefaultMutableTreeNode node) {
|
242
|
244
|
rolloverNode = node;
|
243
|
245
|
SwingUtilities.invokeLater(new Runnable() {
|
244
|
246
|
public void run() {
|
|
@@ -248,29 +250,29 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
248
|
250
|
}
|
249
|
251
|
|
250
|
252
|
/**
|
251
|
|
- * retrives the rollover node
|
252
|
|
- * @return rollover node
|
|
253
|
+ * retrives the rollover node.
|
|
254
|
+ * @return rollover node.
|
253
|
255
|
*/
|
254
|
256
|
public DefaultMutableTreeNode getRollover() {
|
255
|
257
|
return rolloverNode;
|
256
|
258
|
}
|
257
|
259
|
|
258
|
260
|
/**
|
259
|
|
- * Clears a notification from a frame and its node
|
260
|
|
- * @param source Frame to remove notification from
|
|
261
|
+ * Clears a notification from a frame and its node.
|
|
262
|
+ * @param source Frame to remove notification from.
|
261
|
263
|
*/
|
262
|
|
- public void clearNotification(FrameContainer source) {
|
|
264
|
+ public void clearNotification(final FrameContainer source) {
|
263
|
265
|
if (nodeColours != null && nodeColours.containsKey(source)) {
|
264
|
266
|
nodeColours.remove(source);
|
265
|
267
|
}
|
266
|
268
|
}
|
267
|
269
|
|
268
|
270
|
/**
|
269
|
|
- * retrieves the colour of a specific node
|
270
|
|
- * @param source node to check colour of
|
271
|
|
- * @return colour of the node
|
|
271
|
+ * retrieves the colour of a specific node.
|
|
272
|
+ * @param source node to check colour of.
|
|
273
|
+ * @return colour of the node.
|
272
|
274
|
*/
|
273
|
|
- public Color getNodeColour(FrameContainer source) {
|
|
275
|
+ public Color getNodeColour(final FrameContainer source) {
|
274
|
276
|
if (nodeColours != null && nodeColours.containsKey(source)) {
|
275
|
277
|
return nodeColours.get(source);
|
276
|
278
|
}
|
|
@@ -278,16 +280,16 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
278
|
280
|
}
|
279
|
281
|
|
280
|
282
|
/**
|
281
|
|
- * Sets the parent component in the main UI
|
282
|
|
- * @param parent parent component
|
|
283
|
+ * Sets the parent component in the main UI.
|
|
284
|
+ * @param newParent parent component.
|
283
|
285
|
*/
|
284
|
|
- public void setParent(JComponent parent) {
|
285
|
|
- this.parent = parent;
|
|
286
|
+ public void setParent(final JComponent newParent) {
|
|
287
|
+ this.parent = newParent;
|
286
|
288
|
scrollPane = new JScrollPane(tree);
|
287
|
289
|
scrollPane.setAutoscrolls(false);
|
288
|
290
|
parent.setLayout(new BorderLayout());
|
289
|
291
|
parent.add(scrollPane);
|
290
|
|
- scrollPane.setPreferredSize(new Dimension(parent.getWidth(), 0));;
|
|
292
|
+ scrollPane.setPreferredSize(new Dimension(parent.getWidth(), 0));
|
291
|
293
|
tree.setForeground(parent.getForeground());
|
292
|
294
|
tree.setBorder(new EmptyBorder(5, 5, 5, 5));
|
293
|
295
|
tree.setVisible(true);
|
|
@@ -295,11 +297,11 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
295
|
297
|
}
|
296
|
298
|
|
297
|
299
|
/**
|
298
|
|
- * adds a server to the tree
|
299
|
|
- * @param server associated server
|
|
300
|
+ * adds a server to the tree.
|
|
301
|
+ * @param server associated server.
|
300
|
302
|
*/
|
301
|
|
- public void addServer(Server server) {
|
302
|
|
- DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
|
303
|
+ public void addServer(final Server server) {
|
|
304
|
+ final DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
303
|
305
|
nodes.put(server, node);
|
304
|
306
|
node.setUserObject(server);
|
305
|
307
|
model.insertNodeInto(node, root);
|
|
@@ -310,20 +312,20 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
310
|
312
|
}
|
311
|
313
|
|
312
|
314
|
/**
|
313
|
|
- * removes a server from the tree
|
314
|
|
- * @param server associated server
|
|
315
|
+ * removes a server from the tree.
|
|
316
|
+ * @param server associated server.
|
315
|
317
|
*/
|
316
|
|
- public void delServer(Server server) {
|
|
318
|
+ public void delServer(final Server server) {
|
317
|
319
|
model.removeNodeFromParent(nodes.get(server));
|
318
|
320
|
}
|
319
|
321
|
|
320
|
322
|
/**
|
321
|
|
- * adds a channel to the tree
|
322
|
|
- * @param server associated server
|
323
|
|
- * @param channel associated framecontainer
|
|
323
|
+ * adds a channel to the tree.
|
|
324
|
+ * @param server associated server.
|
|
325
|
+ * @param channel associated framecontainer.
|
324
|
326
|
*/
|
325
|
|
- public void addChannel(Server server, Channel channel) {
|
326
|
|
- DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
|
327
|
+ public void addChannel(final Server server, final Channel channel) {
|
|
328
|
+ final DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
327
|
329
|
nodes.put(channel, node);
|
328
|
330
|
node.setUserObject(channel);
|
329
|
331
|
model.insertNodeInto(node, nodes.get(server));
|
|
@@ -331,21 +333,21 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
331
|
333
|
}
|
332
|
334
|
|
333
|
335
|
/**
|
334
|
|
- * deletes a channel from the tree
|
335
|
|
- * @param server associated server
|
336
|
|
- * @param channel associated framecontainer
|
|
336
|
+ * deletes a channel from the tree.
|
|
337
|
+ * @param server associated server.
|
|
338
|
+ * @param channel associated framecontainer.
|
337
|
339
|
*/
|
338
|
|
- public void delChannel(Server server, Channel channel) {
|
|
340
|
+ public void delChannel(final Server server, final Channel channel) {
|
339
|
341
|
model.removeNodeFromParent(nodes.get(channel));
|
340
|
342
|
}
|
341
|
343
|
|
342
|
344
|
/**
|
343
|
|
- * adds a query to the tree
|
344
|
|
- * @param server associated server
|
345
|
|
- * @param query associated framecontainer
|
|
345
|
+ * adds a query to the tree.
|
|
346
|
+ * @param server associated server.
|
|
347
|
+ * @param query associated framecontainer.
|
346
|
348
|
*/
|
347
|
|
- public void addQuery(Server server, Query query) {
|
348
|
|
- DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
|
349
|
+ public void addQuery(final Server server, final Query query) {
|
|
350
|
+ final DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
349
|
351
|
nodes.put(query, node);
|
350
|
352
|
node.setUserObject(query);
|
351
|
353
|
model.insertNodeInto(node, nodes.get(server));
|
|
@@ -353,134 +355,134 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
353
|
355
|
}
|
354
|
356
|
|
355
|
357
|
/**
|
356
|
|
- * deletes a query from the tree
|
357
|
|
- * @param server associated server
|
358
|
|
- * @param query associated framecontainer
|
|
358
|
+ * deletes a query from the tree.
|
|
359
|
+ * @param server associated server.
|
|
360
|
+ * @param query associated framecontainer.
|
359
|
361
|
*/
|
360
|
|
- public void delQuery(Server server, Query query) {
|
|
362
|
+ public void delQuery(final Server server, final Query query) {
|
361
|
363
|
model.removeNodeFromParent(nodes.get(query));
|
362
|
364
|
}
|
363
|
365
|
|
364
|
366
|
/**
|
365
|
|
- * adds a raw to the tree
|
366
|
|
- * @param server associated server
|
367
|
|
- * @param raw associated framecontainer
|
|
367
|
+ * adds a raw to the tree.
|
|
368
|
+ * @param server associated server.
|
|
369
|
+ * @param raw associated framecontainer.
|
368
|
370
|
*/
|
369
|
|
- public void addRaw(Server server, Raw raw) {
|
370
|
|
- DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
|
371
|
+ public void addRaw(final Server server, final Raw raw) {
|
|
372
|
+ final DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
371
|
373
|
nodes.put(raw, node);
|
372
|
374
|
node.setUserObject(raw);
|
373
|
375
|
model.insertNodeInto(node, nodes.get(server));
|
374
|
376
|
}
|
375
|
377
|
|
376
|
378
|
/**
|
377
|
|
- * deletes a raw from the tree
|
378
|
|
- * @param server associated server
|
379
|
|
- * @param raw associated framecontainer
|
|
379
|
+ * deletes a raw from the tree.
|
|
380
|
+ * @param server associated server.
|
|
381
|
+ * @param raw associated framecontainer.
|
380
|
382
|
*/
|
381
|
|
- public void delRaw(Server server, Raw raw) {
|
|
383
|
+ public void delRaw(final Server server, final Raw raw) {
|
382
|
384
|
model.removeNodeFromParent(nodes.get(raw));
|
383
|
385
|
}
|
384
|
386
|
|
385
|
387
|
/**
|
386
|
|
- * valled whenever the value of the selection changes
|
387
|
|
- * @param e selection event
|
|
388
|
+ * valled whenever the value of the selection changes.
|
|
389
|
+ * @param e selection event.
|
388
|
390
|
*/
|
389
|
|
- public void valueChanged(TreeSelectionEvent e) {
|
390
|
|
- DefaultMutableTreeNode node =
|
|
391
|
+ public void valueChanged(final TreeSelectionEvent e) {
|
|
392
|
+ final DefaultMutableTreeNode node =
|
391
|
393
|
(DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
|
392
|
394
|
|
393
|
|
- if (node == null) return;
|
|
395
|
+ if (node == null) { return; }
|
394
|
396
|
|
395
|
|
- Object nodeInfo = node.getUserObject();
|
|
397
|
+ final Object nodeInfo = node.getUserObject();
|
396
|
398
|
if (nodeInfo instanceof FrameContainer) {
|
397
|
|
- ((FrameContainer)nodeInfo).activateFrame();
|
|
399
|
+ ((FrameContainer) nodeInfo).activateFrame();
|
398
|
400
|
} else {
|
399
|
401
|
Logger.error(ErrorLevel.WARNING, "Unknown node type.");
|
400
|
402
|
}
|
401
|
403
|
}
|
402
|
404
|
|
403
|
405
|
/**
|
404
|
|
- * Called after the tree has been expanded
|
405
|
|
- * @param event expansion event
|
|
406
|
+ * Called after the tree has been expanded.
|
|
407
|
+ * @param event expansion event.
|
406
|
408
|
*/
|
407
|
|
- public void treeExpanded(TreeExpansionEvent event) {
|
|
409
|
+ public void treeExpanded(final TreeExpansionEvent event) {
|
408
|
410
|
}
|
409
|
411
|
|
410
|
412
|
/**
|
411
|
|
- * Called after the tree has been collapsed
|
412
|
|
- * @param event expansion event
|
|
413
|
+ * Called after the tree has been collapsed.
|
|
414
|
+ * @param event expansion event.
|
413
|
415
|
*/
|
414
|
|
- public void treeCollapsed(TreeExpansionEvent event) {
|
|
416
|
+ public void treeCollapsed(final TreeExpansionEvent event) {
|
415
|
417
|
}
|
416
|
418
|
|
417
|
419
|
/**
|
418
|
|
- * Called when the tree is about to expand
|
419
|
|
- * @param event expansion event
|
420
|
|
- * @throws javax.swing.tree.ExpandVetoException thrown to prevent
|
|
420
|
+ * Called when the tree is about to expand.
|
|
421
|
+ * @param event expansion event.
|
|
422
|
+ * @throws javax.swing.tree.ExpandVetoException thrown to prevent.
|
421
|
423
|
* node expanding
|
422
|
424
|
*/
|
423
|
|
- public void treeWillExpand(TreeExpansionEvent event) throws
|
|
425
|
+ public void treeWillExpand(final TreeExpansionEvent event) throws
|
424
|
426
|
ExpandVetoException {
|
425
|
427
|
}
|
426
|
428
|
|
427
|
429
|
/**
|
428
|
|
- * Called when the tree is about to collapse
|
429
|
|
- * @param event expansion event
|
430
|
|
- * @throws javax.swing.tree.ExpandVetoException throw to prevent
|
|
430
|
+ * Called when the tree is about to collapse.
|
|
431
|
+ * @param event expansion event.
|
|
432
|
+ * @throws javax.swing.tree.ExpandVetoException throw to prevent.
|
431
|
433
|
* node collapsing
|
432
|
434
|
*/
|
433
|
|
- public void treeWillCollapse(TreeExpansionEvent event) throws
|
|
435
|
+ public void treeWillCollapse(final TreeExpansionEvent event) throws
|
434
|
436
|
ExpandVetoException {
|
435
|
437
|
}
|
436
|
438
|
|
437
|
439
|
/**
|
438
|
|
- * called after a node, or set of nodes, changes
|
439
|
|
- * @param e change event
|
|
440
|
+ * called after a node, or set of nodes, changes.
|
|
441
|
+ * @param e change event.
|
440
|
442
|
*/
|
441
|
|
- public void treeNodesChanged(TreeModelEvent e) {
|
|
443
|
+ public void treeNodesChanged(final TreeModelEvent e) {
|
442
|
444
|
}
|
443
|
445
|
|
444
|
446
|
/**
|
445
|
|
- * called after a node has been inserted into the tree
|
446
|
|
- * @param e change event
|
|
447
|
+ * called after a node has been inserted into the tree.
|
|
448
|
+ * @param e change event.
|
447
|
449
|
*/
|
448
|
|
- public void treeNodesInserted(TreeModelEvent e) {
|
|
450
|
+ public void treeNodesInserted(final TreeModelEvent e) {
|
449
|
451
|
}
|
450
|
452
|
|
451
|
453
|
/**
|
452
|
|
- * Called when a node is removed from the tree
|
453
|
|
- * @param e change event
|
|
454
|
+ * Called when a node is removed from the tree.
|
|
455
|
+ * @param e change event.
|
454
|
456
|
*/
|
455
|
|
- public void treeNodesRemoved(TreeModelEvent e) {
|
|
457
|
+ public void treeNodesRemoved(final TreeModelEvent e) {
|
456
|
458
|
}
|
457
|
459
|
|
458
|
460
|
/**
|
459
|
|
- * Called when a tree changes structure
|
460
|
|
- * @param e change event
|
|
461
|
+ * Called when a tree changes structure.
|
|
462
|
+ * @param e change event.
|
461
|
463
|
*/
|
462
|
|
- public void treeStructureChanged(TreeModelEvent e) {
|
|
464
|
+ public void treeStructureChanged(final TreeModelEvent e) {
|
463
|
465
|
}
|
464
|
466
|
|
465
|
467
|
/**
|
466
|
468
|
* Invoked when the mouse button has been clicked (pressed and released)
|
467
|
469
|
* on a component.
|
468
|
|
- * @param e mouse event
|
|
470
|
+ * @param e mouse event.
|
469
|
471
|
*/
|
470
|
|
- public void mouseClicked(MouseEvent e) {
|
|
472
|
+ public void mouseClicked(final MouseEvent e) {
|
471
|
473
|
}
|
472
|
474
|
|
473
|
475
|
/**
|
474
|
476
|
* Invoked when a mouse button has been pressed on a component.
|
475
|
|
- * @param e mouse event
|
|
477
|
+ * @param e mouse event.
|
476
|
478
|
*/
|
477
|
|
- public void mousePressed(MouseEvent e) {
|
|
479
|
+ public void mousePressed(final MouseEvent e) {
|
478
|
480
|
mouseClicked = true;
|
479
|
481
|
if (e.isPopupTrigger()) {
|
480
|
|
- JTree source = (JTree)e.getSource();
|
481
|
|
- TreePath path = tree.getPathForLocation(e.getX(), e.getY());
|
|
482
|
+ final JTree source = (JTree) e.getSource();
|
|
483
|
+ final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
|
482
|
484
|
if (path != null) {
|
483
|
|
- popupNode = (DefaultMutableTreeNode)path.getLastPathComponent();
|
|
485
|
+ popupNode = (DefaultMutableTreeNode) path.getLastPathComponent();
|
484
|
486
|
popup.show(source, e.getX(), e.getY());
|
485
|
487
|
}
|
486
|
488
|
}
|
|
@@ -488,75 +490,74 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
488
|
490
|
|
489
|
491
|
/**
|
490
|
492
|
* Invoked when a mouse button has been released on a component.
|
491
|
|
- * @param e mouse event
|
|
493
|
+ * @param e mouse event.
|
492
|
494
|
*/
|
493
|
|
- public void mouseReleased(MouseEvent e) {
|
|
495
|
+ public void mouseReleased(final MouseEvent e) {
|
494
|
496
|
mouseClicked = false;
|
495
|
497
|
}
|
496
|
498
|
|
497
|
499
|
/**
|
498
|
500
|
* Invoked when the mouse enters a component.
|
499
|
|
- * @param e mouse event
|
|
501
|
+ * @param e mouse event.
|
500
|
502
|
*/
|
501
|
|
- public void mouseEntered(MouseEvent e) {
|
|
503
|
+ public void mouseEntered(final MouseEvent e) {
|
502
|
504
|
}
|
503
|
505
|
|
504
|
506
|
/**
|
505
|
507
|
* Invoked when the mouse exits a component.
|
506
|
|
- * @param e mouse event
|
|
508
|
+ * @param e mouse event.
|
507
|
509
|
*/
|
508
|
|
- public void mouseExited(MouseEvent e) {
|
|
510
|
+ public void mouseExited(final MouseEvent e) {
|
509
|
511
|
}
|
510
|
512
|
|
511
|
513
|
/**
|
512
|
514
|
* Invoked when an action occurs.
|
513
|
|
- * @param e action event
|
|
515
|
+ * @param e action event.
|
514
|
516
|
*/
|
515
|
|
- public void actionPerformed(ActionEvent e) {
|
|
517
|
+ public void actionPerformed(final ActionEvent e) {
|
516
|
518
|
if (e.getSource() == closeMenuItem && popupNode != null) {
|
517
|
|
- ((FrameContainer)popupNode.getUserObject()).close();
|
|
519
|
+ ((FrameContainer) popupNode.getUserObject()).close();
|
518
|
520
|
popupNode = null;
|
519
|
521
|
}
|
520
|
522
|
}
|
521
|
523
|
|
522
|
524
|
/**
|
523
|
525
|
* Invoked when a mouse button is pressed on a component and then dragged.
|
524
|
|
- * @param e mouse event
|
|
526
|
+ * @param e mouse event.
|
525
|
527
|
*/
|
526
|
|
- public void mouseDragged(MouseEvent e) {
|
|
528
|
+ public void mouseDragged(final MouseEvent e) {
|
527
|
529
|
TreePath selectedPath, currentSelectedPath, oldSelectedPath = null;
|
528
|
530
|
DefaultMutableTreeNode node = null;
|
529
|
|
- DefaultTreeModel treeModel = (DefaultTreeModel)tree.getModel();
|
530
|
|
- int selRow = tree.getRowForLocation(e.getX(), e.getY());
|
531
|
|
- if (selRow < 0) {
|
|
531
|
+ final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
|
|
532
|
+ if (tree.getRowForLocation(e.getX(), e.getY()) < 0) {
|
532
|
533
|
currentSelectedPath = oldSelectedPath;
|
533
|
534
|
oldSelectedPath = null;
|
534
|
535
|
if (currentSelectedPath != null) {
|
535
|
|
- node = (DefaultMutableTreeNode)currentSelectedPath.getLastPathComponent();
|
536
|
|
- if (Config.hasOption("ui", "rolloverEnabled") &&
|
537
|
|
- Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
|
536
|
+ node = (DefaultMutableTreeNode) currentSelectedPath.getLastPathComponent();
|
|
537
|
+ if (Config.hasOption("ui", "rolloverEnabled")
|
|
538
|
+ && Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
538
|
539
|
this.showRollover(node);
|
539
|
540
|
}
|
540
|
|
- ((FrameContainer)node.getUserObject()).activateFrame();
|
|
541
|
+ ((FrameContainer) node.getUserObject()).activateFrame();
|
541
|
542
|
} else {
|
542
|
|
- if (Config.hasOption("ui", "rolloverEnabled") &&
|
543
|
|
- Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
|
543
|
+ if (Config.hasOption("ui", "rolloverEnabled")
|
|
544
|
+ && Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
544
|
545
|
this.showRollover(node);
|
545
|
546
|
}
|
546
|
547
|
}
|
547
|
548
|
} else {
|
548
|
549
|
selectedPath = tree.getPathForLocation(e.getX(), e.getY());
|
549
|
|
- if ((oldSelectedPath== null) || !selectedPath.equals(oldSelectedPath)) {
|
|
550
|
+ if ((oldSelectedPath == null) || !selectedPath.equals(oldSelectedPath)) {
|
550
|
551
|
oldSelectedPath = selectedPath;
|
551
|
|
- node = (DefaultMutableTreeNode)oldSelectedPath.getLastPathComponent();
|
552
|
|
- if (Config.hasOption("ui", "rolloverEnabled") &&
|
553
|
|
- Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
|
552
|
+ node = (DefaultMutableTreeNode) oldSelectedPath.getLastPathComponent();
|
|
553
|
+ if (Config.hasOption("ui", "rolloverEnabled")
|
|
554
|
+ && Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
554
|
555
|
this.showRollover(node);
|
555
|
556
|
}
|
556
|
|
- ((FrameContainer)node.getUserObject()).activateFrame();
|
|
557
|
+ ((FrameContainer) node.getUserObject()).activateFrame();
|
557
|
558
|
} else {
|
558
|
|
- if (Config.hasOption("ui", "rolloverEnabled") &&
|
559
|
|
- Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
|
559
|
+ if (Config.hasOption("ui", "rolloverEnabled")
|
|
560
|
+ && Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
560
|
561
|
this.showRollover(node);
|
561
|
562
|
}
|
562
|
563
|
}
|
|
@@ -566,29 +567,28 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
566
|
567
|
/**
|
567
|
568
|
* Invoked when the mouse cursor has been moved onto a component but no
|
568
|
569
|
* buttons have been pushed.
|
569
|
|
- * @param e mouse event
|
|
570
|
+ * @param e mouse event.
|
570
|
571
|
*/
|
571
|
|
- public void mouseMoved(MouseEvent e) {
|
572
|
|
- if (Config.hasOption("ui", "rolloverEnabled") &&
|
573
|
|
- Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
|
572
|
+ public void mouseMoved(final MouseEvent e) {
|
|
573
|
+ if (Config.hasOption("ui", "rolloverEnabled")
|
|
574
|
+ && Config.getOption("ui", "rolloverEnabled").equals("true")) {
|
574
|
575
|
TreePath selectedPath, currentSelectedPath, oldSelectedPath = null;
|
575
|
576
|
DefaultMutableTreeNode node;
|
576
|
|
- DefaultTreeModel treeModel = (DefaultTreeModel)tree.getModel();
|
577
|
|
- int selRow = tree.getRowForLocation(e.getX(), e.getY());
|
578
|
|
- if (selRow < 0) {
|
|
577
|
+ final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
|
|
578
|
+ if (tree.getRowForLocation(e.getX(), e.getY()) < 0) {
|
579
|
579
|
currentSelectedPath = oldSelectedPath;
|
580
|
580
|
oldSelectedPath = null;
|
581
|
581
|
if (currentSelectedPath != null) {
|
582
|
|
- node = (DefaultMutableTreeNode)currentSelectedPath.getLastPathComponent();
|
|
582
|
+ node = (DefaultMutableTreeNode) currentSelectedPath.getLastPathComponent();
|
583
|
583
|
this.showRollover(node);
|
584
|
584
|
} else {
|
585
|
585
|
this.showRollover(null);
|
586
|
586
|
}
|
587
|
587
|
} else {
|
588
|
588
|
selectedPath = tree.getPathForLocation(e.getX(), e.getY());
|
589
|
|
- if ((oldSelectedPath== null) || !selectedPath.equals(oldSelectedPath)) {
|
|
589
|
+ if ((oldSelectedPath == null) || !selectedPath.equals(oldSelectedPath)) {
|
590
|
590
|
oldSelectedPath = selectedPath;
|
591
|
|
- node = (DefaultMutableTreeNode)oldSelectedPath.getLastPathComponent();
|
|
591
|
+ node = (DefaultMutableTreeNode) oldSelectedPath.getLastPathComponent();
|
592
|
592
|
this.showRollover(node);
|
593
|
593
|
} else {
|
594
|
594
|
this.showRollover(null);
|
|
@@ -599,12 +599,11 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
599
|
599
|
|
600
|
600
|
/**
|
601
|
601
|
* Invoked when the mouse wheel is rotated.
|
602
|
|
- * @param e mouse event
|
|
602
|
+ * @param e mouse event.
|
603
|
603
|
*/
|
604
|
|
- public void mouseWheelMoved(MouseWheelEvent e) {
|
|
604
|
+ public void mouseWheelMoved(final MouseWheelEvent e) {
|
605
|
605
|
//get the number of notches (used only for direction)
|
606
|
|
- int notches = e.getWheelRotation();
|
607
|
|
- if (notches < 0) {
|
|
606
|
+ if (e.getWheelRotation() < 0) {
|
608
|
607
|
changeFocus(true);
|
609
|
608
|
} else {
|
610
|
609
|
changeFocus(false);
|
|
@@ -612,20 +611,19 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
612
|
611
|
}
|
613
|
612
|
|
614
|
613
|
/**
|
615
|
|
- * Activates the node above or below the active node in the tree
|
|
614
|
+ * Activates the node above or below the active node in the tree.
|
616
|
615
|
*
|
617
|
|
- *@param direction true = up, false = down
|
|
616
|
+ *@param direction true = up, false = down.
|
618
|
617
|
*/
|
619
|
|
- private void changeFocus(boolean direction) {
|
|
618
|
+ private void changeFocus(final boolean direction) {
|
620
|
619
|
DefaultMutableTreeNode thisNode, nextNode;
|
621
|
|
- TreePath path;
|
622
|
620
|
|
623
|
621
|
if (getSelectedNode() == null) {
|
624
|
622
|
//no selected node, get the root node
|
625
|
623
|
thisNode = root;
|
626
|
624
|
//are there any servers to select?
|
627
|
625
|
if (thisNode.getChildCount() > 0) {
|
628
|
|
- thisNode = (DefaultMutableTreeNode)thisNode.getChildAt(0);
|
|
626
|
+ thisNode = (DefaultMutableTreeNode) thisNode.getChildAt(0);
|
629
|
627
|
} else {
|
630
|
628
|
//then wait till there are
|
631
|
629
|
return;
|
|
@@ -635,13 +633,13 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
635
|
633
|
thisNode = getSelectedNode();
|
636
|
634
|
}
|
637
|
635
|
//are we going up or down?
|
638
|
|
- if (direction){
|
|
636
|
+ if (direction) {
|
639
|
637
|
//up
|
640
|
638
|
if (thisNode.getUserObject() instanceof Server) {
|
641
|
639
|
if (thisNode.getParent().getIndex(thisNode) == 0) {
|
642
|
640
|
//first server - last child of parent's last child
|
643
|
641
|
nextNode = (DefaultMutableTreeNode)
|
644
|
|
- ((DefaultMutableTreeNode)((DefaultMutableTreeNode)
|
|
642
|
+ ((DefaultMutableTreeNode) ((DefaultMutableTreeNode)
|
645
|
643
|
thisNode.getParent()).getLastChild()).getLastChild();
|
646
|
644
|
} else {
|
647
|
645
|
//other servers - last child of previous sibling
|
|
@@ -651,7 +649,7 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
651
|
649
|
} else {
|
652
|
650
|
if (thisNode.getParent().getIndex(thisNode) == 0) {
|
653
|
651
|
//first frame - parent
|
654
|
|
- nextNode = (DefaultMutableTreeNode)thisNode.getParent();
|
|
652
|
+ nextNode = (DefaultMutableTreeNode) thisNode.getParent();
|
655
|
653
|
} else {
|
656
|
654
|
//other frame - previous sibling
|
657
|
655
|
nextNode = thisNode.getPreviousSibling();
|
|
@@ -661,15 +659,15 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
661
|
659
|
//down
|
662
|
660
|
if (thisNode.getUserObject() instanceof Server) {
|
663
|
661
|
//all servers - get the first child
|
664
|
|
- nextNode = (DefaultMutableTreeNode)thisNode.getFirstChild();
|
|
662
|
+ nextNode = (DefaultMutableTreeNode) thisNode.getFirstChild();
|
665
|
663
|
} else {
|
666
|
|
- if (thisNode.getParent().getIndex(thisNode) ==
|
667
|
|
- thisNode.getParent().getChildCount()-1) {
|
|
664
|
+ if (thisNode.getParent().getIndex(thisNode)
|
|
665
|
+ == thisNode.getParent().getChildCount() - 1) {
|
668
|
666
|
//last frame - get the parents next sibling
|
669
|
|
- nextNode = ((DefaultMutableTreeNode)thisNode.getParent()).getNextSibling();
|
|
667
|
+ nextNode = ((DefaultMutableTreeNode) thisNode.getParent()).getNextSibling();
|
670
|
668
|
//parent doesnt have a next sibling, get the first child of the grandparent
|
671
|
669
|
if (nextNode == null) {
|
672
|
|
- nextNode = (DefaultMutableTreeNode)((DefaultMutableTreeNode)
|
|
670
|
+ nextNode = (DefaultMutableTreeNode) ((DefaultMutableTreeNode)
|
673
|
671
|
thisNode.getParent().getParent()).getFirstChild();
|
674
|
672
|
}
|
675
|
673
|
} else {
|
|
@@ -679,21 +677,21 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
679
|
677
|
}
|
680
|
678
|
}
|
681
|
679
|
//activate the nodes frame
|
682
|
|
- ((FrameContainer)nextNode.getUserObject()).activateFrame();
|
|
680
|
+ ((FrameContainer) nextNode.getUserObject()).activateFrame();
|
683
|
681
|
}
|
684
|
682
|
|
685
|
683
|
/**
|
686
|
684
|
* Invoked when a key has been typed.
|
687
|
|
- * @param e key event
|
|
685
|
+ * @param e key event.
|
688
|
686
|
*/
|
689
|
|
- public void keyTyped(KeyEvent e) {
|
|
687
|
+ public void keyTyped(final KeyEvent e) {
|
690
|
688
|
}
|
691
|
689
|
|
692
|
690
|
/**
|
693
|
691
|
* Invoked when a key has been pressed.
|
694
|
|
- * @param e key event
|
|
692
|
+ * @param e key event.
|
695
|
693
|
*/
|
696
|
|
- public void keyPressed(KeyEvent e) {
|
|
694
|
+ public void keyPressed(final KeyEvent e) {
|
697
|
695
|
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
698
|
696
|
changeFocus(false);
|
699
|
697
|
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
|
|
@@ -703,8 +701,8 @@ public class TreeFrameManager implements FrameManager, TreeModelListener,
|
703
|
701
|
|
704
|
702
|
/**
|
705
|
703
|
* Invoked when a key has been released.
|
706
|
|
- * @param e key event
|
|
704
|
+ * @param e key event.
|
707
|
705
|
*/
|
708
|
|
- public void keyReleased(KeyEvent e) {
|
|
706
|
+ public void keyReleased(final KeyEvent e) {
|
709
|
707
|
}
|
710
|
708
|
}
|