1 /* ******************************************************************** **
2 ** Copyright notice **
3 ** **
4 ** (c) 2003 WiSim Development Team **
5 ** http://wisim.sourceforge.net/ **
6 ** **
7 ** All rights reserved **
8 ** **
9 ** This script is part of the WiSim Business Game project. The WiSim **
10 ** project is free software; you can redistribute it and/or modify **
11 ** it under the terms of the GNU General Public License as published by **
12 ** the Free Software Foundation; either version 2 of the License, or **
13 ** (at your option) any later version. **
14 ** **
15 ** The GNU General Public License can be found at **
16 ** http://www.gnu.org/copyleft/gpl.html. **
17 ** A copy is found in the textfile GPL.txt and important notices to the **
18 ** license from the team is found in the textfile LICENSE.txt distributed **
19 ** in these package. **
20 ** **
21 ** This copyright notice MUST APPEAR in all copies of the file! **
22 ** ******************************************************************** */
23
24 package net.sourceforge.wisim.controller;
25
26 import java.util;
27 import java.awt;
28 import javax.swing;
29 import javax.swing.tree;
30
31
32 /** Der CellRenderer f?r einen JTree mit IconNodes. Erlaubt es jedem Node im JTree ein eigenes Icon
33 * zuzuweisen.
34 * Diese Klasse wurde von:
35 * http://www.codeguru.com/java/articles/187.shtml
36 * heruntergeladen.
37 * @version 1.0 01/12/99
38 */
39 public class IconNodeRenderer extends DefaultTreeCellRenderer {
40
41 /**
42 * @param tree
43 * @param value
44 * @param sel
45 * @param expanded
46 * @param leaf
47 * @param row
48 * @param hasFocus
49 * @return Component
50 */
51 public Component getTreeCellRendererComponent(JTree tree, Object value,
52 boolean sel, boolean expanded, boolean leaf,
53 int row, boolean hasFocus) {
54
55 super.getTreeCellRendererComponent(tree, value,
56 sel, expanded, leaf, row, hasFocus);
57
58 Icon icon = ((IconNode)value).getIcon();
59
60 if (icon == null) {
61 Hashtable icons = (Hashtable)tree.getClientProperty("JTree.icons");
62 String name = ((IconNode)value).getIconName();
63 if ((icons != null) && (name != null)) {
64 icon = (Icon)icons.get(name);
65 if (icon != null) {
66 setIcon(icon);
67 }
68 }
69 } else {
70 setIcon(icon);
71 }
72
73 return this;
74 }
75 }