01: package com.xoetrope.carousel.builder;
02:
03: import java.awt.Color;
04: import java.awt.Component;
05: import java.util.EventObject;
06: import javax.swing.DefaultCellEditor;
07: import javax.swing.JComboBox;
08: import javax.swing.JTable;
09: import javax.swing.table.TableCellRenderer;
10:
11: /**
12: * A table cell renderer that renders boolean content with a checkbox
13: *
14: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
15: * the GNU Public License (GPL), please see license.txt for more details. If
16: * you make commercial use of this software you must purchase a commercial
17: * license from Xoetrope.</p>
18: */
19: public class XFormComboTableCellRenderer extends DefaultCellEditor
20: implements TableCellRenderer {
21: /**
22: * Creates a new instance of XCheckBoxTableCellRenderer
23: */
24: public XFormComboTableCellRenderer(String[] items) {
25: super (new JComboBox(items));
26:
27: editorComponent.setOpaque(true);
28: editorComponent.setEnabled(true);
29: }
30:
31: /**
32: *
33: * Returns the default table cell renderer.
34: *
35: * @param table the <code>JTable</code>
36: * @param value the value to assign to the cell at
37: * <code>[row, column]</code>
38: * @param isSelected true if cell is selected
39: * @param hasFocus true if cell has focus
40: * @param row the row of the cell to render
41: * @param column the column of the cell to render
42: * @return the default table cell renderer
43: */
44: public Component getTableCellRendererComponent(JTable table,
45: Object value, boolean isSelected, boolean hasFocus,
46: int row, int column) {
47: if (isSelected) {
48: editorComponent.setForeground(Color.black);//table.getSelectionForeground() );
49: editorComponent.setBackground(table
50: .getSelectionBackground());
51: } else {
52: editorComponent.setForeground(table.getForeground());
53: editorComponent.setBackground(table.getBackground());
54: }
55:
56: if ((value == null) || (value.toString().length() == 0))
57: ((JComboBox) editorComponent).setSelectedIndex(0);
58: else if (!((JComboBox) editorComponent).getSelectedItem()
59: .toString().equals(value.toString()))
60: ((JComboBox) editorComponent).setSelectedItem(value
61: .toString());
62:
63: return editorComponent;
64: }
65:
66: /**
67: * Sets the <code>String</code> object for the cell being rendered to
68: * <code>value</code>.
69: *
70: * @param value the string value for this cell; if value is
71: * <code>null</code> it sets the text value to an empty string
72: * @see JLabel#setText
73: *
74: */
75: public void setValue(Object value) {
76: if ((value == null) || (value.toString().length() == 0))
77: ((JComboBox) editorComponent).setSelectedIndex(0);
78: else
79: ((JComboBox) editorComponent).setSelectedItem(value
80: .toString());
81: }
82:
83: public boolean isCellEditable(EventObject anEvent) {
84: return true;
85: }
86: }
|