/* SwingML
* Copyright (C) 2002 SwingML Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors:
* Ezequiel Cuellar <ecuellar@crosslogic.com>
* Hamdi Mohs Yusof <hamdi@medical-online.net>
*/
package org.swingml.component;
import java.util.Iterator;
import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import org.swingml.model.JTableModel;
import org.swingml.model.TableColumnModel;
public class TableCellColorDecorator {
public TableCellColorDecorator(JTableComponent aTable) {
JTableModel theModel = (JTableModel) aTable.getModel();
Iterator theColumns = theModel.getColumns().iterator();
/*Sets the cell renderer for columns of type ColorComponent*/
aTable.setDefaultRenderer(ColorComponent.class, new TableCellColorRenderer());
TableColumnModel theColumn = null;
List theColumnItems = null;
ColorComponent[] theColors = null;
String theColorName = null;
ColorComponent theColor = null;
JComboBox theCombo = null;
while (theColumns.hasNext()) {
theColumn = (TableColumnModel) theColumns.next();
if (theColumn.getType() instanceof ColorComponent) {
/*Sets the cell editor for columns of type ColorComponent*/
theColumnItems = theColumn.getItems();
if (theColumnItems != null) {
theColors = new ColorComponent[theColumnItems.size()];
for (int i = 0; i < theColumnItems.size(); i++) {
theColorName = (String) theColumnItems.get(i);
theColor = ColorComponent.getColorByName(theColorName);
theColors[i] = theColor;
}
theCombo = new JComboBox(theColors);
theCombo.setRenderer(new ListCellColorRenderer());
aTable.setDefaultEditor(ColorComponent.class, new DefaultCellEditor(theCombo));
}
}
}
}
}