root / branches / v2_0_0_prep / libraries / libUIComponent / src / org / gvsig / gui / beans / swing / celleditors / StringTableCellEditor.java @ 22758
History | View | Annotate | Download (3.48 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.gui.beans.swing.celleditors; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.event.ActionEvent; |
45 |
import java.awt.event.ActionListener; |
46 |
import java.util.ArrayList; |
47 |
import java.util.EventObject; |
48 |
|
49 |
import javax.swing.JComponent; |
50 |
import javax.swing.JTable; |
51 |
import javax.swing.JTextField; |
52 |
import javax.swing.event.CellEditorListener; |
53 |
import javax.swing.event.ChangeEvent; |
54 |
import javax.swing.table.TableCellEditor; |
55 |
|
56 |
import org.gvsig.gui.beans.swing.cellrenderers.StringTableCellRenderer; |
57 |
|
58 |
public class StringTableCellEditor implements TableCellEditor { |
59 |
private StringTableCellRenderer renderer;
|
60 |
private ArrayList listeners = new ArrayList(); |
61 |
|
62 |
|
63 |
public StringTableCellEditor(final JTable ownerTable) { |
64 |
renderer = new StringTableCellRenderer();
|
65 |
} |
66 |
|
67 |
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row, int column) { |
68 |
if (value == null) return null; |
69 |
JComponent aux = (JComponent) renderer.getTableCellRendererComponent(table, value, isSelected, false, row, column); |
70 |
((JTextField) aux).addActionListener(new ActionListener() { |
71 |
public void actionPerformed(ActionEvent e) { |
72 |
// Store the value to avoid the need of pressing ENTER
|
73 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4139078
|
74 |
table.editingStopped(new ChangeEvent(table)); |
75 |
} |
76 |
}); |
77 |
return aux;
|
78 |
} |
79 |
|
80 |
|
81 |
public void cancelCellEditing() { |
82 |
for (int i = 0; i < listeners.size(); i++) { |
83 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
84 |
ChangeEvent evt = new ChangeEvent(this); |
85 |
l.editingCanceled(evt); |
86 |
} |
87 |
} |
88 |
|
89 |
public boolean stopCellEditing() { |
90 |
for (int i = 0; i < listeners.size(); i++) { |
91 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
92 |
ChangeEvent evt = new ChangeEvent(this); |
93 |
l.editingStopped(evt); |
94 |
} |
95 |
return true; |
96 |
} |
97 |
|
98 |
|
99 |
public Object getCellEditorValue() { |
100 |
if (renderer!=null && renderer.getText()!=null) |
101 |
return new Boolean(renderer.getText()); |
102 |
return null; |
103 |
} |
104 |
|
105 |
public boolean isCellEditable(EventObject anEvent) { |
106 |
return true; |
107 |
} |
108 |
|
109 |
public boolean shouldSelectCell(EventObject anEvent) { |
110 |
return true; |
111 |
} |
112 |
|
113 |
public void addCellEditorListener(CellEditorListener l) { |
114 |
listeners.add(l); |
115 |
} |
116 |
|
117 |
public void removeCellEditorListener(CellEditorListener l) { |
118 |
listeners.remove(l); |
119 |
} |
120 |
|
121 |
} |