svn-gvsig-desktop / trunk / org.gvsig.desktop / 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 / DefaultColorTableClassesTableModel.java @ 44831
History | View | Annotate | Download (5.67 KB)
1 | 44831 | jjdelcerro | /* 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.Color; |
||
26 | import java.util.List; |
||
27 | |||
28 | import javax.swing.table.AbstractTableModel; |
||
29 | |||
30 | import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
||
31 | import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass; |
||
32 | import org.gvsig.raster.swing.legend.colortable.editor.ColorTableClassesTableModel; |
||
33 | import org.gvsig.raster.swing.legend.colortable.selector.ColorTablesTableModel; |
||
34 | import org.gvsig.tools.ToolsLocator; |
||
35 | import org.gvsig.tools.i18n.I18nManager; |
||
36 | |||
37 | |||
38 | /**
|
||
39 | * @author fdiaz
|
||
40 | *
|
||
41 | */
|
||
42 | public class DefaultColorTableClassesTableModel extends AbstractTableModel implements ColorTableClassesTableModel{ |
||
43 | |||
44 | /**
|
||
45 | *
|
||
46 | */
|
||
47 | private static final long serialVersionUID = -456045233313370454L; |
||
48 | |||
49 | private ColorTable colorTable;
|
||
50 | |||
51 | private static final int COLUMNS = 4; |
||
52 | |||
53 | public static final int COLUMN_COLOR = 0; |
||
54 | public static final int COLUMN_NAME = 1; |
||
55 | public static final int COLUMN_VALUE = 2; |
||
56 | public static final int COLUMN_INTERPOLATED = 3; |
||
57 | |||
58 | /**
|
||
59 | * @param bandsInfo
|
||
60 | */
|
||
61 | public DefaultColorTableClassesTableModel(ColorTable colorTable) {
|
||
62 | this.colorTable = colorTable;
|
||
63 | } |
||
64 | |||
65 | /* (non-Javadoc)
|
||
66 | * @see javax.swing.table.TableModel#getRowCount()
|
||
67 | */
|
||
68 | @Override
|
||
69 | public int getRowCount() { |
||
70 | if(colorTable==null){ |
||
71 | return 0; |
||
72 | } |
||
73 | return colorTable.getClasses().size();
|
||
74 | } |
||
75 | |||
76 | /* (non-Javadoc)
|
||
77 | * @see javax.swing.table.TableModel#getColumnCount()
|
||
78 | */
|
||
79 | @Override
|
||
80 | public int getColumnCount() { |
||
81 | return COLUMNS;
|
||
82 | } |
||
83 | |||
84 | /* (non-Javadoc)
|
||
85 | * @see javax.swing.table.TableModel#getValueAt(int, int)
|
||
86 | */
|
||
87 | @Override
|
||
88 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
89 | switch (columnIndex) {
|
||
90 | case COLUMN_COLOR:
|
||
91 | return colorTable.getClasses().get(rowIndex).getColor();
|
||
92 | case COLUMN_NAME:
|
||
93 | return colorTable.getClasses().get(rowIndex).getName();
|
||
94 | case COLUMN_VALUE:
|
||
95 | return colorTable.getClasses().get(rowIndex).getValue();
|
||
96 | case COLUMN_INTERPOLATED:
|
||
97 | return colorTable.getClasses().get(rowIndex).getInterpolated();
|
||
98 | } |
||
99 | return null; |
||
100 | } |
||
101 | |||
102 | @Override
|
||
103 | public String getColumnName(int column) { |
||
104 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
105 | switch (column) {
|
||
106 | case COLUMN_COLOR:
|
||
107 | return i18nManager.getTranslation("_color"); |
||
108 | case COLUMN_NAME:
|
||
109 | return i18nManager.getTranslation("_name"); |
||
110 | case COLUMN_VALUE:
|
||
111 | return i18nManager.getTranslation("_value"); |
||
112 | case COLUMN_INTERPOLATED:
|
||
113 | return i18nManager.getTranslation("_interpolation_percent"); |
||
114 | } |
||
115 | return null; |
||
116 | } |
||
117 | |||
118 | public boolean isCellEditable(int row, int col) { |
||
119 | return true; |
||
120 | } |
||
121 | |||
122 | @Override
|
||
123 | public Class<?> getColumnClass(int col) { |
||
124 | switch (col) {
|
||
125 | case COLUMN_COLOR:
|
||
126 | return Color.class; |
||
127 | case COLUMN_VALUE:
|
||
128 | return Double.class; |
||
129 | case COLUMN_INTERPOLATED:
|
||
130 | return Double.class; |
||
131 | default:
|
||
132 | return super.getColumnClass(col); |
||
133 | } |
||
134 | } |
||
135 | |||
136 | |||
137 | @Override
|
||
138 | public void addColorTableClass(ColorTableClass colorTableClass) { |
||
139 | this.colorTable.getClasses().add(colorTableClass);
|
||
140 | this.fireTableDataChanged();
|
||
141 | } |
||
142 | |||
143 | @Override
|
||
144 | public ColorTableClass getColorTableClass(int index) { |
||
145 | return this.colorTable.getClasses().get(index); |
||
146 | } |
||
147 | |||
148 | @Override
|
||
149 | public void removeColorTableClass(int index) { |
||
150 | this.colorTable.getClasses().remove(index);
|
||
151 | this.fireTableDataChanged();
|
||
152 | } |
||
153 | |||
154 | @Override
|
||
155 | public void removeAllColorTableClasses() { |
||
156 | this.colorTable.getClasses().clear();
|
||
157 | this.fireTableDataChanged();
|
||
158 | } |
||
159 | |||
160 | @Override
|
||
161 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
||
162 | |||
163 | switch (columnIndex) {
|
||
164 | case COLUMN_COLOR:
|
||
165 | this.colorTable.getClasses().get(rowIndex).setColor((Color)aValue); |
||
166 | break;
|
||
167 | case COLUMN_NAME:
|
||
168 | this.colorTable.getClasses().get(rowIndex).setName((String)aValue); |
||
169 | break;
|
||
170 | case COLUMN_VALUE:
|
||
171 | this.colorTable.getClasses().get(rowIndex).setValue(((Number)aValue).doubleValue()); |
||
172 | break;
|
||
173 | case COLUMN_INTERPOLATED:
|
||
174 | this.colorTable.getClasses().get(rowIndex).setInterpolated(((Number)aValue).doubleValue()); |
||
175 | break;
|
||
176 | default:
|
||
177 | throw new IllegalArgumentException("Illegal column index: "+columnIndex+"."); |
||
178 | } |
||
179 | this.fireTableDataChanged();
|
||
180 | } |
||
181 | |||
182 | @Override
|
||
183 | public void setColorTable(ColorTable colorTable) { |
||
184 | this.colorTable = colorTable;
|
||
185 | this.fireTableDataChanged();
|
||
186 | } |
||
187 | |||
188 | } |