01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.properties;
20:
21: import java.awt.Component;
22:
23: import javax.swing.JTable;
24: import javax.swing.UIManager;
25: import javax.swing.table.DefaultTableCellRenderer;
26: import javax.swing.table.DefaultTableColumnModel;
27: import javax.swing.table.TableColumn;
28:
29: import com.jeta.forms.gui.beans.JETAPropertyDescriptor;
30:
31: /**
32: *
33: */
34: public class PropertyColumnModel extends DefaultTableColumnModel {
35: private final static String COL_LABEL_PROP = "Property";
36: private final static String COL_LABEL_DESC = "Description";
37: private final static String COL_LABEL_VALUE = "Value";
38:
39: private static final int minColWidth = 150;
40:
41: /**
42: * PropertyColumnModel
43: */
44: public PropertyColumnModel() {
45: // Configure the columns and add them to the model
46: TableColumn column;
47:
48: // Property
49: column = new TableColumn(0);
50: column.setHeaderValue(COL_LABEL_PROP);
51: column.setPreferredWidth(minColWidth);
52: column.setCellRenderer(new PropertyNameRenderer());
53: addColumn(column);
54:
55: // Value
56: column = new TableColumn(1);
57: column.setHeaderValue(COL_LABEL_VALUE);
58: column.setPreferredWidth(minColWidth * 2);
59: addColumn(column);
60: }
61:
62: /**
63: * Renders the name of the property. Sets the short description of the
64: * property as the tooltip text.
65: */
66: class PropertyNameRenderer extends DefaultTableCellRenderer {
67: /**
68: * Get UI for current editor, including custom editor button if
69: * applicable.
70: */
71: public Component getTableCellRendererComponent(JTable table,
72: Object value, boolean isSelected, boolean hasFocus,
73: int row, int column) {
74:
75: PropertyTableModel model = (PropertyTableModel) table
76: .getModel();
77: JETAPropertyDescriptor desc = model
78: .getPropertyDescriptor(row);
79:
80: setToolTipText(desc.getShortDescription());
81: setBackground(UIManager.getColor("control"));
82:
83: return super.getTableCellRendererComponent(table, value,
84: isSelected, hasFocus, row, column);
85: }
86: }
87: }
|