svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / swing / celleditors / IntegerTableCellEditor.java @ 40561
History | View | Annotate | Download (2.83 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.swing.celleditors; |
25 |
|
26 |
import java.awt.Component; |
27 |
import java.util.ArrayList; |
28 |
import java.util.EventObject; |
29 |
|
30 |
import javax.swing.JTable; |
31 |
import javax.swing.event.CellEditorListener; |
32 |
import javax.swing.event.ChangeEvent; |
33 |
import javax.swing.table.TableCellEditor; |
34 |
|
35 |
import org.gvsig.gui.beans.swing.cellrenderers.NumberTableCellRenderer; |
36 |
|
37 |
/**
|
38 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
39 |
*/
|
40 |
public class IntegerTableCellEditor implements TableCellEditor { |
41 |
private static NumberTableCellRenderer renderer = new NumberTableCellRenderer(true, false); |
42 |
private ArrayList listeners = new ArrayList(); |
43 |
|
44 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
45 |
if (value == null) return null; |
46 |
return renderer.getTableCellRendererComponent(table, value, isSelected, false, row, column); |
47 |
} |
48 |
|
49 |
|
50 |
public void cancelCellEditing() { |
51 |
for (int i = 0; i < listeners.size(); i++) { |
52 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
53 |
ChangeEvent evt = new ChangeEvent(this); |
54 |
l.editingCanceled(evt); |
55 |
} |
56 |
} |
57 |
|
58 |
public boolean stopCellEditing() { |
59 |
for (int i = 0; i < listeners.size(); i++) { |
60 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
61 |
ChangeEvent evt = new ChangeEvent(this); |
62 |
l.editingStopped(evt); |
63 |
} |
64 |
return true; |
65 |
} |
66 |
|
67 |
|
68 |
public Object getCellEditorValue() { |
69 |
if (renderer!=null && renderer.getIncrementalNumberField()!=null) |
70 |
return new Integer(renderer.getIncrementalNumberField().getInteger()); |
71 |
return null; |
72 |
} |
73 |
|
74 |
public boolean isCellEditable(EventObject anEvent) { |
75 |
return true; |
76 |
} |
77 |
|
78 |
public boolean shouldSelectCell(EventObject anEvent) { |
79 |
return false; |
80 |
} |
81 |
|
82 |
public void addCellEditorListener(CellEditorListener l) { |
83 |
listeners.add(l); |
84 |
} |
85 |
|
86 |
public void removeCellEditorListener(CellEditorListener l) { |
87 |
listeners.remove(l); |
88 |
} |
89 |
} |