gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.legend / org.gvsig.raster.swing.legend.impl / src / main / java / org / gvsig / raster / swing / legend / impl / colortable / selector / DefaultColorTablesTableModel.java @ 6899
History | View | Annotate | Download (4.56 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.selector; |
24 |
|
25 |
import java.io.File; |
26 |
import java.util.List; |
27 |
|
28 |
import javax.swing.table.AbstractTableModel; |
29 |
|
30 |
import org.apache.commons.lang3.tuple.Pair; |
31 |
|
32 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
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 DefaultColorTablesTableModel extends AbstractTableModel implements ColorTablesTableModel{ |
43 |
|
44 |
/**
|
45 |
*
|
46 |
*
|
47 |
*/
|
48 |
private static final long serialVersionUID = -6739781555636046945L; |
49 |
private List<Pair<File,ColorTable>> colorTables; |
50 |
|
51 |
private static final int COLUMNS = 4; |
52 |
|
53 |
public static final int COLUMN_PREVIEW = 0; |
54 |
public static final int COLUMN_NAME = 1; |
55 |
public static final int COLUMN_CLASSES = 2; |
56 |
public static final int COLUMN_INTERPOLATED = 3; |
57 |
|
58 |
/**
|
59 |
* @param bandsInfo
|
60 |
*/
|
61 |
public DefaultColorTablesTableModel(List<Pair<File,ColorTable>> colorTables) { |
62 |
this.colorTables = colorTables;
|
63 |
} |
64 |
|
65 |
/* (non-Javadoc)
|
66 |
* @see javax.swing.table.TableModel#getRowCount()
|
67 |
*/
|
68 |
@Override
|
69 |
public int getRowCount() { |
70 |
return colorTables.size();
|
71 |
} |
72 |
|
73 |
/* (non-Javadoc)
|
74 |
* @see javax.swing.table.TableModel#getColumnCount()
|
75 |
*/
|
76 |
@Override
|
77 |
public int getColumnCount() { |
78 |
return COLUMNS;
|
79 |
} |
80 |
|
81 |
/* (non-Javadoc)
|
82 |
* @see javax.swing.table.TableModel#getValueAt(int, int)
|
83 |
*/
|
84 |
@Override
|
85 |
public Object getValueAt(int rowIndex, int columnIndex) { |
86 |
switch (columnIndex) {
|
87 |
case COLUMN_PREVIEW:
|
88 |
return colorTables.get(rowIndex).getValue();
|
89 |
case COLUMN_NAME:
|
90 |
return colorTables.get(rowIndex).getValue().getName();
|
91 |
case COLUMN_CLASSES:
|
92 |
return colorTables.get(rowIndex).getValue().getClasses().size();
|
93 |
case COLUMN_INTERPOLATED:
|
94 |
return colorTables.get(rowIndex).getValue().isInterpolated();
|
95 |
} |
96 |
return null; |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public String getColumnName(int column) { |
101 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
102 |
switch (column) {
|
103 |
case COLUMN_PREVIEW:
|
104 |
return i18nManager.getTranslation("_preview"); |
105 |
case COLUMN_NAME:
|
106 |
return i18nManager.getTranslation("_name"); |
107 |
case COLUMN_CLASSES:
|
108 |
return i18nManager.getTranslation("_classes"); |
109 |
case COLUMN_INTERPOLATED:
|
110 |
return i18nManager.getTranslation("_interpolated"); |
111 |
} |
112 |
return null; |
113 |
} |
114 |
|
115 |
public boolean isCellEditable(int row, int col) { |
116 |
return false; |
117 |
} |
118 |
|
119 |
@Override
|
120 |
public Class<?> getColumnClass(int col) { |
121 |
if (col == COLUMN_PREVIEW) {
|
122 |
return ColorTable.class;
|
123 |
} else if (col == COLUMN_INTERPOLATED) { |
124 |
return Boolean.class; |
125 |
} |
126 |
return super.getColumnClass(col); |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void addColorTable(Pair<File,ColorTable> colorTable) { |
131 |
colorTables.add(colorTable); |
132 |
this.fireTableDataChanged();
|
133 |
} |
134 |
|
135 |
@Override
|
136 |
public void removeColorTable(int index) { |
137 |
colorTables.remove(index); |
138 |
this.fireTableDataChanged();
|
139 |
} |
140 |
|
141 |
@Override
|
142 |
public Pair<File, ColorTable> getColorTable(int index) { |
143 |
return colorTables.get(index);
|
144 |
} |
145 |
|
146 |
@Override
|
147 |
public void setColorTable(int index, ColorTable colorTableEdited) { |
148 |
colorTables.get(index).getValue().copyFrom(colorTableEdited); |
149 |
this.fireTableDataChanged();
|
150 |
} |
151 |
|
152 |
@Override
|
153 |
public List<Pair<File, ColorTable>> getColorTables() { |
154 |
return colorTables;
|
155 |
} |
156 |
|
157 |
} |