Statistics
| Revision:

root / org.gvsig.jcrs / trunk / extJCRS / src / org / gvsig / crs / gui / panels / ProjChooserPanel.java @ 60

History | View | Annotate | Download (7.58 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.Dimension;
43
import java.awt.FlowLayout;
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
import org.gvsig.andami.PluginServices;
52
import org.gvsig.andami.ui.mdiManager.IWindow;
53
import org.gvsig.app.addlayer.AddLayerDialog;
54
import org.gvsig.app.gui.panels.CRSSelectPanel;
55
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
56
import org.gvsig.crs.ICrs;
57
import org.gvsig.crs.gui.dialog.CSSelectionDialog;
58
import org.gvsig.crs.gui.dialog.TRSelectionDialog;
59
import org.gvsig.gui.beans.swing.JButton;
60

    
61

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

    
94
        /**
95
         * This method initializes this
96
         *
97
         * @return void
98
         */
99
        private void initialize() {
100
        
101
        GridLayout gl = new GridLayout(1,2);
102
        
103
        this.setLayout(gl); // new FlowLayout(FlowLayout.LEFT, 15, 0));
104
        this.add(getJLblProjName());
105
        
106
        JPanel secondHalf = new JPanel(gl);
107
        secondHalf.add(getJLblProj());
108
        secondHalf.add(getJBtnChangeProj());
109
        this.add(secondHalf);
110
        
111
        initBtnChangeProj();
112

    
113
        }
114

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

    
179

    
180

    
181
        public JLabel getJLblProjName() {
182
                if (jLblProjName == null) {
183
                jLblProjName = new JLabel("Proyeccion actual");
184
                        jLblProjName.setText(PluginServices.getText(this,"proyeccion_actual")); //$NON-NLS-1$
185
                }
186
                return jLblProjName;
187
        }
188
        
189
        public JLabel getJLabel() {
190
                return getJLblProjName();
191
        }
192

    
193
        public JLabel getJLblProj() {
194
                if (jLblProj == null) {
195
                jLblProj = new JLabel();                
196
                }
197
                return jLblProj;
198
        }
199

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