source: trunk/gli/src/org/greenstone/gatherer/gui/table/TableCellRenderer.java@ 8240

Last change on this file since 8240 was 8240, checked in by mdewsnip, 20 years ago

Removed unnecessary imports of org.greenstone.gatherer.Gatherer.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 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.table;
38
39import java.awt.*;
40import java.io.*;
41import javax.swing.*;
42import javax.swing.table.DefaultTableCellRenderer;
43import org.greenstone.gatherer.Configuration;
44import org.greenstone.gatherer.msm.ElementWrapper;
45import org.greenstone.gatherer.msm.Metadata;
46import org.greenstone.gatherer.util.Utility;
47
48public class TableCellRenderer
49 extends DefaultTableCellRenderer {
50
51 private GTableModel model = null;
52
53 public TableCellRenderer(GTableModel model) {
54 super();
55 this.model = model;
56 }
57
58 /** Returns the default table cell renderer.
59 * @param table The <strong>JTable</strong>.
60 * @param value The value to assign to the cell at [row, column] as an <strong>Object</strong>.
61 * @param isSelected <i>true</i> if cell is selected.
62 * @param row The row of the cell to render as an <i>int</i>.
63 * @param column The column of the cell to render as an <i>int</i>.
64 * @param hasFocus <i>true</i> if cell has focus, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editing.
65 * @return The default table cell renderer <strong>Component</strong>.
66 */
67 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
68 JLabel renderer = null;
69 if(value instanceof File) {
70 if(value != null) {
71 renderer = new JLabel(Utility.getImage("upfolder.gif"));
72 }
73 }
74 if(renderer == null) {
75 renderer = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
76 }
77 // Set up the component
78 renderer.setOpaque(true);
79 // Foreground
80 if(model.isCommon(row)) {
81 renderer.setForeground(Color.black);
82 }
83 else {
84 renderer.setForeground(Color.gray);
85 }
86 // Background
87 if(column <= 1) {
88 if(isSelected) {
89 renderer.setBackground(Configuration.getColor("coloring.workspace_heading_background", true));
90 }
91 else {
92 renderer.setBackground(Configuration.getColor("coloring.collection_heading_background", true));
93 }
94 }
95 else {
96 if(isSelected) {
97 renderer.setBackground(Configuration.getColor("coloring.workspace_heading_background", true));
98 }
99 else {
100 renderer.setBackground(Configuration.getColor("coloring.collection_tree_background", true));
101 }
102 }
103 // Finally the 3rd column of cells never paint focus.
104 if(column == 2) {
105 renderer.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
106 }
107
108 // We set a tooltip over the element column containing the description of the element
109 if(value instanceof ElementWrapper) {
110 renderer.setToolTipText(((ElementWrapper)value).getToolTip());
111 }
112
113 return renderer;
114 }
115}
Note: See TracBrowser for help on using the repository browser.