root / trunk / extensions / extAddEventTheme / src / com / iver / gvsig / addeventtheme / gui / AddEventThemePanel.java @ 3525
History | View | Annotate | Download (10.3 KB)
1 | 3525 | caballero | /*
|
---|---|---|---|
2 | * Created on 09-nov-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.gvsig.addeventtheme.gui; |
||
45 | |||
46 | import java.util.ArrayList; |
||
47 | |||
48 | import javax.swing.JPanel; |
||
49 | |||
50 | import com.hardcode.gdbms.engine.data.DataSource; |
||
51 | import com.iver.andami.PluginServices; |
||
52 | import com.iver.andami.ui.mdiManager.View; |
||
53 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
54 | import com.iver.cit.gvsig.fmap.DriverException; |
||
55 | import com.iver.cit.gvsig.fmap.FMap; |
||
56 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
57 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
58 | import com.iver.cit.gvsig.project.ProjectTable; |
||
59 | import com.iver.gvsig.addeventtheme.AddEventThemeDriver; |
||
60 | |||
61 | import javax.swing.DefaultComboBoxModel; |
||
62 | import javax.swing.JDialog; |
||
63 | import javax.swing.JLabel; |
||
64 | import javax.swing.JComboBox; |
||
65 | import javax.swing.JButton; |
||
66 | |||
67 | import org.cresques.cts.IProjection; |
||
68 | |||
69 | /**
|
||
70 | * The AddEventThemePanel class creates a JPanel where the
|
||
71 | * user can input the name of the gvSIG Table from that the
|
||
72 | * plugin will create the new point Layer, and the fields
|
||
73 | * corresponding with the point coordinates.
|
||
74 | *
|
||
75 | * @author jmorell
|
||
76 | */
|
||
77 | public class AddEventThemePanel extends JPanel implements View { |
||
78 | private static final long serialVersionUID = 1L; |
||
79 | private ViewInfo viewInfo = null; |
||
80 | private JLabel tableLabel = null; |
||
81 | private JLabel xLabel = null; |
||
82 | private JLabel yLabel = null; |
||
83 | private JComboBox tableComboBox = null; |
||
84 | private JComboBox xComboBox = null; |
||
85 | private JComboBox yComboBox = null; |
||
86 | private JButton okButton = null; |
||
87 | private FMap mapContext;
|
||
88 | private ArrayList tableList; |
||
89 | private String firstCoordinate; |
||
90 | private String secondCoordinate; |
||
91 | |||
92 | /**
|
||
93 | * This is the default constructor
|
||
94 | */
|
||
95 | public AddEventThemePanel(FMap mapContext, ArrayList tableList) { |
||
96 | super();
|
||
97 | this.mapContext = mapContext;
|
||
98 | this.tableList = tableList;
|
||
99 | initializeCoordinates(); |
||
100 | initialize(); |
||
101 | } |
||
102 | |||
103 | private void initializeCoordinates() { |
||
104 | IProjection proj = mapContext.getProjection(); |
||
105 | String projName = proj.getAbrev();
|
||
106 | if (projName.equals("EPSG:23030") || projName.equals("EPSG:27492") || projName.equals("EPSG:42101") || projName.equals("EPSG:42304")) { |
||
107 | firstCoordinate = "X";
|
||
108 | secondCoordinate = "Y";
|
||
109 | } else if (projName.equals("EPSG:4230") || projName.equals("EPSG:4326")) { |
||
110 | firstCoordinate = "Lon";
|
||
111 | secondCoordinate = "Lat";
|
||
112 | } else {
|
||
113 | System.out.println("Proyecci?n: " + projName); |
||
114 | System.out.println("Proyecci?n no soportada."); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | /**
|
||
119 | * This method initializes this
|
||
120 | *
|
||
121 | * @return void
|
||
122 | */
|
||
123 | private void initialize() { |
||
124 | yLabel = new JLabel(); |
||
125 | yLabel.setBounds(6, 68, 36, 24); |
||
126 | yLabel.setText(secondCoordinate + ":");
|
||
127 | xLabel = new JLabel(); |
||
128 | xLabel.setBounds(6, 37, 36, 24); |
||
129 | xLabel.setText(firstCoordinate + ":");
|
||
130 | tableLabel = new JLabel(); |
||
131 | tableLabel.setBounds(6, 6, 36, 24); |
||
132 | tableLabel.setText(PluginServices.getText(this,"Tabla") + ":"); |
||
133 | this.setLayout(null); |
||
134 | this.setSize(221, 131); |
||
135 | this.add(tableLabel, null); |
||
136 | this.add(xLabel, null); |
||
137 | this.add(yLabel, null); |
||
138 | this.add(getTableComboBox(), null); |
||
139 | this.add(getXComboBox(), null); |
||
140 | this.add(getYComboBox(), null); |
||
141 | this.add(getOkButton(), null); |
||
142 | } |
||
143 | |||
144 | private String[] getTableNames() { |
||
145 | String[] tableNames = new String[tableList.size()]; |
||
146 | for (int i=0;i<tableList.size();i++) { |
||
147 | tableNames[i] = ((ProjectTable)tableList.get(i)).getName(); |
||
148 | } |
||
149 | return tableNames;
|
||
150 | } |
||
151 | private String[] getFieldNames() { |
||
152 | String tableName = (String)tableComboBox.getSelectedItem(); |
||
153 | ProjectTable projectTable = getProjectTable(tableName); |
||
154 | DataSource ds;
|
||
155 | String[] fieldNames = null; |
||
156 | try {
|
||
157 | ds = projectTable.getModelo(); |
||
158 | fieldNames = new String[ds.getFieldCount()]; |
||
159 | for (int i = 0; i < ds.getFieldCount(); i++) { |
||
160 | fieldNames[i] = ds.getFieldName(i); |
||
161 | } |
||
162 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
163 | // TODO Auto-generated catch block
|
||
164 | e.printStackTrace(); |
||
165 | } |
||
166 | return fieldNames;
|
||
167 | } |
||
168 | |||
169 | private ProjectTable getProjectTable(String tableName) { |
||
170 | ProjectTable projectTable = null;
|
||
171 | for (int i=0;i<tableList.size();i++) { |
||
172 | if (((ProjectTable)tableList.get(i)).getName().equals(tableName)) {
|
||
173 | projectTable = (ProjectTable)tableList.get(i); |
||
174 | break;
|
||
175 | } |
||
176 | } |
||
177 | return projectTable;
|
||
178 | } |
||
179 | |||
180 | private void createNewLayerFromDataSource() { |
||
181 | String tableName = (String)tableComboBox.getSelectedItem(); |
||
182 | ProjectTable projectTable = getProjectTable(tableName); |
||
183 | DataSource ds = projectTable.getModelo();
|
||
184 | int xFieldIndex = 0; |
||
185 | int yFieldIndex = 0; |
||
186 | try {
|
||
187 | xFieldIndex = ds.getFieldIndexByName(getXFieldName()); |
||
188 | yFieldIndex = ds.getFieldIndexByName(getYFieldName()); |
||
189 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
||
190 | // TODO Auto-generated catch block
|
||
191 | e1.printStackTrace(); |
||
192 | } |
||
193 | AddEventThemeDriver addEventThemeDriver = new AddEventThemeDriver();
|
||
194 | addEventThemeDriver.setData(ds, xFieldIndex, yFieldIndex); |
||
195 | FLayer capa = null;
|
||
196 | try {
|
||
197 | capa = LayerFactory.createLayer(tableName, addEventThemeDriver, mapContext.getProjection()); |
||
198 | } catch (DriverException e) {
|
||
199 | // TODO Auto-generated catch block
|
||
200 | e.printStackTrace(); |
||
201 | } |
||
202 | mapContext.getLayers().addLayer(capa); |
||
203 | } |
||
204 | |||
205 | private String getXFieldName() { |
||
206 | return ((String)xComboBox.getSelectedItem()); |
||
207 | } |
||
208 | |||
209 | private String getYFieldName() { |
||
210 | return ((String)yComboBox.getSelectedItem()); |
||
211 | } |
||
212 | |||
213 | /* (non-Javadoc)
|
||
214 | * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
||
215 | */
|
||
216 | public ViewInfo getViewInfo() {
|
||
217 | // TODO Auto-generated method stub
|
||
218 | if (viewInfo == null) { |
||
219 | viewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
220 | viewInfo.setTitle(PluginServices.getText(this,"Anadir_tema_de_eventos")); |
||
221 | } |
||
222 | return viewInfo;
|
||
223 | } |
||
224 | |||
225 | /**
|
||
226 | * This method initializes tableComboBox
|
||
227 | *
|
||
228 | * @return javax.swing.JComboBox
|
||
229 | */
|
||
230 | private JComboBox getTableComboBox() { |
||
231 | if (tableComboBox == null) { |
||
232 | tableComboBox = new JComboBox(); |
||
233 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getTableNames()); |
||
234 | tableComboBox.setModel(defaultModel); |
||
235 | tableComboBox.setBounds(43, 6, 161, 24); |
||
236 | tableComboBox.addItemListener(new java.awt.event.ItemListener() {
|
||
237 | public void itemStateChanged(java.awt.event.ItemEvent e) { |
||
238 | System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged() |
||
239 | // Cambiar el estado del xComboBox
|
||
240 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
241 | xComboBox.setModel(defaultModel); |
||
242 | // Cambiar el estado del yComboBox
|
||
243 | defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
244 | yComboBox.setModel(defaultModel); |
||
245 | } |
||
246 | }); |
||
247 | } |
||
248 | return tableComboBox;
|
||
249 | } |
||
250 | |||
251 | /**
|
||
252 | * This method initializes xComboBox
|
||
253 | *
|
||
254 | * @return javax.swing.JComboBox
|
||
255 | */
|
||
256 | private JComboBox getXComboBox() { |
||
257 | if (xComboBox == null) { |
||
258 | xComboBox = new JComboBox(); |
||
259 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
260 | xComboBox.setModel(defaultModel); |
||
261 | xComboBox.setBounds(43, 37, 161, 24); |
||
262 | } |
||
263 | return xComboBox;
|
||
264 | } |
||
265 | |||
266 | /**
|
||
267 | * This method initializes yComboBox
|
||
268 | *
|
||
269 | * @return javax.swing.JComboBox
|
||
270 | */
|
||
271 | private JComboBox getYComboBox() { |
||
272 | if (yComboBox == null) { |
||
273 | yComboBox = new JComboBox(); |
||
274 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
275 | yComboBox.setModel(defaultModel); |
||
276 | yComboBox.setBounds(43, 68, 161, 24); |
||
277 | } |
||
278 | return yComboBox;
|
||
279 | } |
||
280 | |||
281 | /**
|
||
282 | * This method initializes okButton
|
||
283 | *
|
||
284 | * @return javax.swing.JButton
|
||
285 | */
|
||
286 | private JButton getOkButton() { |
||
287 | if (okButton == null) { |
||
288 | okButton = new JButton(); |
||
289 | okButton.setBounds(104, 100, 100, 24); |
||
290 | okButton.addActionListener(new java.awt.event.ActionListener() {
|
||
291 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
292 | System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
||
293 | createNewLayerFromDataSource(); |
||
294 | // y sale.
|
||
295 | if (PluginServices.getMainFrame() == null) |
||
296 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
297 | else
|
||
298 | PluginServices.getMDIManager().closeView(AddEventThemePanel.this); |
||
299 | } |
||
300 | }); |
||
301 | okButton.setText(PluginServices.getText(this,"Aceptar")); |
||
302 | } |
||
303 | return okButton;
|
||
304 | } |
||
305 | } // @jve:decl-index=0:visual-constraint="10,10" |