svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster.legend / org.gvsig.raster.legend.swing / org.gvsig.raster.legend.swing.impl / src / main / java / org / gvsig / raster / swing / legend / impl / colortable / editor / NumberCellEditor.java @ 43803
History | View | Annotate | Download (2.37 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2017 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.raster.swing.legend.impl.colortable.editor; |
24 |
|
25 |
import java.awt.Component; |
26 |
import java.text.NumberFormat; |
27 |
|
28 |
import javax.swing.AbstractCellEditor; |
29 |
import javax.swing.JFormattedTextField; |
30 |
import javax.swing.JTable; |
31 |
import javax.swing.table.TableCellEditor; |
32 |
import javax.swing.text.DefaultFormatterFactory; |
33 |
import javax.swing.text.NumberFormatter; |
34 |
|
35 |
|
36 |
/**
|
37 |
* @author fdiaz
|
38 |
*
|
39 |
*/
|
40 |
class NumberCellEditor extends AbstractCellEditor implements TableCellEditor { |
41 |
|
42 |
|
43 |
/**
|
44 |
*
|
45 |
*/
|
46 |
private static final long serialVersionUID = 6651535828174933397L; |
47 |
|
48 |
private JFormattedTextField delegated = new JFormattedTextField(); |
49 |
|
50 |
|
51 |
public NumberCellEditor() {
|
52 |
NumberFormat numberInstance = NumberFormat.getNumberInstance(); |
53 |
numberInstance.setGroupingUsed(false);
|
54 |
numberInstance.setMaximumFractionDigits(Integer.MAX_VALUE);
|
55 |
NumberFormatter numberFormatter = new NumberFormatter(numberInstance); |
56 |
DefaultFormatterFactory tf = new DefaultFormatterFactory( |
57 |
numberFormatter, |
58 |
numberFormatter, |
59 |
numberFormatter, |
60 |
numberFormatter); |
61 |
delegated.setFormatterFactory(tf); |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public Object getCellEditorValue() { |
66 |
return delegated.getValue();
|
67 |
} |
68 |
|
69 |
@Override
|
70 |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
71 |
delegated.setValue(value); |
72 |
return delegated;
|
73 |
} |
74 |
} |