svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / 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 @ 43803
History | View | Annotate | Download (5.6 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.BufferManager; |
35 |
import org.gvsig.raster.lib.buffer.api.statistics.Statistics; |
36 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
37 |
import org.gvsig.raster.swing.buffer.statistics.StatisticsPanel; |
38 |
import org.gvsig.tools.ToolsLocator; |
39 |
import org.gvsig.tools.dispose.Disposable; |
40 |
import org.gvsig.tools.dispose.DisposeUtils; |
41 |
import org.gvsig.tools.i18n.I18nManager; |
42 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
43 |
import org.gvsig.tools.swing.impl.DefaultActionListenerSupport; |
44 |
import org.gvsig.tools.util.InformationBuilder; |
45 |
import org.gvsig.tools.util.ToolsUtilLocator; |
46 |
|
47 |
|
48 |
/**
|
49 |
* @author fdiaz
|
50 |
*
|
51 |
*/
|
52 |
public class StatisticsPanelController extends StatisticsPanelView implements StatisticsPanel{ |
53 |
|
54 |
|
55 |
/**
|
56 |
*
|
57 |
*/
|
58 |
private static final long serialVersionUID = -8356595978140294871L; |
59 |
@SuppressWarnings("unused") |
60 |
private static final Logger LOG = LoggerFactory.getLogger(StatisticsPanelController.class); |
61 |
private ActionListenerSupport listenerSupport;
|
62 |
|
63 |
/**
|
64 |
* @param layer
|
65 |
*/
|
66 |
public StatisticsPanelController() {
|
67 |
translate(); |
68 |
this.btnRecalculate.addActionListener( new ActionListener() { |
69 |
@Override
|
70 |
public void actionPerformed(ActionEvent e) { |
71 |
doRecalculate(e); |
72 |
} |
73 |
}); |
74 |
listenerSupport = new DefaultActionListenerSupport();
|
75 |
} |
76 |
|
77 |
private void translate() { |
78 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
79 |
txtStatistics.setToolTipText(i18nManager.getTranslation(txtStatistics.getToolTipText())); |
80 |
btnRecalculate.setText(i18nManager.getTranslation(btnRecalculate.getText())); |
81 |
btnRecalculate.setToolTipText(i18nManager.getTranslation(btnRecalculate.getToolTipText())); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* @param locale
|
86 |
*
|
87 |
*/
|
88 |
public void setLocate(Locale locale) { |
89 |
Locale l = super.getLocale(); |
90 |
if (!l.equals(locale)) {
|
91 |
translate(); |
92 |
} |
93 |
super.setLocale(locale);
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* @param layer
|
98 |
*/
|
99 |
public void set(Statistics statistics) { |
100 |
txtStatistics.setText(statistics.toHTMLString()); |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public JComponent asJComponent() { |
105 |
return this; |
106 |
} |
107 |
|
108 |
private void doRecalculate(ActionEvent e){ |
109 |
this.fireActionEvent(new ActionEvent(this, e.getID(), e.getActionCommand())); |
110 |
} |
111 |
|
112 |
private String dataTypeString(int dataType) { |
113 |
|
114 |
// FIXME
|
115 |
switch (dataType) {
|
116 |
case BufferManager.TYPE_BYTE:
|
117 |
return "Byte"; |
118 |
case BufferManager.TYPE_USHORT:
|
119 |
return "Unsigned short"; |
120 |
case BufferManager.TYPE_SHORT:
|
121 |
return "Short"; |
122 |
case BufferManager.TYPE_INT:
|
123 |
return "Integer"; |
124 |
case BufferManager.TYPE_FLOAT:
|
125 |
return "Float"; |
126 |
case BufferManager.TYPE_DOUBLE:
|
127 |
return "Double"; |
128 |
default:
|
129 |
throw new IllegalArgumentException(); |
130 |
} |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public void addActionListener(ActionListener listener) { |
135 |
listenerSupport.addActionListener(listener); |
136 |
btnRecalculate.setEnabled(true);
|
137 |
|
138 |
} |
139 |
|
140 |
@Override
|
141 |
public ActionListener[] getActionListeners() { |
142 |
return listenerSupport.getActionListeners();
|
143 |
} |
144 |
|
145 |
@Override
|
146 |
public void removeActionListener(ActionListener listener) { |
147 |
listenerSupport.removeActionListener(listener); |
148 |
if(listenerSupport.getActionListeners().length == 0){ |
149 |
btnRecalculate.setEnabled(false);
|
150 |
} |
151 |
} |
152 |
|
153 |
@Override
|
154 |
public void removeAllActionListener() { |
155 |
listenerSupport.removeAllActionListener(); |
156 |
btnRecalculate.setEnabled(false);
|
157 |
} |
158 |
|
159 |
@Override
|
160 |
public void fireActionEvent(ActionEvent event) { |
161 |
ActionEvent e = null; |
162 |
|
163 |
ActionListener[] listeners = listenerSupport.getActionListeners(); |
164 |
for (ActionListener actionListener : listeners) { |
165 |
if (e == null) { |
166 |
String actionCommand = event.getActionCommand();
|
167 |
if (actionCommand == null) { |
168 |
if (e.getSource() == btnRecalculate) {
|
169 |
actionCommand = btnRecalculate.getActionCommand(); |
170 |
} |
171 |
} |
172 |
e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand); |
173 |
actionListener.actionPerformed(e); |
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
@Override
|
179 |
public boolean hasActionListeners() { |
180 |
return listenerSupport.hasActionListeners();
|
181 |
} |
182 |
} |