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 / statistics / StatisticsPanelController.java @ 6701
History | View | Annotate | Download (6.17 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.statistics; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.util.Locale; |
28 |
|
29 |
import javax.swing.JComponent; |
30 |
|
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
import org.gvsig.raster.lib.buffer.api.BandInfo; |
35 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
36 |
import org.gvsig.raster.lib.buffer.api.statistics.Statistics; |
37 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
38 |
import org.gvsig.raster.swing.buffer.statistics.StatisticsPanel; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.i18n.I18nManager; |
41 |
import org.gvsig.tools.util.InformationBuilder; |
42 |
import org.gvsig.tools.util.ToolsUtilLocator; |
43 |
|
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public class StatisticsPanelController extends StatisticsPanelView implements StatisticsPanel{ |
50 |
|
51 |
|
52 |
/**
|
53 |
*
|
54 |
*/
|
55 |
private static final long serialVersionUID = -8356595978140294871L; |
56 |
@SuppressWarnings("unused") |
57 |
private static final Logger LOG = LoggerFactory.getLogger(StatisticsPanelController.class); |
58 |
private Statistics statistics;
|
59 |
|
60 |
/**
|
61 |
* @param layer
|
62 |
*/
|
63 |
public StatisticsPanelController() {
|
64 |
translate(); |
65 |
this.btnRecalculate.addActionListener( new ActionListener() { |
66 |
@Override
|
67 |
public void actionPerformed(ActionEvent e) { |
68 |
doRecalculate(); |
69 |
} |
70 |
}); |
71 |
} |
72 |
|
73 |
private void translate() { |
74 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
75 |
txtStatistics.setToolTipText(i18nManager.getTranslation(txtStatistics.getToolTipText())); |
76 |
btnRecalculate.setText(i18nManager.getTranslation(btnRecalculate.getText())); |
77 |
btnRecalculate.setToolTipText(i18nManager.getTranslation(btnRecalculate.getToolTipText())); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* @param locale
|
82 |
*
|
83 |
*/
|
84 |
public void setLocate(Locale locale) { |
85 |
Locale l = super.getLocale(); |
86 |
if (!l.equals(locale)) {
|
87 |
translate(); |
88 |
} |
89 |
super.setLocale(locale);
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* @param layer
|
94 |
*/
|
95 |
public void set(Statistics statistics) { |
96 |
this.statistics = statistics;
|
97 |
txtStatistics.setText(this.getStatisticsString());
|
98 |
} |
99 |
|
100 |
private String getStatisticsString() { |
101 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
102 |
|
103 |
InformationBuilder builder = ToolsUtilLocator.getToolsUtilManager().createInformationBuilder(); |
104 |
|
105 |
int bandCounter = 0; |
106 |
for (StatisticsBand statisticsBand : this.statistics) { |
107 |
|
108 |
builder.title().labelkey(i18nManager.getTranslation("_band") + " " + bandCounter); |
109 |
|
110 |
int dataType = statisticsBand.getDataType();
|
111 |
builder.property().labelkey("_dataType").value(dataTypeString(dataType));
|
112 |
|
113 |
Long dataCount = statisticsBand.getBandLength();
|
114 |
builder.property().labelkey("_dataCount").value(dataCount.toString());
|
115 |
|
116 |
Long noDataValuesCount = statisticsBand.getNoDataValuesCount();
|
117 |
builder.property().labelkey("_noDataValuesCount").value(noDataValuesCount.toString());
|
118 |
|
119 |
Double minimum = statisticsBand.getMinimum();
|
120 |
builder.property().labelkey("_minimum").value(minimum.toString());
|
121 |
|
122 |
Double maximum = statisticsBand.getMaximum();
|
123 |
builder.property().labelkey("_maximum").value(maximum.toString());
|
124 |
|
125 |
Double mean = statisticsBand.getMean();
|
126 |
builder.property().labelkey("_mean").value(mean.toString());
|
127 |
|
128 |
Double median = statisticsBand.getMedian();
|
129 |
builder.property().labelkey("_median").value(median.toString());
|
130 |
|
131 |
Double secondMin = statisticsBand.getSecondMin();
|
132 |
builder.property().labelkey("_secondMin").value(secondMin.toString());
|
133 |
|
134 |
Double secondMax = statisticsBand.getSecondMax();
|
135 |
builder.property().labelkey("_secondMax").value(secondMax.toString());
|
136 |
|
137 |
Double variance = statisticsBand.getVariance();
|
138 |
builder.property().labelkey("_variance").value(variance.toString());
|
139 |
|
140 |
int bandCounter2 = 0; |
141 |
for (StatisticsBand statisticsBand2 : statistics) {
|
142 |
if (bandCounter != bandCounter2) {
|
143 |
Double covariance = statisticsBand.getCovariance(statisticsBand2);
|
144 |
builder.property().label(i18nManager.getTranslation("_covariance_with_band") + " " + bandCounter2) |
145 |
.value(covariance.toString()); |
146 |
} |
147 |
bandCounter2++; |
148 |
} |
149 |
bandCounter++; |
150 |
} |
151 |
|
152 |
return builder.toString();
|
153 |
} |
154 |
|
155 |
@Override
|
156 |
public JComponent asJComponent() { |
157 |
return this; |
158 |
} |
159 |
|
160 |
private void doRecalculate(){ |
161 |
this.statistics.calculate(null); |
162 |
} |
163 |
|
164 |
private String dataTypeString(int dataType) { |
165 |
|
166 |
// FIXME
|
167 |
switch (dataType) {
|
168 |
case BufferManager.TYPE_BYTE:
|
169 |
return "Byte"; |
170 |
case BufferManager.TYPE_USHORT:
|
171 |
return "Unsigned short"; |
172 |
case BufferManager.TYPE_SHORT:
|
173 |
return "Short"; |
174 |
case BufferManager.TYPE_INT:
|
175 |
return "Integer"; |
176 |
case BufferManager.TYPE_FLOAT:
|
177 |
return "Float"; |
178 |
case BufferManager.TYPE_DOUBLE:
|
179 |
return "Double"; |
180 |
default:
|
181 |
throw new IllegalArgumentException(); |
182 |
} |
183 |
} |
184 |
|
185 |
|
186 |
} |