Statistics
| Revision:

gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.swing / org.gvsig.raster.georeferencing.swing.impl / src / main / java / org / gvsig / raster / georeferencing / swing / impl / control / GeorefControlPanelImpl.java @ 1724

History | View | Annotate | Download (10.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.raster.georeferencing.swing.impl.control;
25

    
26
import java.awt.Dimension;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.event.ComponentEvent;
30
import java.io.File;
31

    
32
import javax.swing.ImageIcon;
33
import javax.swing.JButton;
34
import javax.swing.JPanel;
35
import javax.swing.JToggleButton;
36

    
37
import org.gvsig.andami.IconThemeHelper;
38
import org.gvsig.gui.beans.datainput.DataInputContainer;
39
import org.gvsig.i18n.Messages;
40
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanel;
41
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanelListener;
42

    
43
/**
44
 * Panel que contiene la tabla de puntos de control
45
 * 
46
 * 22/12/2007
47
 * @author Nacho Brodin (nachobrodin@gmail.com)
48
 */
49
public class GeorefControlPanelImpl extends JPanel implements GeorefControlPanel {
50
        private static final long             serialVersionUID     = 1L;
51
        private JPanel                        buttonsPanel         = null;
52
        private JButton                       bSaveToXml           = null;
53
        private JButton                       bLoadFromXml         = null;
54
        private JButton                       bSaveToAscii         = null;
55
        private JButton                       bLoadFromAscii       = null;
56
        private JButton                       bOptions             = null;
57
        private JButton                       bTest                = null;
58
        private JButton                       bEndTest             = null;
59
        private JButton                       bEndGeoref           = null;
60
        private JButton                       bCenterView          = null;
61
        private JToggleButton                 bAddPoint            = null;
62
        private DataInputContainer            error                = null;
63
        
64
        private String                        pathToImagesForTest = "/src/main/resources/image/";
65
        
66
        /**
67
         * Constructor.
68
         * Crea la composici?n de controles de zoom.
69
         */
70
        public GeorefControlPanelImpl() {
71
                init();
72
        }
73
        
74
        public int getButtonIDPressed(Object source) {
75
                if(source == bSaveToXml)
76
                        return GeorefControlPanel.bSaveToXml;
77
                if(source == bLoadFromXml)
78
                        return GeorefControlPanel.bLoadFromXml;
79
                if(source == bSaveToAscii)
80
                        return GeorefControlPanel.bSaveToAscii;
81
                if(source == bLoadFromAscii)
82
                        return GeorefControlPanel.bLoadFromAscii;
83
                if(source == bTest)
84
                        return GeorefControlPanel.bTest;
85
                if(source == bOptions)
86
                        return GeorefControlPanel.bOptions;
87
                if(source == bEndTest)
88
                        return GeorefControlPanel.bEndTest;
89
                if(source == bEndGeoref)
90
                        return GeorefControlPanel.bEndGeoref;
91
                if(source == bCenterView)
92
                        return GeorefControlPanel.bCenterView;
93
                if(source == bAddPoint)
94
                        return GeorefControlPanel.bAddPoint;
95
                return -1;
96
        }
97

    
98
        public JPanel getComponent() {
99
                return this;
100
        }
101
        
102
        public void setListener(GeorefControlPanelListener listener) {
103
                getSaveToXMLButton().addActionListener(listener);
104
                getLoadFromXMLButton().addActionListener(listener);
105
                getExporToCSVButton().addActionListener(listener);
106
                getLoadFromCSVButton().addActionListener(listener);
107
                getOptionsButton().addActionListener(listener);
108
                getCenterButton().addActionListener(listener);
109
                getToolSelectPointButton().addActionListener(listener);
110
                getEndGeorefButton().addActionListener(listener);
111
                getTestButton().addActionListener(listener);
112
                getEndTestButton().addActionListener(listener);
113
        }
114
        
115
        private void init() {
116
                setLayout(new GridBagLayout());
117
                //setPreferredSize(new java.awt.Dimension(0, h)); 
118
                
119
                GridBagConstraints gb = new GridBagConstraints();
120
                gb.insets = new java.awt.Insets(0, 0, 0, 0);
121
                
122
                gb.fill = GridBagConstraints.HORIZONTAL;
123
                gb.weightx = 1;
124
                gb.weighty = 0;
125
                gb.gridx = 0;
126
                add(new JPanel(), gb);
127
                gb.gridx = 2;
128
                add(new JPanel(), gb);
129
                
130
                gb.fill = GridBagConstraints.NONE;
131
                gb.weightx = 0;
132
                gb.gridx = 1;
133
                add(getButtonsPanel(), gb);
134
        }
135
        
136
        /**
137
         * Obtiene el panel de botones
138
         * @return JPanel
139
         */
140
        public JPanel getButtonsPanel() {
141
                if(buttonsPanel == null) {
142
                        buttonsPanel = new JPanel();
143
                        buttonsPanel.setLayout(new GridBagLayout());
144
                        
145
                        GridBagConstraints gb = new GridBagConstraints();
146
                        gb.insets = new java.awt.Insets(0, 0, 1, 1);
147
                        gb.fill = GridBagConstraints.NONE;
148
                        gb.weightx = 0;
149
                        gb.gridy = 0;
150
                        gb.gridx = 0;
151
                        buttonsPanel.add(getSaveToXMLButton(), gb);
152
                        
153
                        gb.gridy = 0;
154
                        gb.gridx = 1;
155
                        buttonsPanel.add(getLoadFromXMLButton(), gb);
156
                        
157
                        gb.gridy = 0;
158
                        gb.gridx = 2;
159
                        buttonsPanel.add(getExporToCSVButton(), gb);
160
                        
161
                        gb.gridy = 0;
162
                        gb.gridx = 3;
163
                        buttonsPanel.add(getLoadFromCSVButton(), gb);
164
                        
165
                        gb.gridy = 0;
166
                        gb.gridx = 4;
167
                        buttonsPanel.add(getOptionsButton(), gb);
168
                        
169
                        gb.gridy = 0;
170
                        gb.gridx = 5;
171
                        buttonsPanel.add(getCenterButton(), gb);
172
                        
173
                        gb.gridy = 0;
174
                        gb.gridx = 6;
175
                        buttonsPanel.add(getToolSelectPointButton(), gb);
176
                        
177
                        gb.gridy = 0;
178
                        gb.gridx = 7;
179
                        buttonsPanel.add(getEndGeorefButton(), gb);
180
                        
181
                        gb.gridy = 0;
182
                        gb.gridx = 8;
183
                        buttonsPanel.add(getTestButton(), gb);
184
                        
185
                        gb.gridy = 0;
186
                        gb.gridx = 9;
187
                        buttonsPanel.add(getEndTestButton(), gb);
188
                        
189
                        gb.gridy = 0;
190
                        gb.gridx = 10;
191
                        buttonsPanel.add(getError(), gb);
192
                }
193
                return buttonsPanel;
194
        }
195
        
196
        /**
197
         * Obtiene el objeto con el error total
198
         * @return
199
         */
200
        public DataInputContainer getError() {
201
                if(error == null) {
202
                        error = new DataInputContainer();
203
                        error.setLabelText("RMS");
204
                        error.setPreferredSize(new Dimension(85, 35));
205
                }
206
                return error;
207
        }
208
        
209
        /**
210
         * Obtiene el bot?n de finalizar georreferenciaci?n. Si no existe se crea.
211
         * @return JButton
212
         */
213
        public JButton getEndGeorefButton() {
214
                if(bEndGeoref == null) {
215
                        bEndGeoref = new JButton();
216
                        bEndGeoref.setPreferredSize(new Dimension(22, 22));
217
                        bEndGeoref.setIcon(loadIcon("exit-icon"));
218
                        bEndGeoref.setToolTipText(Messages.getText("end_georef"));
219
                }
220
                return bEndGeoref;
221
        }
222
        
223
        /**
224
         * Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
225
         * @return JButton
226
         */
227
        public JButton getTestButton() {
228
                if(bTest == null) {
229
                        bTest = new JButton();
230
                        bTest.setPreferredSize(new Dimension(22, 22));
231
                        bTest.setToolTipText(Messages.getText("test_georef"));
232
                        bTest.setIcon(loadIcon("process-icon"));
233
                }
234
                return bTest;
235
        }
236
        
237
        /**
238
         * Obtiene el bot?n de terminar el test de georreferenciaci?n. Si no existe se crea.
239
         * @return JButton
240
         */
241
        public JButton getEndTestButton() {
242
                if(bEndTest == null) {
243
                        bEndTest = new JButton();
244
                        bEndTest.setPreferredSize(new Dimension(22, 22));
245
                        bEndTest.setToolTipText(Messages.getText("end_test_georef"));
246
                        bEndTest.setIcon(loadIcon("endprocess-icon"));
247
                }
248
                return bEndTest;
249
        }
250
                
251
        /**
252
         * Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
253
         * @return JButton
254
         */
255
        public JButton getLoadFromCSVButton() {
256
                if(bLoadFromAscii == null) {
257
                        bLoadFromAscii = new JButton();
258
                        bLoadFromAscii.setPreferredSize(new Dimension(22, 22));
259
                        bLoadFromAscii.setToolTipText(Messages.getText("load_from_ascii"));
260
                        bLoadFromAscii.setIcon(loadIcon("importfromcsv-icon"));
261
                }
262
                return bLoadFromAscii;
263
        }
264
        
265
        /**
266
         * Obtiene el bot?n de exportar a Ascii. Si no existe se crea.
267
         * @return JButton
268
         */
269
        public JButton getExporToCSVButton() {
270
                if(bSaveToAscii == null) {
271
                        bSaveToAscii = new JButton();
272
                        bSaveToAscii.setPreferredSize(new Dimension(22, 22));
273
                        bSaveToAscii.setToolTipText(Messages.getText("save_to_ascii"));
274
                        bSaveToAscii.setIcon(loadIcon("exporttocsv-icon"));
275
                }
276
                return bSaveToAscii;
277
        }
278
        
279
        /**
280
         * Obtiene el bot?n de cargar desde XML. Si no existe se crea.
281
         * @return JButton
282
         */
283
        public JButton getLoadFromXMLButton() {
284
                if(bLoadFromXml == null) {
285
                        bLoadFromXml = new JButton();
286
                        bLoadFromXml.setPreferredSize(new Dimension(22, 22));
287
                        bLoadFromXml.setToolTipText(Messages.getText("load_from_xml"));
288
                        bLoadFromXml.setIcon(loadIcon("tfwload-icon"));
289
                }
290
                return bLoadFromXml;
291
        }
292
        
293
        private ImageIcon loadIcon(String iconName) {
294
                ImageIcon icon = null;
295
                try {
296
                        icon = IconThemeHelper.getImageIcon(iconName);
297
                } catch(NullPointerException e) {}
298
                String file = System.getProperty("user.dir") + pathToImagesForTest + iconName;
299
                if(icon == null) { 
300
                        if(new File(file + ".png").exists())
301
                                icon = new ImageIcon(file + ".png", "");
302
                }
303
                if(icon == null) {
304
                        if(new File(file + ".gif").exists())
305
                        icon = new ImageIcon(file + ".gif", "");
306
                }
307
                return icon;
308
        }
309
        
310
        /**
311
         * Obtiene el bot?n de salvar a XML. Si no existe se crea.
312
         * @return JButton
313
         */
314
        public JButton getSaveToXMLButton() {
315
                if(bSaveToXml == null) {
316
                        bSaveToXml = new JButton();
317
                        bSaveToXml.setPreferredSize(new Dimension(22, 22));
318
                        bSaveToXml.setToolTipText(Messages.getText("save_gcp_to_xml"));
319
                        bSaveToXml.setIcon(loadIcon("save-icon"));
320
                }
321
                return bSaveToXml;
322
        }
323
        
324
        /**
325
         * Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
326
         * @return JButton
327
         */
328
        public JButton getOptionsButton() {
329
                if(bOptions == null) {
330
                        bOptions = new JButton();
331
                        bOptions.setPreferredSize(new Dimension(22, 22));
332
                        bOptions.setToolTipText(Messages.getText("options"));
333
                        bOptions.setIcon(loadIcon("options-icon"));
334
                }
335
                return bOptions;
336
        }
337
        
338
        /**
339
         * Obtiene el bot?n de asignar el punto de control seleccionado en la tabla sobre 
340
         * una posici?n de la vista. Si no existe se crea.
341
         * @return JButton
342
         */
343
        public JToggleButton getToolSelectPointButton() {
344
                if(bAddPoint == null) {
345
                        bAddPoint = new JToggleButton();
346
                        bAddPoint.setPreferredSize(new Dimension(22, 22));
347
                        bAddPoint.setToolTipText(Messages.getText("move-point"));
348
                        bAddPoint.setIcon(loadIcon("add-icon"));
349
                }
350
                return bAddPoint;
351
        }
352
        
353
        /**
354
         * Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
355
         * @return JButton
356
         */
357
        public JButton getCenterButton() {
358
                if(bCenterView == null) {
359
                        bCenterView = new JButton();
360
                        bCenterView.setPreferredSize(new Dimension(22, 22));
361
                        bCenterView.setToolTipText(Messages.getText("center_view"));
362
                        bCenterView.setIcon(loadIcon("centerpoint-icon"));
363
                }
364
                return bCenterView;
365
        }
366
        
367
        public void componentHidden(ComponentEvent e) {
368
        }
369

    
370
        public void componentMoved(ComponentEvent e) {
371
        }
372

    
373
        public void componentShown(ComponentEvent e) {
374
        }
375
}
376

    
377