001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.modules.types;
019:
020: import java.awt.Color;
021:
022: import javax.swing.DefaultCellEditor;
023: import javax.swing.JCheckBox;
024: import javax.swing.JComponent;
025: import javax.swing.JLabel;
026: import javax.swing.JTable;
027: import javax.swing.table.TableCellRenderer;
028:
029: import de.finix.contelligent.client.base.TypeProperty;
030: import de.finix.contelligent.client.util.SortableTable;
031: import de.finix.contelligent.client.util.TableModelSorter;
032:
033: public class TypeTable extends SortableTable implements
034: java.awt.event.MouseListener {
035:
036: private JTable typeTable;
037:
038: private TypeTableModel typeTableModel;
039:
040: public TypeTable(TypeTableModel ptm) {
041: super (new TableModelSorter(ptm));
042: typeTableModel = ptm;
043: typeTable = this ;
044:
045: setDefaultRenderer(TypeProperty.class, new TypeRenderer());
046: setDefaultEditor(TypeProperty.class, new TypeEditor(this ));
047: }
048:
049: class TypeEditor extends DefaultCellEditor {
050: private TypeProperty typeProperty;
051:
052: public TypeEditor(TypeTable vt) {
053: super (new JCheckBox()); // Bad Swing design
054: typeTable = vt;
055: }
056:
057: protected void fireEditingStopped() {
058: super .fireEditingStopped();
059: }
060:
061: public Object getCellEditorValue() {
062: return typeProperty;
063: }
064:
065: public java.awt.Component getTableCellEditorComponent(
066: JTable table, Object object, boolean isSelected,
067: final int row, final int column) {
068: // Type to edit
069: typeProperty = (TypeProperty) object;
070: JLabel cellEditor = new JLabel("Hallo");
071: return cellEditor;
072: }
073: }
074:
075: class TypeRenderer implements TableCellRenderer {
076: public java.awt.Component getTableCellRendererComponent(
077: JTable table, Object object, boolean isSelected,
078: boolean hasFocus, int row, int column) {
079: // Type to edit
080: TypeProperty typeProperty = (TypeProperty) object;
081:
082: JComponent cellRenderer = null;
083: switch (column) {
084: case 0: {
085: cellRenderer = new JLabel(typeProperty.getName());
086: break;
087: }
088: case 1: {
089: cellRenderer = new JLabel(typeProperty.getValue());
090: break;
091: }
092: case 2: {
093: cellRenderer = new JLabel(typeProperty
094: .getPropertyType());
095: break;
096: }
097: case 3: {
098: cellRenderer = new JCheckBox();
099: ((JCheckBox) cellRenderer).setSelected(typeProperty
100: .isRequired());
101: break;
102: }
103: case 4: {
104: cellRenderer = new JCheckBox();
105: ((JCheckBox) cellRenderer).setSelected(typeProperty
106: .isFinal());
107: break;
108: }
109: case 5: {
110: cellRenderer = new JLabel(typeProperty.getMode());
111: break;
112: }
113: case 6: {
114: cellRenderer = new JLabel(typeProperty.getGroup());
115: break;
116: }
117: case 7: {
118: cellRenderer = new JLabel(typeProperty.getConstraints());
119: break;
120: }
121: }
122: cellRenderer.setFont(TypeTable.this .getFont());
123: cellRenderer.setOpaque(true);
124:
125: if (isSelected) {
126: cellRenderer.setBackground(typeTable
127: .getSelectionBackground());
128: cellRenderer.setForeground(typeTable
129: .getSelectionForeground());
130: } else {
131: cellRenderer.setBackground(typeTable.getBackground());
132: if (typeTableModel.getType().isPropertyInherited(
133: typeProperty.getName())) {
134: cellRenderer.setForeground(Color.gray);
135: } else {
136: cellRenderer.setForeground(Color.black);
137: }
138: }
139: return cellRenderer;
140: }
141: }
142: }
|