01: /* SwingML
02: * Copyright (C) 2002 SwingML Team
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 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
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Ezequiel Cuellar <ecuellar@crosslogic.com>
21: * Hamdi Mohs Yusof <hamdi@medical-online.net>
22: */
23:
24: package org.swingml.component;
25:
26: import java.util.Iterator;
27: import java.util.List;
28:
29: import javax.swing.DefaultCellEditor;
30: import javax.swing.JComboBox;
31:
32: import org.swingml.model.JTableModel;
33: import org.swingml.model.TableColumnModel;
34:
35: public class TableCellColorDecorator {
36:
37: public TableCellColorDecorator(JTableComponent aTable) {
38: JTableModel theModel = (JTableModel) aTable.getModel();
39: Iterator theColumns = theModel.getColumns().iterator();
40:
41: /*Sets the cell renderer for columns of type ColorComponent*/
42: aTable.setDefaultRenderer(ColorComponent.class,
43: new TableCellColorRenderer());
44:
45: TableColumnModel theColumn = null;
46: List theColumnItems = null;
47: ColorComponent[] theColors = null;
48: String theColorName = null;
49: ColorComponent theColor = null;
50: JComboBox theCombo = null;
51:
52: while (theColumns.hasNext()) {
53: theColumn = (TableColumnModel) theColumns.next();
54: if (theColumn.getType() instanceof ColorComponent) {
55:
56: /*Sets the cell editor for columns of type ColorComponent*/
57: theColumnItems = theColumn.getItems();
58: if (theColumnItems != null) {
59: theColors = new ColorComponent[theColumnItems
60: .size()];
61: for (int i = 0; i < theColumnItems.size(); i++) {
62: theColorName = (String) theColumnItems.get(i);
63: theColor = ColorComponent
64: .getColorByName(theColorName);
65: theColors[i] = theColor;
66: }
67: theCombo = new JComboBox(theColors);
68: theCombo.setRenderer(new ListCellColorRenderer());
69: aTable.setDefaultEditor(ColorComponent.class,
70: new DefaultCellEditor(theCombo));
71: }
72: }
73: }
74: }
75:
76: }
|