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.Color;
26: import java.awt.Component;
27:
28: import javax.swing.JTree;
29: import javax.swing.tree.DefaultTreeCellRenderer;
30:
31: import org.isqlviewer.bookmarks.BookmarkFolder;
32: import org.isqlviewer.bookmarks.BookmarkReference;
33: import org.isqlviewer.bookmarks.ColorLabel;
34: import org.isqlviewer.swing.SwingUtilities;
35:
36: /**
37: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
38: * @version 1.0
39: */
40: public class BookmarkTreeCellRenderer extends DefaultTreeCellRenderer {
41:
42: private static final long serialVersionUID = 7723595988535143452L;
43:
44: public BookmarkTreeCellRenderer() {
45:
46: setLeafIcon(SwingUtilities.loadIconResource("bookmark", 16));
47: setOpenIcon(SwingUtilities.loadIconResource("folder", 16));
48: setClosedIcon(SwingUtilities.loadIconResource("folder", 16));
49: }
50:
51: @Override
52: public Component getTreeCellRendererComponent(JTree tree,
53: Object value, boolean sel, boolean expanded, boolean leaf,
54: int row, boolean foc) {
55:
56: super .getTreeCellRendererComponent(tree, value, sel, expanded,
57: leaf, row, foc);
58: Color color = tree.getBackground();
59: if (value instanceof BookmarkFolder) {
60: BookmarkFolder folder = (BookmarkFolder) value;
61: setText(folder.getName());
62: } else if (value instanceof BookmarkReference) {
63: BookmarkReference bookmark = (BookmarkReference) value;
64: ColorLabel labelColor = bookmark.getColorLabel();
65: if (labelColor != null) {
66: color = labelColor.toColor();
67: }
68: if (bookmark.isFavorite()) {
69: setIcon(SwingUtilities.loadIconResource("apply", 16));
70: } else {
71: setIcon(getLeafIcon());
72: }
73: setText(bookmark.getName());
74: }
75: setBackgroundNonSelectionColor(color);
76: setBackground(color);
77: return this;
78: }
79:
80: }
|