01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.modules.preferences;
19:
20: import javax.swing.JTable;
21:
22: public class PreferencesTable extends JTable {
23:
24: public PreferencesTable(PreferencesTableModel ptm) {
25: super (ptm);
26: preferencesTableModel = ptm;
27: preferencesTable = this ;
28:
29: // setDefaultRenderer(Preferences.class, new PropertyRenderer());
30: // setDefaultEditor(Preferences.class, new PreferencesEditor(this));
31: }
32:
33: PreferencesTableModel preferencesTableModel;
34:
35: /*
36: * class PreferencesEditor extends DefaultCellEditor { private
37: * ComponentPreferences preferences; private PreferencesTable
38: * preferencesTable; private java.awt.ContelligentComponent cellEditor;
39: *
40: * public PreferencesEditor(PreferencesTable vt) { super(new JCheckBox()); //
41: * Bad Swing design preferencesTable = vt; }
42: *
43: * protected void fireEditingStopped() { super.fireEditingStopped(); }
44: *
45: * public Object getCellEditorValue() { return preferences; }
46: *
47: * public java.awt.ContelligentComponent getTableCellEditorComponent(JTable
48: * table, Object object, boolean isSelected, final int row, final int
49: * column) { // Preferences to edit preferences =
50: * (ComponentPreferences)object;
51: *
52: * TypePreferences typePreferences = preferences.getTypePreferences();
53: *
54: * if ( typeProperty.isEnumerable() ) { String[] items =
55: * typeProperty.getEnumeration(); cellEditor = new JComboBox(items); //
56: * preselect the current value
57: * ((JComboBox)cellEditor).setSelectedItem(property.getValue()); if (
58: * typeProperty.isFreeTextAllowed() ) {
59: * ((JComboBox)cellEditor).setEditable(true); } else {
60: * ((JComboBox)cellEditor).setEditable(false); }
61: * ((JComboBox)cellEditor).addActionListener(new ActionListener() { public
62: * void actionPerformed(ActionEvent e) { JComboBox cb =
63: * (JComboBox)e.getSource();
64: * property.setValue((String)cb.getSelectedItem()); fireEditingStopped(); }
65: * }); if ( property.isFinal() ||
66: * typeProperty.getMode().equals(TypeProperty.READ_ONLY) ||
67: * typeProperty.getMode().equals(TypeProperty.READ_ONLY_NOT_PERSISTENT) ) {
68: * ((JComboBox)cellEditor).setEditable(false); } } else { cellEditor = new
69: * JTextField(property.getValue()); if ( property.isFinal() ||
70: * typeProperty.getMode().equals(TypeProperty.READ_ONLY) ||
71: * typeProperty.getMode().equals(TypeProperty.READ_ONLY_NOT_PERSISTENT) ) {
72: * ((JTextField)cellEditor).setEditable(false); } else {
73: * ((JTextField)cellEditor).addActionListener(new ActionListener() { public
74: * void actionPerformed(ActionEvent e) {
75: * property.setValue(((JTextField)cellEditor).getText());
76: * fireEditingStopped(); } }); } } return cellEditor; } }
77: *
78: * class PreferencesRenderer implements TableCellRenderer { public
79: * java.awt.ContelligentComponent getTableCellRendererComponent(JTable
80: * table, Object object, boolean isSelected, boolean hasFocus, int row, int
81: * column) { JLabel cellRenderer = new JLabel();
82: * cellRenderer.setOpaque(true); ComponentPreferences preferences =
83: * (ComponentPreferences)object; if ( column == 0 ) {
84: * cellRenderer.setText(preferences.getName()); } else {
85: * cellRenderer.setText(preferences.getValue()); } if (
86: * preferences.getValue().equals(preferences.getInitialValue()) ) {
87: * cellRenderer.setForeground(Color.gray); } else {
88: * cellRenderer.setForeground(Color.black); } if ( isSelected ) {
89: * cellRenderer.setBackground(preferencesTable.getSelectionBackground());
90: * cellRenderer.setForeground(preferencesTable.getSelectionForeground()); }
91: * else { if ( preferences.isFinal() ) {
92: * cellRenderer.setBackground(Color.yellow); } else {
93: * cellRenderer.setBackground(preferencesTable.getBackground()); } }
94: * cellRenderer.setFont(preferencesTable.getFont());
95: *
96: * return cellRenderer; } }
97: */
98: JTable preferencesTable;
99: }
|