Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / raster / gui / wizard / proj / RasterProjectionActionsPanel.java @ 1314

History | View | Annotate | Download (7.77 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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
*/
22
package org.gvsig.raster.tools.app.basic.raster.gui.wizard.proj;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27

    
28
import javax.swing.ButtonGroup;
29
import javax.swing.JCheckBox;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JRadioButton;
33

    
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
37
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
38
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
39
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
40
import org.gvsig.i18n.Messages;
41

    
42
/**
43
 * Obtiene el panel con las opciones a realizar con la proyecci?n. Nos ofrece
44
 * las siguientes posibilidades:
45
 * <UL>
46
 * <LI>Cambiar la proyecci?n de la vista</LI>
47
 * <LI>Reproyectar el raster</LI>
48
 * <LI>Ignorar la proyecci?n del raster y cargar</LI>
49
 * <LI>No cargar</LI>
50
 * </UL>
51
 * 
52
 * 07/04/2008
53
 * @author Nacho Brodin nachobrodin@gmail.com
54
 */
55
public class RasterProjectionActionsPanel extends DefaultButtonsPanel {
56
        private static final long serialVersionUID = -3868504818382448187L;
57

    
58
        private JPanel        buttonsPanel           = null;
59
        private ButtonGroup   group                  = new ButtonGroup();
60
        private JRadioButton  changeViewProjection   = null;
61
        private JRadioButton  reproject              = null;
62
        private JRadioButton  ignoreRasterProjection = null;
63
        private JRadioButton  notLoad                = null;
64
        private JRadioButton  onTheFly               = null;
65
        private JCheckBox     allfiles               = null;
66
        private boolean       layerIsReprojectable   = true;
67
        
68
        /**
69
         * Constructor. Llama al inicializador de componentes gr?ficos.
70
         */
71
        public RasterProjectionActionsPanel(boolean layerIsReprojectable, String layerName, int defaultAction) {
72
                super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
73
                this.layerIsReprojectable = layerIsReprojectable;
74
                init(layerName);
75
                setSelection(defaultAction);
76
        }
77
        
78
        /**
79
         * Inicializaci?n de componentes gr?ficos.
80
         */
81
        public void init(String lyrName) {
82
                BorderLayout bl = new BorderLayout();
83
                bl.setVgap(5);
84
                setLayout(bl);
85
                add(new JLabel("<html><b>" + lyrName + "</b><BR><BR>" + Messages.getText("dif_proj") + "</html>"), BorderLayout.NORTH);
86
                add(getButtonsActionPanel(), BorderLayout.CENTER);
87
                add(getCheckOption(), BorderLayout.SOUTH);
88
        }
89
                
90
        /**
91
         * Obtiene el panel con los botones se selecci?n de opci?n.
92
         * @return JPanel
93
         */
94
        private JPanel getButtonsActionPanel() {
95
                if (buttonsPanel == null) {
96
                        buttonsPanel = new JPanel();
97
                        buttonsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("proj_options"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
98

    
99
                        group.add(getIgnoreRasterProjectionButton());
100
                        group.add(getChangeViewProjectionButton());
101
                        group.add(getReprojectButton());
102
                        group.add(getNotLoadButton());
103
                        group.add(getOnTheFlyButton());
104

    
105
                        buttonsPanel.setLayout(new GridBagLayout());
106
                        GridBagConstraints gbc = new GridBagConstraints();
107
                        gbc.insets = new java.awt.Insets(0, 5, 5, 0);
108
                        
109
                        gbc.gridx = 0;
110
                        gbc.gridy = 0;
111
                        gbc.weightx = 1;
112
                        gbc.anchor = GridBagConstraints.WEST;
113
                        buttonsPanel.add(getIgnoreRasterProjectionButton(), gbc);
114
                        
115
                        gbc.gridy = 1;
116
                        buttonsPanel.add(getReprojectButton(), gbc);
117
                        
118
                        gbc.gridy = 2;
119
                        buttonsPanel.add(getChangeViewProjectionButton(), gbc);
120
                        
121
                        gbc.gridy = 3;
122
                        buttonsPanel.add(getNotLoadButton(), gbc);
123
                        
124
                        gbc.gridy = 4;
125
                        buttonsPanel.add(getOnTheFlyButton(), gbc);
126
                }
127
                return buttonsPanel;
128
        }
129
        
130
        /**
131
         * Obtiene el bot?n de cambio de projecci?n de la vista
132
         * @return
133
         */
134
        private JRadioButton getChangeViewProjectionButton() {
135
                if(changeViewProjection == null) {
136
                        changeViewProjection = new JRadioButton(Messages.getText("change_view_proj"));
137
                        
138
                        IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
139
                        if (activeWindow instanceof AbstractViewPanel) {                
140
                                AbstractViewPanel activeView = (org.gvsig.app.project.documents.view.gui.AbstractViewPanel) activeWindow;
141
                                if (activeView.getMapControl().getMapContext().getLayers().getLayersCount() >= 1)
142
                                        changeViewProjection.setEnabled(false);
143
                        }
144
                }
145
                return changeViewProjection;
146
        }
147
        
148
        /**
149
         * Obtiene el bot?n de cambio de reproyecci?n
150
         * @return
151
         */
152
        private JRadioButton getReprojectButton() {
153
                if(reproject == null) {
154
                        reproject = new JRadioButton(Messages.getText("reproject"));
155
                        reproject.setEnabled(layerIsReprojectable);
156
                }
157
                return reproject;
158
        }
159
        
160
        /**
161
         * Obtiene el bot?n de ignorar la proyecci?n del raster
162
         * @return
163
         */
164
        private JRadioButton getIgnoreRasterProjectionButton() {
165
                if(ignoreRasterProjection == null) {
166
                        ignoreRasterProjection = new JRadioButton(Messages.getText("ignore_raster_proj"));
167
                }
168
                return ignoreRasterProjection;
169
        }
170
        
171
        /**
172
         * Obtiene el bot?n de no cargar el raster.
173
         * @return
174
         */
175
        private JRadioButton getNotLoadButton() {
176
                if(notLoad == null) {
177
                        notLoad = new JRadioButton(Messages.getText("not_load"));
178
                }
179
                return notLoad;
180
        }
181
        
182
        /**
183
         * Gets the button to reproject on the fly
184
         * @return
185
         */
186
        private JRadioButton getOnTheFlyButton() {
187
                if(onTheFly == null) {
188
                        onTheFly = new JRadioButton(Messages.getText("reproject_on_the_fly") + " (Not implemented yet)");
189
                        onTheFly.setEnabled(false);
190
                }
191
                return onTheFly;
192
        }
193
        
194
        /**
195
         * Obtiene la selecci?n del panel
196
         * @return entero con la selecci?n. Esta representada por las constantes de FileOpenRaster.
197
         */
198
        public int getSelection() {
199
                if (getChangeViewProjectionButton().isSelected())
200
                        return RasterDataParameters.REPROJECT_VIEW;
201
                if (getReprojectButton().isSelected())
202
                        return RasterDataParameters.REPROJECT_DATA;
203
                if (getIgnoreRasterProjectionButton().isSelected())
204
                        return RasterDataParameters.DONT_CHANGE_PROJECTION;
205
                if (getNotLoadButton().isSelected())
206
                        return RasterDataParameters.NOT_LOAD;
207
                if (getOnTheFlyButton().isSelected())
208
                        return RasterDataParameters.ON_THE_FLY;
209
                return RasterDataParameters.DONT_CHANGE_PROJECTION;
210
        }
211
        
212
        /**
213
         * Asigna una selecci?n de opci?n
214
         * @param entero con la selecci?n. Esta representada por las constantes de FileOpenRaster.
215
         */
216
        public void setSelection(int value) {
217
                if (value == RasterDataParameters.DONT_CHANGE_PROJECTION)
218
                        getIgnoreRasterProjectionButton().setSelected(true);
219
                if (value == RasterDataParameters.REPROJECT_DATA)
220
                        getReprojectButton().setSelected(true);
221
                if (value == RasterDataParameters.REPROJECT_VIEW)
222
                        getChangeViewProjectionButton().setSelected(true);
223
                if (value == RasterDataParameters.NOT_LOAD)
224
                        getNotLoadButton().setSelected(true);
225
                if (value == RasterDataParameters.ON_THE_FLY)
226
                        getOnTheFlyButton().setSelected(true);
227
        }
228
        
229
        /**
230
         * Obtiene el check con la opci?n de aplicar a todos los ficheros
231
         * @return
232
         */
233
        public JCheckBox getCheckOption() {
234
                if (allfiles == null)
235
                        allfiles = new JCheckBox(PluginServices.getText(this, "apply_all"));
236
                return allfiles;
237
        }
238
}