01: /*
02: * TreeRenderer.java - The Tree Rendering
03: * Copyright (C) 2003 Alexandre THOMAS
04: * alexthomas@free.fr
05: * http://helpgui.sourceforge.net
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package salomeTMF_plug.helpgui.gui;
23:
24: import java.awt.Component;
25: import javax.swing.JTree;
26: import javax.swing.tree.DefaultTreeCellRenderer;
27: import javax.swing.ImageIcon;
28:
29: import salomeTMF_plug.helpgui.page.Page;
30:
31: /**
32: * Tree rendering
33: *
34: * @author Alexandre THOMAS
35: */
36: public class TreeRenderer extends DefaultTreeCellRenderer {
37:
38: public Component getTreeCellRendererComponent(JTree tree,
39: Object value, boolean sel, boolean expanded, boolean leaf,
40: int row, boolean hasFocus) {
41: super .getTreeCellRendererComponent(tree, value, sel, expanded,
42: leaf, row, hasFocus);
43: Page page;
44: try {
45: page = (Page) value;
46: } catch (Exception e) {
47: return this ;
48: }
49:
50: String image = page.getImage();
51: if (image == null) {
52: if (leaf)
53: image = "/salomeTMF_plug/helpgui/icons/"
54: + MainPanel.iconsPath + "/sheet.gif";
55: else if (expanded)
56: image = "/salomeTMF_plug/helpgui/icons/"
57: + MainPanel.iconsPath + "/contents.gif";
58: else
59: image = "/salomeTMF_plug/helpgui/icons/"
60: + MainPanel.iconsPath + "/contents2.gif";
61: } else
62: image = MainPanel.helpPath + "/images/" + image + ".gif";
63: try {
64: setIcon(new ImageIcon(getClass().getResource(image)));
65: } catch (Exception e) {
66: }
67:
68: return this;
69: }
70:
71: }
|