01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.ui.renderer;
24:
25: import java.awt.Component;
26:
27: import javax.swing.BorderFactory;
28: import javax.swing.Icon;
29: import javax.swing.JTree;
30: import javax.swing.tree.DefaultTreeCellRenderer;
31:
32: import org.isqlviewer.model.SchemaNode;
33: import org.isqlviewer.model.SchemaNodeType;
34: import org.isqlviewer.swing.CompoundIcon;
35: import org.isqlviewer.swing.SwingUtilities;
36:
37: /**
38: * Object responsible for rendering the nodes in the schema tree view.
39: * <p>
40: *
41: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
42: * @version 1.0
43: */
44: public class JDBCTreeCellRenderer extends DefaultTreeCellRenderer {
45:
46: private static final long serialVersionUID = -8888787908432640991L;
47:
48: public JDBCTreeCellRenderer() {
49:
50: super ();
51: setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
52: }
53:
54: @Override
55: public Component getTreeCellRendererComponent(JTree tree,
56: Object value, boolean sel, boolean expanded, boolean leaf,
57: int row, boolean foc) {
58:
59: super .getTreeCellRendererComponent(tree, value, sel, expanded,
60: leaf, row, foc);
61: SchemaNode node = (SchemaNode) value;
62: SchemaNodeType nodeType = node.getNodeType();
63: String iconName = nodeType.getPreferredIcon();
64: if (iconName != null && iconName.length() > 0) {
65: setIcon(SwingUtilities.loadIconResource(iconName, 16));
66: }
67: if (node.isHasError()) {
68: Icon errorIcon = SwingUtilities.loadIconResource("warning",
69: 16);
70: setIcon(new CompoundIcon(getIcon(), errorIcon));
71: }
72: setText(node.getUserObject());
73: return this;
74: }
75: }
|