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

Last change on this file since 19513 was 8848, checked in by mdewsnip, 19 years ago

Moved some collection tree specific stuff out of here and into CollectionTree. Oh, and fixed a big bug I just added into DragTree :-)

  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 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.file.FileNode;
44import org.greenstone.gatherer.util.StaticStrings;
45import org.greenstone.gatherer.util.Utility;
46
47public class DragTreeCellRenderer
48 extends DefaultTreeCellRenderer
49{
50 private Color selection_background;
51 private Color selection_foreground;
52
53 public DragTreeCellRenderer() {
54 super();
55 // Have to wait until this image is loaded
56 selection_background = getBackgroundSelectionColor();
57 selection_foreground = getTextSelectionColor();
58 }
59
60 public void gainFocus() {
61 setBackgroundSelectionColor(selection_background);
62 setTextSelectionColor(selection_foreground);
63 }
64
65 /** Configures the renderer based on the passed in components. */
66 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
67 {
68 // Rendering FileNodes
69 if (value instanceof FileNode) {
70 FileNode node = (FileNode) value;
71 String node_text = node.toString();
72
73 // Add file sizes if necessary
74 if (Configuration.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC) && node.getFile() != null && !node.getAllowsChildren()) {
75 node_text = node_text + StaticStrings.SPACE_CHARACTER + StaticStrings.LBRACKET_CHARACTER + Utility.formatFileLength(node.getFile().length()) + StaticStrings.RBRACKET_CHARACTER;
76 }
77
78 return (JLabel) super.getTreeCellRendererComponent(tree, node_text, sel, expanded, leaf, row, hasFocus);
79 }
80
81 // Use default renderer for anything else
82 return (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
83 }
84
85 public void loseFocus() {
86 setBackgroundSelectionColor(Color.lightGray);
87 setTextSelectionColor(Color.black);
88 }
89}
Note: See TracBrowser for help on using the repository browser.