source: trunk/gli/src/org/greenstone/gatherer/gui/tree/DragTreeCellRenderer.java@ 5590

Last change on this file since 5590 was 5590, checked in by mdewsnip, 21 years ago

Could it be I've finished adding tooltips?? Why yes, very nearly... and a big "hallelulah" for that.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui.tree;
38
39import java.awt.*;
40import javax.swing.*;
41import javax.swing.tree.DefaultTreeCellRenderer;
42import org.greenstone.gatherer.Configuration;
43import org.greenstone.gatherer.Gatherer;
44import org.greenstone.gatherer.file.FileNode;
45import org.greenstone.gatherer.util.Utility;
46
47public class DragTreeCellRenderer
48 extends DefaultTreeCellRenderer {
49
50 private boolean in_focus = false;
51 private Color selection_background;
52 private Color selection_foreground;
53
54 static final private ImageIcon GRAY_FOLDER = Utility.getImage("greyfolder.gif");
55 static final private String PREFIX = " [";
56 static final private String SUFFIX = "]";
57
58 public DragTreeCellRenderer() {
59 super();
60 selection_background = getBackgroundSelectionColor();
61 selection_foreground = getTextSelectionColor();
62 }
63
64 public void gainFocus() {
65 setBackgroundSelectionColor(selection_background);
66 setTextSelectionColor(selection_foreground);
67 }
68
69 /** Configures the renderer based on the passed in components. */
70 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
71 Component tree_cell = null;
72 if(value instanceof FileNode) {
73 FileNode node = (FileNode) value;
74
75 String new_value = null;
76 if(Gatherer.config.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC) && node.getFile() != null && !node.getAllowsChildren()) {
77 new_value = node.toString() + PREFIX + Utility.formatFileLength(node.getFile().length()) + SUFFIX;
78 }
79 else {
80 new_value = node.toString();
81 }
82
83 tree_cell = (JLabel) super.getTreeCellRendererComponent(tree, new_value, sel, expanded, leaf, row, hasFocus);
84
85 if(node.getFile() == null || node.isFileSystemRoot()) {
86 ((JLabel)tree_cell).setIcon(GRAY_FOLDER);
87 }
88 }
89 else {
90 tree_cell = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
91 }
92 return tree_cell;
93 }
94
95 public void loseFocus() {
96 setBackgroundSelectionColor(Color.lightGray);
97 setTextSelectionColor(Color.black);
98 }
99}
Note: See TracBrowser for help on using the repository browser.