Statistics
| Revision:

root / org.gvsig.jcrs / tags / 2059 / extJCRS / src / org / gvsig / crs / gui / panels / ProjChooserPanel.java @ 71

History | View | Annotate | Download (7.98 KB)

1
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ibez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40
package org.gvsig.crs.gui.panels;
41

    
42
import java.awt.GridBagConstraints;
43
import java.awt.GridBagLayout;
44
import java.awt.GridLayout;
45
import java.awt.event.ActionListener;
46

    
47
import javax.swing.JLabel;
48
import javax.swing.JPanel;
49

    
50
import org.cresques.cts.IProjection;
51

    
52
import org.gvsig.andami.PluginServices;
53
import org.gvsig.andami.ui.mdiManager.IWindow;
54
import org.gvsig.app.addlayer.AddLayerDialog;
55
import org.gvsig.app.gui.panels.CRSSelectPanel;
56
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
57
import org.gvsig.crs.ICrs;
58
import org.gvsig.crs.gui.dialog.CSSelectionDialog;
59
import org.gvsig.crs.gui.dialog.TRSelectionDialog;
60
import org.gvsig.gui.beans.swing.JButton;
61

    
62

    
63
/**
64
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
65
 */
66
public class ProjChooserPanel extends CRSSelectPanel {
67
    
68
        private static final long serialVersionUID = 1L;
69
        
70
        public  ICrs curProj = null; 
71
        
72
        private JLabel jLblProj = null;
73
        private JLabel jLblProjName = null;
74
        private JButton jBtnChangeProj = null;
75
        private boolean okPressed = false;
76
        private String abrev;
77
        boolean panel = false;
78
        boolean targetNad = false;
79
        String dataSource = "EPSG";
80
        
81
        public ProjChooserPanel(IProjection proj) {
82
                super(proj);        
83
                IProjection pr = proj;
84
                IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
85
            if (activeWindow instanceof AbstractViewPanel) {                
86
                    AbstractViewPanel activeView = (AbstractViewPanel) activeWindow;
87
                    pr = activeView.getMapControl().getProjection();
88
            }
89
            AddLayerDialog.setLastProjection(pr);        
90
                setCurProj(pr);
91
                initialize();                
92
        }
93
        
94

    
95
        /**
96
         * This method initializes this
97
         *
98
         * @return void
99
         */
100
        private void initialize() {
101
        
102
        GridLayout gl = new GridLayout(1,2);
103
        
104
        this.setLayout(gl); // new FlowLayout(FlowLayout.LEFT, 15, 0));
105
        this.add(getJLblProjName());
106
        
107
        JPanel secondHalf = new JPanel(new GridBagLayout());
108
        
109
        GridBagConstraints c = new GridBagConstraints();
110
        
111
        c.fill = GridBagConstraints.HORIZONTAL;
112
        c.weightx = 1.0;   //request any extra hor space
113
        c.gridx = 0;      
114
        c.gridwidth = 1;  
115
        c.gridy = 0;      
116
        secondHalf.add(getJLblProj(), c);
117
        
118
        c.fill = GridBagConstraints.NONE;
119
        c.weightx = 0.0;  
120
        c.gridx = 1;      
121
        secondHalf.add(getJBtnChangeProj(), c);
122
        
123
        this.add(secondHalf);
124
        initBtnChangeProj();
125
        }
126

    
127
        private void initBtnChangeProj() {
128
                getJBtnChangeProj().addActionListener(new java.awt.event.ActionListener() {
129
                        public void actionPerformed(java.awt.event.ActionEvent e) {
130
                                CSSelectionDialog csSelect = null;
131
                                TRSelectionDialog trSelect = null;
132
                                if (!isTransPanelActive()){
133
                                        okPressed = false;
134
                                        csSelect = new CSSelectionDialog((ICrs) curProj);
135
                                        csSelect.setProjection(curProj);
136
                                        csSelect.initRecents(curProj);
137
                                        //csSelect.setLayout(new GridLayout(0,1));
138
                                        
139
                                PluginServices.getMDIManager().addWindow(csSelect);
140
//                                abrev = curProj.getAbrev();
141
                                abrev = dataSource+ ":" +String.valueOf(curProj.getCode());
142
                                if (csSelect.isOkPressed()) {
143
                                        curProj = (ICrs) csSelect.getProjection();
144
                                        dataSource = curProj.getCrsWkt().getAuthority()[0];
145
                                        //dataSource = csSelect.getDataSource();
146
                                        abrev = dataSource+ ":" +String.valueOf(curProj.getCode());
147
                                        
148
                                        getJLblProj().setText(dataSource+ ":" +String.valueOf(curProj.getCode()));//.getAbrev());
149
                                        AddLayerDialog.setLastProjection(curProj);
150
                                        okPressed = true;
151
                                        if (actionListener != null) {
152
                                                actionListener.actionPerformed(e);
153
                                        }
154
                                }else{
155
                                        getJLblProj().setText(abrev);                                          
156
                                }
157
                                }
158
                                else {
159
                                        okPressed = false;                                                                                
160
                                    trSelect = new TRSelectionDialog(curProj);
161
                                        
162
                                        trSelect.setProjection(curProj);
163
                                
164
                                        trSelect.setLayout(new GridLayout(0,1));
165
                                        
166
                                        PluginServices.getMDIManager().addWindow(trSelect);
167
                                        setTargetNad(trSelect.getTargetNad());
168
                                //abrev = curProj.getAbrev();
169
                                        
170
                                if (trSelect.getProjection() != curProj) {
171
                                        curProj = (ICrs) trSelect.getProjection();
172
                                        dataSource = curProj.getCrsWkt().getAuthority()[0];
173
                                        //dataSource = trSelect.getProjPanel().getDataSource();
174
                                        //abrev = trSelect.getProjectionName();
175
                                        getJLblProj().setText(dataSource+ ":" +String.valueOf(curProj.getCode()));//abrev);
176
                                        AddLayerDialog.setLastProjection(curProj);                                        
177
                                        okPressed = true;
178
                                        
179
                                        if (actionListener != null) {
180
                                                actionListener.actionPerformed(e);
181
                                        }
182
                                }else{
183
                                        refresh();
184
                                }
185
                                }
186
                                                        
187
                        }
188
                });
189
        }
190

    
191

    
192

    
193
        public JLabel getJLblProjName() {
194
                if (jLblProjName == null) {
195
                jLblProjName = new JLabel("Proyeccion actual");
196
                        jLblProjName.setText(PluginServices.getText(this,"proyeccion_actual")); //$NON-NLS-1$
197
                }
198
                return jLblProjName;
199
        }
200
        
201
        public JLabel getJLabel() {
202
                return getJLblProjName();
203
        }
204

    
205
        public JLabel getJLblProj() {
206
                if (jLblProj == null) {
207
                jLblProj = new JLabel();
208
                }
209
                return jLblProj;
210
        }
211

    
212
        /**
213
         * This method initializes jButton
214
         *
215
         * @return javax.swing.JButton
216
         */
217
        public JButton getJBtnChangeProj() {
218
                if (jBtnChangeProj == null) {
219
                        jBtnChangeProj = new JButton();                        
220
                        jBtnChangeProj.setText("..."); //$NON-NLS-1$
221
                        // jBtnChangeProj.setPreferredSize(new Dimension(50, 23));
222
                }
223
                return jBtnChangeProj;
224
        }
225
        
226
        public void setTargetNad(boolean tarNad){
227
                targetNad = tarNad;
228
        }
229
        
230
        public boolean getTargetNad(){
231
                return targetNad;
232
        }
233
        
234
        /**
235
         * @return Returns the curProj.
236
         */
237
        public IProjection getCurProj() {
238
                return curProj;
239
        }
240
        
241
        /**
242
         * @param curProj The curProj to set.
243
         */
244
        public void setCurProj(IProjection curProj) {
245
                this.curProj = (ICrs) curProj;
246
                refresh();
247
        }
248
        
249
        private void refresh() {
250
                if (curProj != null){   
251
            dataSource = curProj.getCrsWkt().getAuthority()[0];
252
            String text = dataSource + ":" + String.valueOf(curProj.getCode());
253
            getJLblProj().setText(text.trim());              
254
        }else{
255
                getJLblProj().setText("");
256
        }
257
        }
258
        
259
        /**
260
         * @return Returns the okPressed.
261
         */
262
        public boolean isOkPressed() {
263
                return okPressed;
264
        }
265
        
266
        /**
267
         * @param actionListener The actionListener to set.
268
         */
269
        public void addActionListener(ActionListener actionListener) {
270
                this.actionListener = actionListener;
271
        }
272
}  //  @jve:decl-index=0:visual-constraint="10,10"