Statistics
| Revision:

gvsig-raster / org.gvsig.raster.reproject / branches / org.gvsig.raster.reproject_dataaccess_refactoring / org.gvsig.raster.reproject.app.reprojectclient / src / main / java / org / gvsig / raster / reproject / app / preparelayer / RasterProjectionActionsPanel.java @ 2440

History | View | Annotate | Download (7.75 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.reproject.app.preparelayer;
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.i18n.Messages;
39
import org.gvsig.raster.swing.basepanel.AbstractButtonsPanel;
40
import org.gvsig.raster.swing.basepanel.IButtonsPanel;
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
 * @author Nacho Brodin nachobrodin@gmail.com
53
 */
54
public class RasterProjectionActionsPanel extends AbstractButtonsPanel {
55
        private static final long serialVersionUID = -3868504818382448187L;
56

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

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

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