gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.buffer / org.gvsig.raster.swing.buffer.impl / src / main / java / org / gvsig / raster / swing / buffer / impl / histogram / StatisticsTableModel.java @ 6703
History | View | Annotate | Download (5.52 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.buffer.impl.histogram; |
24 |
|
25 |
import java.util.List; |
26 |
|
27 |
import javax.swing.table.AbstractTableModel; |
28 |
|
29 |
import org.gvsig.raster.lib.buffer.api.statistics.Statistics; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.i18n.I18nManager; |
32 |
|
33 |
|
34 |
/**
|
35 |
* @author fdiaz
|
36 |
*
|
37 |
*/
|
38 |
public class StatisticsTableModel extends AbstractTableModel { |
39 |
|
40 |
/**
|
41 |
*
|
42 |
*/
|
43 |
private static final long serialVersionUID = 5110298183227533382L; |
44 |
|
45 |
private Statistics statistics;
|
46 |
private List<Integer> selectedBands; |
47 |
|
48 |
public static final int COLUMNS = 9; |
49 |
|
50 |
public static final int COLUMN_NUMBER = 0; |
51 |
public static final int COLUMN_LENGTH = 1; |
52 |
public static final int COLUMN_MAX = 2; |
53 |
public static final int COLUMN_SECOND_MAX = 3; |
54 |
public static final int COLUMN_MIN = 4; |
55 |
public static final int COLUMN_SECOND_MIN = 5; |
56 |
public static final int COLUMN_MEAN = 6; |
57 |
public static final int COLUMN_MEDIAN = 7; |
58 |
public static final int COLUMN_VARIANCE = 8; |
59 |
|
60 |
/**
|
61 |
* @param statistics
|
62 |
* @param selectedBands
|
63 |
*/
|
64 |
public StatisticsTableModel(Statistics statistics, List<Integer> selectedBands) { |
65 |
this.statistics = statistics;
|
66 |
this.selectedBands = selectedBands;
|
67 |
} |
68 |
|
69 |
/* (non-Javadoc)
|
70 |
* @see javax.swing.table.TableModel#getRowCount()
|
71 |
*/
|
72 |
@Override
|
73 |
public int getRowCount() { |
74 |
if(statistics==null){ |
75 |
return 0; |
76 |
} |
77 |
return selectedBands.size(); //.getBandCount(); |
78 |
} |
79 |
|
80 |
/* (non-Javadoc)
|
81 |
* @see javax.swing.table.TableModel#getColumnCount()
|
82 |
*/
|
83 |
@Override
|
84 |
public int getColumnCount() { |
85 |
return COLUMNS;
|
86 |
} |
87 |
|
88 |
/* (non-Javadoc)
|
89 |
* @see javax.swing.table.TableModel#getValueAt(int, int)
|
90 |
*/
|
91 |
@Override
|
92 |
public Object getValueAt(int rowIndex, int columnIndex) { |
93 |
switch (columnIndex) {
|
94 |
case COLUMN_NUMBER:
|
95 |
return selectedBands.get(rowIndex);
|
96 |
case COLUMN_LENGTH:
|
97 |
if(statistics==null || selectedBands==null || selectedBands.size()==0){ |
98 |
return 0; |
99 |
} |
100 |
return statistics.getNumberOfValues()[selectedBands.get(rowIndex)];
|
101 |
case COLUMN_MAX:
|
102 |
if(statistics==null){ |
103 |
return null; //noValidValueString(); |
104 |
} |
105 |
return statistics.getMax()[selectedBands.get(rowIndex)];
|
106 |
case COLUMN_SECOND_MAX:
|
107 |
if(statistics==null){ |
108 |
return null; //noValidValueString(); |
109 |
} |
110 |
return statistics.getSecondMax()[selectedBands.get(rowIndex)];
|
111 |
case COLUMN_MIN:
|
112 |
if(statistics==null){ |
113 |
return null; //noValidValueString(); |
114 |
} |
115 |
return statistics.getMin()[selectedBands.get(rowIndex)];
|
116 |
case COLUMN_SECOND_MIN:
|
117 |
if(statistics==null){ |
118 |
return null; //noValidValueString(); |
119 |
} |
120 |
return statistics.getSecondMin()[selectedBands.get(rowIndex)];
|
121 |
case COLUMN_MEAN:
|
122 |
if(statistics==null){ |
123 |
return null; //noValidValueString(); |
124 |
} |
125 |
return statistics.getMean()[selectedBands.get(rowIndex)];
|
126 |
case COLUMN_MEDIAN:
|
127 |
if(statistics==null){ |
128 |
return null; //noValidValueString(); |
129 |
} |
130 |
return statistics.getMedian()[selectedBands.get(rowIndex)];
|
131 |
case COLUMN_VARIANCE:
|
132 |
if(statistics==null){ |
133 |
return null; //noValidValueString(); |
134 |
} |
135 |
return statistics.getVariance()[selectedBands.get(rowIndex)];
|
136 |
} |
137 |
return null; |
138 |
} |
139 |
|
140 |
|
141 |
@Override
|
142 |
public String getColumnName(int column) { |
143 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
144 |
switch (column) {
|
145 |
|
146 |
case COLUMN_NUMBER:
|
147 |
return i18nManager.getTranslation("_number"); |
148 |
case COLUMN_LENGTH:
|
149 |
return i18nManager.getTranslation("_number_of_values"); |
150 |
case COLUMN_MAX:
|
151 |
return i18nManager.getTranslation("_maximum"); |
152 |
case COLUMN_SECOND_MAX:
|
153 |
return i18nManager.getTranslation("_second_maximum"); |
154 |
case COLUMN_MIN:
|
155 |
return i18nManager.getTranslation("_minimum"); |
156 |
case COLUMN_SECOND_MIN:
|
157 |
return i18nManager.getTranslation("_second_minimum"); |
158 |
case COLUMN_MEAN:
|
159 |
return i18nManager.getTranslation("_mean"); |
160 |
case COLUMN_MEDIAN:
|
161 |
return i18nManager.getTranslation("_median"); |
162 |
case COLUMN_VARIANCE:
|
163 |
return i18nManager.getTranslation("_variance"); |
164 |
} |
165 |
return null; |
166 |
} |
167 |
|
168 |
public boolean isCellEditable(int row, int col) { |
169 |
return false; |
170 |
} |
171 |
|
172 |
} |