root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / ProjChooserPanel.java @ 7570
History | View | Annotate | Download (4.39 KB)
1 | 7570 | jlgomez | /*
|
---|---|---|---|
2 | * Created on 30-ene-2005
|
||
3 | */
|
||
4 | package org.gvsig.crs.gui.panels; |
||
5 | |||
6 | import java.awt.FlowLayout; |
||
7 | import java.awt.GridLayout; |
||
8 | import java.awt.event.ActionListener; |
||
9 | import java.sql.Connection; |
||
10 | import java.sql.DriverManager; |
||
11 | import java.sql.SQLException; |
||
12 | |||
13 | import javax.swing.JLabel; |
||
14 | import javax.swing.JPanel; |
||
15 | |||
16 | import org.cresques.cts.IProjection; |
||
17 | import org.gvsig.crs.EpsgConnection; |
||
18 | import org.gvsig.crs.ICrs; |
||
19 | import org.gvsig.gui.beans.swing.JButton; |
||
20 | |||
21 | import com.iver.andami.PluginServices; |
||
22 | import com.iver.cit.gvsig.gui.FOpenDialog; |
||
23 | import com.iver.cit.gvsig.gui.View; |
||
24 | import com.iver.cit.gvsig.gui.dialogs.CSSelectionDialog; |
||
25 | |||
26 | /**
|
||
27 | * @author Luis W. Sevilla (sevilla_lui@gva.es)
|
||
28 | */
|
||
29 | public class ProjChooserPanel extends JPanel { |
||
30 | |||
31 | private static final long serialVersionUID = 1L; |
||
32 | |||
33 | private static IProjection curProj = null; //(IProjection) new CRSFactory().getCRS("EPSG:23030"); |
||
34 | private JLabel jLblProj = null; |
||
35 | private JLabel jLblProjName = null; |
||
36 | private JButton jBtnChangeProj = null; |
||
37 | private static boolean okPressed = false; |
||
38 | private String abrev; |
||
39 | |||
40 | public EpsgConnection connect = null; |
||
41 | |||
42 | private ActionListener actionListener = null; |
||
43 | |||
44 | public ProjChooserPanel(IProjection proj) {
|
||
45 | super();
|
||
46 | setCurProj(proj); |
||
47 | initialize(); |
||
48 | } |
||
49 | |||
50 | public ProjChooserPanel(){
|
||
51 | connect = new EpsgConnection();
|
||
52 | connect.setConnection(); |
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * This method initializes this
|
||
57 | *
|
||
58 | * @return void
|
||
59 | */
|
||
60 | private void initialize() { |
||
61 | this.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 0)); |
||
62 | setPreferredSize(new java.awt.Dimension(330,35)); |
||
63 | this.setSize(new java.awt.Dimension(330,23)); |
||
64 | this.add(getJLblProjName(), null); |
||
65 | this.add(getJLblProj(), null); |
||
66 | this.add(getJBtnChangeProj(), null); |
||
67 | //cambiar cuando la parte de JLuis se ensamble
|
||
68 | if(!((ICrs)curProj).getAbrev().equals("EPSG:23030")) |
||
69 | jLblProj.setText(((ICrs)curProj).getCrsWkt().getName()); |
||
70 | else
|
||
71 | jLblProj.setText("EPSG:23030");
|
||
72 | initBtnChangeProj(); |
||
73 | } |
||
74 | |||
75 | private void initBtnChangeProj() { |
||
76 | getJBtnChangeProj().addActionListener(new java.awt.event.ActionListener() {
|
||
77 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
78 | okPressed = false;
|
||
79 | CSSelectionDialog csSelect = new CSSelectionDialog();
|
||
80 | csSelect.setProjection(curProj); |
||
81 | |||
82 | csSelect.setLayout(new GridLayout(0,1)); |
||
83 | |||
84 | PluginServices.getMDIManager().addWindow(csSelect); |
||
85 | if(View.m_MapControl == null) |
||
86 | abrev = curProj.getAbrev(); |
||
87 | else
|
||
88 | abrev = View.m_MapControl.getProjection().getAbrev();
|
||
89 | |||
90 | if (csSelect.isOkPressed()) {
|
||
91 | curProj = csSelect.getProjection(); |
||
92 | if(View.m_MapControl == null) |
||
93 | abrev = csSelect.getProjectionAbrev(); |
||
94 | else
|
||
95 | abrev = View.m_MapControl.getProjection().getAbrev();
|
||
96 | jLblProj.setText(curProj.getAbrev()); |
||
97 | FOpenDialog.setLastProjection(curProj); |
||
98 | okPressed = true;
|
||
99 | if (actionListener != null) { |
||
100 | actionListener.actionPerformed(e); |
||
101 | } |
||
102 | }else
|
||
103 | |||
104 | jLblProj.setText(abrev); |
||
105 | } |
||
106 | }); |
||
107 | } |
||
108 | |||
109 | public JLabel getJLblProjName() { |
||
110 | if (jLblProjName == null) { |
||
111 | jLblProjName = new JLabel("Proyeccion actual"); |
||
112 | jLblProjName.setText(PluginServices.getText(this,"__proyeccion_actual")); //$NON-NLS-1$ |
||
113 | } |
||
114 | return jLblProjName;
|
||
115 | } |
||
116 | |||
117 | public JLabel getJLblProj() { |
||
118 | if (jLblProj == null) { |
||
119 | jLblProj = new JLabel(); |
||
120 | jLblProj.setText(curProj.getAbrev()); |
||
121 | } |
||
122 | return jLblProj;
|
||
123 | } |
||
124 | public void addBtnChangeProjActionListener(java.awt.event.ActionListener al) { |
||
125 | jBtnChangeProj.addActionListener(al); |
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * This method initializes jButton
|
||
130 | *
|
||
131 | * @return javax.swing.JButton
|
||
132 | */
|
||
133 | public JButton getJBtnChangeProj() { |
||
134 | if (jBtnChangeProj == null) { |
||
135 | jBtnChangeProj = new JButton(); |
||
136 | jBtnChangeProj.setText("..."); //$NON-NLS-1$ |
||
137 | } |
||
138 | return jBtnChangeProj;
|
||
139 | } |
||
140 | /**
|
||
141 | * @return Returns the curProj.
|
||
142 | */
|
||
143 | public static IProjection getCurProj() { |
||
144 | return curProj;
|
||
145 | } |
||
146 | /**
|
||
147 | * @param curProj The curProj to set.
|
||
148 | */
|
||
149 | public void setCurProj(IProjection curProj) { |
||
150 | this.curProj = curProj;
|
||
151 | } |
||
152 | /**
|
||
153 | * @return Returns the okPressed.
|
||
154 | */
|
||
155 | public static boolean isOkPressed() { |
||
156 | return okPressed;
|
||
157 | } |
||
158 | /**
|
||
159 | * @param actionListener The actionListener to set.
|
||
160 | */
|
||
161 | public void addActionListener(ActionListener actionListener) { |
||
162 | this.actionListener = actionListener;
|
||
163 | } |
||
164 | } // @jve:decl-index=0:visual-constraint="10,10" |