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 @ 937

History | View | Annotate | Download (7.19 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

    
41
/**
42
 * Obtiene el panel con las opciones a realizar con la proyecci?n. Nos ofrece
43
 * las siguientes posibilidades:
44
 * <UL>
45
 * <LI>Cambiar la proyecci?n de la vista</LI>
46
 * <LI>Reproyectar el raster</LI>
47
 * <LI>Ignorar la proyecci?n del raster y cargar</LI>
48
 * <LI>No cargar</LI>
49
 * </UL>
50
 * 
51
 * 07/04/2008
52
 * @author Nacho Brodin nachobrodin@gmail.com
53
 */
54
public class RasterProjectionActionsPanel extends DefaultButtonsPanel {
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 JCheckBox     allfiles               = null;
64
        private boolean       layerIsReprojectable   = true;
65
        
66
        /**
67
         * Constructor. Llama al inicializador de componentes gr?ficos.
68
         */
69
        public RasterProjectionActionsPanel(boolean layerIsReprojectable, String layerName, int defaultAction) {
70
                super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
71
                this.layerIsReprojectable = layerIsReprojectable;
72
                init(layerName);
73
                setSelection(defaultAction);
74
        }
75
        
76
        /**
77
         * Inicializaci?n de componentes gr?ficos.
78
         */
79
        public void init(String lyrName) {
80
                BorderLayout bl = new BorderLayout();
81
                bl.setVgap(5);
82
                setLayout(bl);
83
                add(new JLabel("<html><b>" + lyrName + "</b><BR><BR>" + PluginServices.getText(this, "dif_proj") + "</html>"), BorderLayout.NORTH);
84
                add(getButtonsActionPanel(), BorderLayout.CENTER);
85
                add(getCheckOption(), BorderLayout.SOUTH);
86
        }
87
                
88
        /**
89
         * Obtiene el panel con los botones se selecci?n de opci?n.
90
         * @return JPanel
91
         */
92
        private JPanel getButtonsActionPanel() {
93
                if (buttonsPanel == null) {
94
                        buttonsPanel = new JPanel();
95
                        buttonsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "proj_options"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
96

    
97
                        group.add(getIgnoreRasterProjectionButton());
98
                        group.add(getChangeViewProjectionButton());
99
                        group.add(getReprojectButton());
100
                        group.add(getNotLoadButton());
101

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