Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / ProjChooserPanel.java @ 8426

History | View | Annotate | Download (6.29 KB)

1
/*
2
 * Created on 30-ene-2005
3
 */
4
package org.gvsig.crs.gui.panels;
5

    
6
import java.awt.Dimension;
7
import java.awt.FlowLayout;
8
import java.awt.GridLayout;
9
import java.awt.event.ActionListener;
10

    
11
import org.gvsig.gui.beans.swing.JButton;
12
import javax.swing.JLabel;
13
import javax.swing.UIDefaults.ActiveValue;
14

    
15
import org.cresques.cts.IProjection;
16
import org.gvsig.crs.EpsgConnection;
17
import org.gvsig.crs.ICrs;
18
import org.gvsig.crs.gui.dialog.CSSelectionDialog;
19
import org.gvsig.crs.gui.dialog.TRSelectionDialog;
20

    
21
import com.iver.andami.PluginServices;
22
import com.iver.andami.ui.mdiManager.IWindow;
23
import com.iver.cit.gvsig.gui.FOpenDialog;
24
import com.iver.cit.gvsig.gui.View;
25
import com.iver.cit.gvsig.gui.panels.CRSSelectPanel;
26

    
27
/**
28
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
29
 */
30
public class ProjChooserPanel extends CRSSelectPanel {
31
    
32
        private static final long serialVersionUID = 1L;
33
        
34
        public  ICrs curProj = null; //(IProjection) new CRSFactory().getCRS("EPSG:23030");
35
        
36
        private JLabel jLblProj = null;
37
        private JLabel jLblProjName = null;
38
        private JButton jBtnChangeProj = null;
39
        private boolean okPressed = false;
40
        private String abrev;
41
        boolean panel = false;
42
        boolean targetNad = false;
43
        String dataSource = "EPSG";
44
        
45
        private ActionListener actionListener = null;
46
        
47
        public ProjChooserPanel(IProjection proj) {
48
                super(proj);        
49
                IProjection pr = proj;
50
                IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
51
            if (activeWindow instanceof View) {                
52
                    View activeView = (com.iver.cit.gvsig.gui.View) activeWindow;
53
                    pr = activeView.getMapControl().getProjection();
54
            }
55
            FOpenDialog.setLastProjection(pr);        
56
                setCurProj(pr);
57
                initialize();                
58
        }
59
        
60

    
61
        /**
62
         * This method initializes this
63
         *
64
         * @return void
65
         */
66
        private void initialize() {
67
                this.setLayout(new GridLayout(3,1));
68
        this.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 0));
69
        setPreferredSize(new java.awt.Dimension(330,35));
70
        this.setSize(new java.awt.Dimension(330,23));
71
        this.add(getJLblProjName(), null);
72
        this.add(getJLblProj(), null);
73
        this.add(getJBtnChangeProj(), null);
74
       
75
        
76
        //cambiar cuando la parte de JLuis se ensamble
77
        if(!((ICrs)curProj).getAbrev().equals("EPSG:23030")){
78
                dataSource = curProj.getCrsWkt().getAuthority()[0];
79
                jLblProj.setText(dataSource+":" +String.valueOf(curProj.getCode()));
80
                //jLblProj.setText(((ICrs)curProj).getCrsWkt().getName());
81
        }
82
        else
83
                jLblProj.setText("EPSG:23030");        
84
                initBtnChangeProj();
85
        }
86

    
87
        private void initBtnChangeProj() {
88
                getJBtnChangeProj().addActionListener(new java.awt.event.ActionListener() {
89
                        public void actionPerformed(java.awt.event.ActionEvent e) {
90
                                CSSelectionDialog csSelect = null;
91
                                TRSelectionDialog trSelect = null;
92
                                if (!isTransPanelActive()){
93
                                        okPressed = false;
94
                                        csSelect = new CSSelectionDialog();
95
                                        csSelect.setProjection(curProj);
96
                                        
97
                                        //csSelect.setLayout(new GridLayout(0,1));
98
                                        
99
                                PluginServices.getMDIManager().addWindow(csSelect);
100
                                abrev = dataSource+ ":" +String.valueOf(curProj.getCode());
101
                                if (csSelect.isOkPressed()) {
102
                                        curProj = (ICrs) csSelect.getProjection();
103
                                        dataSource = curProj.getCrsWkt().getAuthority()[0];
104
                                        //dataSource = csSelect.getDataSource();
105
                                        abrev = dataSource+ ":" +String.valueOf(curProj.getCode());
106
                                        
107
                                        jLblProj.setText(dataSource+ ":" +String.valueOf(curProj.getCode()));//.getAbrev());
108
                                        FOpenDialog.setLastProjection(curProj);
109
                                        okPressed = true;
110
                                        if (actionListener != null) {
111
                                                actionListener.actionPerformed(e);
112
                                        }
113
                                }else                                        
114
                                        jLblProj.setText(abrev);  
115
                                }
116
                                else {
117
                                        okPressed = false;                                                                                
118
                                    trSelect = new TRSelectionDialog(curProj);
119
                                        
120
                                        trSelect.setProjection(curProj);
121
                                
122
                                        trSelect.setLayout(new GridLayout(0,1));
123
                                        
124
                                        PluginServices.getMDIManager().addWindow(trSelect);
125
                                        setTargetNad(trSelect.getTargetNad());
126
                                //abrev = curProj.getAbrev();
127
                                        
128
                                if (trSelect.getProjection() != curProj) {
129
                                        curProj = (ICrs) trSelect.getProjection();
130
                                        dataSource = curProj.getCrsWkt().getAuthority()[0];
131
                                        //dataSource = trSelect.getProjPanel().getDataSource();
132
                                        //abrev = trSelect.getProjectionName();
133
                                        jLblProj.setText(dataSource+ ":" +String.valueOf(curProj.getCode()));//abrev);
134
                                        FOpenDialog.setLastProjection(curProj);                                        
135
                                        okPressed = true;
136
                                        
137
                                        if (actionListener != null) {
138
                                                actionListener.actionPerformed(e);
139
                                        }
140
                                }else
141
                                        jLblProj.setText(dataSource+ ":" +String.valueOf(curProj.getCode()));//abrev);
142
                                        
143
                                }
144
                                                        
145
                        }
146
                });
147
        }
148

    
149
        public JLabel getJLblProjName() {
150
                if (jLblProjName == null) {
151
                jLblProjName = new JLabel("Proyeccion actual");
152
                        jLblProjName.setText(PluginServices.getText(this,"proyeccion_actual")); //$NON-NLS-1$
153
                }
154
                return jLblProjName;
155
        }
156

    
157
        public JLabel getJLblProj() {
158
                if (jLblProj == null) {
159
                jLblProj = new JLabel();
160
                        jLblProj.setText(curProj.getAbrev());
161
                }
162
                return jLblProj;
163
        }
164
        public void addBtnChangeProjActionListener(java.awt.event.ActionListener al) {
165
                jBtnChangeProj.addActionListener(al);
166
        }
167

    
168
        /**
169
         * This method initializes jButton
170
         *
171
         * @return javax.swing.JButton
172
         */
173
        public JButton getJBtnChangeProj() {
174
                if (jBtnChangeProj == null) {
175
                        jBtnChangeProj = new JButton();                        
176
                        jBtnChangeProj.setText("..."); //$NON-NLS-1$
177
                        jBtnChangeProj.setPreferredSize(new Dimension(50, 23));
178
                }
179
                return jBtnChangeProj;
180
        }
181
        
182
        public void setTargetNad(boolean tarNad){
183
                targetNad = tarNad;
184
        }
185
        
186
        public boolean getTargetNad(){
187
                return targetNad;
188
        }
189
        
190
        /**
191
         * @return Returns the curProj.
192
         */
193
        public IProjection getCurProj() {
194
                return curProj;
195
        }
196
        /**
197
         * @param curProj The curProj to set.
198
         */
199
        public void setCurProj(IProjection curProj) {
200
                this.curProj = (ICrs) curProj;
201
        }
202
        /**
203
         * @return Returns the okPressed.
204
         */
205
        public boolean isOkPressed() {
206
                return okPressed;
207
        }
208
        /**
209
         * @param actionListener The actionListener to set.
210
         */
211
        public void addActionListener(ActionListener actionListener) {
212
                this.actionListener = actionListener;
213
        }
214
}  //  @jve:decl-index=0:visual-constraint="10,10"