root / trunk / extensions / extAddEventTheme / src / com / iver / gvsig / addeventtheme / gui / AddEventThemePanel.java @ 6877
History | View | Annotate | Download (11.7 KB)
1 | 3525 | caballero | /*
|
---|---|---|---|
2 | * Created on 09-nov-2005
|
||
3 | *
|
||
4 | 6759 | jjdelcerro | * gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
|
5 | 3525 | caballero | *
|
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 | 6759 | jjdelcerro | * Av. Blasco Ibez, 50
|
27 | 3525 | caballero | * 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 | 5932 | caballero | import java.sql.Types; |
47 | 3525 | caballero | import java.util.ArrayList; |
48 | |||
49 | 5908 | caballero | import javax.swing.DefaultComboBoxModel; |
50 | import javax.swing.JComboBox; |
||
51 | import javax.swing.JDialog; |
||
52 | import javax.swing.JLabel; |
||
53 | 3525 | caballero | import javax.swing.JPanel; |
54 | |||
55 | 5908 | caballero | import org.cresques.cts.IProjection; |
56 | 6225 | jmvivo | import org.gvsig.gui.beans.AcceptCancelPanel; |
57 | import org.gvsig.gui.beans.swing.JButton; |
||
58 | 5908 | caballero | |
59 | 3954 | fjp | import com.hardcode.driverManager.DriverLoadException; |
60 | 3525 | caballero | import com.hardcode.gdbms.engine.data.DataSource; |
61 | import com.iver.andami.PluginServices; |
||
62 | 3954 | fjp | import com.iver.andami.messages.NotificationManager; |
63 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
64 | 3525 | caballero | import com.iver.andami.ui.mdiManager.ViewInfo; |
65 | import com.iver.cit.gvsig.fmap.DriverException; |
||
66 | import com.iver.cit.gvsig.fmap.FMap; |
||
67 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
68 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
69 | 5113 | caballero | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
70 | 3525 | caballero | import com.iver.cit.gvsig.project.ProjectTable; |
71 | 5115 | caballero | import com.iver.gvsig.addeventtheme.AddEventThemListener; |
72 | 5377 | jmvivo | import com.iver.gvsig.addeventtheme.AddEventThemeDriver; |
73 | 3525 | caballero | |
74 | /**
|
||
75 | * The AddEventThemePanel class creates a JPanel where the
|
||
76 | * user can input the name of the gvSIG Table from that the
|
||
77 | * plugin will create the new point Layer, and the fields
|
||
78 | * corresponding with the point coordinates.
|
||
79 | 5113 | caballero | *
|
80 | 3525 | caballero | * @author jmorell
|
81 | */
|
||
82 | 6877 | cesar | public class AddEventThemePanel extends JPanel implements IWindow { |
83 | 3525 | caballero | private static final long serialVersionUID = 1L; |
84 | private ViewInfo viewInfo = null; |
||
85 | private JLabel tableLabel = null; |
||
86 | private JLabel xLabel = null; |
||
87 | private JLabel yLabel = null; |
||
88 | private JComboBox tableComboBox = null; |
||
89 | private JComboBox xComboBox = null; |
||
90 | private JComboBox yComboBox = null; |
||
91 | 6225 | jmvivo | //private JButton okButton = null;
|
92 | private AcceptCancelPanel acceptPanel = null; |
||
93 | 3525 | caballero | private FMap mapContext;
|
94 | private ArrayList tableList; |
||
95 | private String firstCoordinate; |
||
96 | private String secondCoordinate; |
||
97 | |||
98 | /**
|
||
99 | * This is the default constructor
|
||
100 | */
|
||
101 | public AddEventThemePanel(FMap mapContext, ArrayList tableList) { |
||
102 | super();
|
||
103 | this.mapContext = mapContext;
|
||
104 | this.tableList = tableList;
|
||
105 | initializeCoordinates(); |
||
106 | initialize(); |
||
107 | } |
||
108 | |||
109 | private void initializeCoordinates() { |
||
110 | IProjection proj = mapContext.getProjection(); |
||
111 | String projName = proj.getAbrev();
|
||
112 | if (projName.equals("EPSG:23030") || projName.equals("EPSG:27492") || projName.equals("EPSG:42101") || projName.equals("EPSG:42304")) { |
||
113 | firstCoordinate = "X";
|
||
114 | secondCoordinate = "Y";
|
||
115 | } else if (projName.equals("EPSG:4230") || projName.equals("EPSG:4326")) { |
||
116 | firstCoordinate = "Lon";
|
||
117 | secondCoordinate = "Lat";
|
||
118 | } else {
|
||
119 | 6759 | jjdelcerro | System.out.println("Proyeccin: " + projName); |
120 | System.out.println("Proyeccin no soportada."); |
||
121 | 3525 | caballero | } |
122 | } |
||
123 | |||
124 | /**
|
||
125 | * This method initializes this
|
||
126 | 5113 | caballero | *
|
127 | 3525 | caballero | * @return void
|
128 | */
|
||
129 | private void initialize() { |
||
130 | yLabel = new JLabel(); |
||
131 | 6225 | jmvivo | yLabel.setBounds(6, 68, 90, 23); |
132 | 3525 | caballero | yLabel.setText(secondCoordinate + ":");
|
133 | xLabel = new JLabel(); |
||
134 | 6225 | jmvivo | xLabel.setBounds(6, 37, 90, 23); |
135 | 3525 | caballero | xLabel.setText(firstCoordinate + ":");
|
136 | tableLabel = new JLabel(); |
||
137 | 6225 | jmvivo | tableLabel.setBounds(6, 6, 90, 23); |
138 | 3525 | caballero | tableLabel.setText(PluginServices.getText(this,"Tabla") + ":"); |
139 | this.setLayout(null); |
||
140 | 6225 | jmvivo | this.setSize(400, 135); |
141 | 3525 | caballero | this.add(tableLabel, null); |
142 | this.add(xLabel, null); |
||
143 | this.add(yLabel, null); |
||
144 | this.add(getTableComboBox(), null); |
||
145 | this.add(getXComboBox(), null); |
||
146 | this.add(getYComboBox(), null); |
||
147 | 6225 | jmvivo | this.add(getAcceptPanel(), null); |
148 | 3525 | caballero | } |
149 | |||
150 | private String[] getTableNames() { |
||
151 | String[] tableNames = new String[tableList.size()]; |
||
152 | for (int i=0;i<tableList.size();i++) { |
||
153 | tableNames[i] = ((ProjectTable)tableList.get(i)).getName(); |
||
154 | } |
||
155 | return tableNames;
|
||
156 | } |
||
157 | private String[] getFieldNames() { |
||
158 | String tableName = (String)tableComboBox.getSelectedItem(); |
||
159 | ProjectTable projectTable = getProjectTable(tableName); |
||
160 | DataSource ds;
|
||
161 | 5932 | caballero | ArrayList fieldName=new ArrayList(); |
162 | 3525 | caballero | try {
|
163 | 3954 | fjp | ds = projectTable.getModelo().getRecordset(); |
164 | 3525 | caballero | for (int i = 0; i < ds.getFieldCount(); i++) { |
165 | 6857 | fjp | // Podr?amos comprobar si es un campo num?rico pero entonces
|
166 | // no va con el driver de csv => moraleja: cuando
|
||
167 | // se cambia el driver de csv para que sepa de qu? campos
|
||
168 | // hablamos, se habilita esta l?nea.
|
||
169 | // if (ds.getFieldType(i)==Types.DOUBLE || ds.getFieldType(i)==Types.INTEGER || ds.getFieldType(i)==Types.VARCHAR)
|
||
170 | 5932 | caballero | fieldName.add(ds.getFieldName(i)); |
171 | 3525 | caballero | } |
172 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
173 | e.printStackTrace(); |
||
174 | 3954 | fjp | NotificationManager.addError(e); |
175 | } catch (DriverLoadException e) {
|
||
176 | e.printStackTrace(); |
||
177 | } |
||
178 | 5932 | caballero | return (String[])fieldName.toArray(new String[0]); |
179 | 3525 | caballero | } |
180 | 5113 | caballero | |
181 | 3525 | caballero | private ProjectTable getProjectTable(String tableName) { |
182 | ProjectTable projectTable = null;
|
||
183 | for (int i=0;i<tableList.size();i++) { |
||
184 | if (((ProjectTable)tableList.get(i)).getName().equals(tableName)) {
|
||
185 | projectTable = (ProjectTable)tableList.get(i); |
||
186 | break;
|
||
187 | } |
||
188 | } |
||
189 | return projectTable;
|
||
190 | } |
||
191 | 5113 | caballero | |
192 | 3525 | caballero | private void createNewLayerFromDataSource() { |
193 | String tableName = (String)tableComboBox.getSelectedItem(); |
||
194 | ProjectTable projectTable = getProjectTable(tableName); |
||
195 | try {
|
||
196 | 3954 | fjp | DataSource ds = projectTable.getModelo().getRecordset();
|
197 | int xFieldIndex = 0; |
||
198 | int yFieldIndex = 0; |
||
199 | 5113 | caballero | |
200 | 3525 | caballero | xFieldIndex = ds.getFieldIndexByName(getXFieldName()); |
201 | yFieldIndex = ds.getFieldIndexByName(getYFieldName()); |
||
202 | 3954 | fjp | AddEventThemeDriver addEventThemeDriver = new AddEventThemeDriver();
|
203 | addEventThemeDriver.setData(ds, xFieldIndex, yFieldIndex); |
||
204 | FLayer capa = null;
|
||
205 | try {
|
||
206 | capa = LayerFactory.createLayer(tableName, addEventThemeDriver, mapContext.getProjection()); |
||
207 | 5115 | caballero | |
208 | 3954 | fjp | } catch (DriverException e) {
|
209 | // TODO Auto-generated catch block
|
||
210 | e.printStackTrace(); |
||
211 | } |
||
212 | 5115 | caballero | capa.addLayerListener(new AddEventThemListener());
|
213 | 5113 | caballero | projectTable.setAssociatedTable((AlphanumericData)capa); |
214 | 3954 | fjp | mapContext.getLayers().addLayer(capa); |
215 | 3525 | caballero | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
216 | 3954 | fjp | NotificationManager.addError(e1); |
217 | } catch (DriverLoadException e) {
|
||
218 | NotificationManager.addError(e); |
||
219 | } |
||
220 | 5113 | caballero | |
221 | 3525 | caballero | } |
222 | 5113 | caballero | |
223 | 3525 | caballero | private String getXFieldName() { |
224 | return ((String)xComboBox.getSelectedItem()); |
||
225 | } |
||
226 | |||
227 | private String getYFieldName() { |
||
228 | return ((String)yComboBox.getSelectedItem()); |
||
229 | } |
||
230 | 5113 | caballero | |
231 | 3525 | caballero | /* (non-Javadoc)
|
232 | * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
||
233 | */
|
||
234 | public ViewInfo getViewInfo() {
|
||
235 | // TODO Auto-generated method stub
|
||
236 | if (viewInfo == null) { |
||
237 | viewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
238 | 5258 | jmvivo | viewInfo.setTitle(PluginServices.getText(this,"Anadir_capa_de_eventos")); |
239 | 3525 | caballero | } |
240 | return viewInfo;
|
||
241 | } |
||
242 | |||
243 | /**
|
||
244 | 5113 | caballero | * This method initializes tableComboBox
|
245 | *
|
||
246 | * @return javax.swing.JComboBox
|
||
247 | */
|
||
248 | 3525 | caballero | private JComboBox getTableComboBox() { |
249 | if (tableComboBox == null) { |
||
250 | tableComboBox = new JComboBox(); |
||
251 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getTableNames()); |
||
252 | tableComboBox.setModel(defaultModel); |
||
253 | 6225 | jmvivo | tableComboBox.setBounds(92, 6, 290, 23); |
254 | 5113 | caballero | tableComboBox.addItemListener(new java.awt.event.ItemListener() {
|
255 | public void itemStateChanged(java.awt.event.ItemEvent e) { |
||
256 | 3525 | caballero | System.out.println("itemStateChanged()"); // TODO Auto-generated Event stub itemStateChanged() |
257 | // Cambiar el estado del xComboBox
|
||
258 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
259 | xComboBox.setModel(defaultModel); |
||
260 | // Cambiar el estado del yComboBox
|
||
261 | defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
262 | yComboBox.setModel(defaultModel); |
||
263 | } |
||
264 | }); |
||
265 | } |
||
266 | return tableComboBox;
|
||
267 | } |
||
268 | |||
269 | /**
|
||
270 | 5113 | caballero | * This method initializes xComboBox
|
271 | *
|
||
272 | * @return javax.swing.JComboBox
|
||
273 | */
|
||
274 | 3525 | caballero | private JComboBox getXComboBox() { |
275 | if (xComboBox == null) { |
||
276 | xComboBox = new JComboBox(); |
||
277 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
278 | xComboBox.setModel(defaultModel); |
||
279 | 6225 | jmvivo | xComboBox.setBounds(92, 37, 290, 23); |
280 | 3525 | caballero | } |
281 | return xComboBox;
|
||
282 | } |
||
283 | |||
284 | /**
|
||
285 | 5113 | caballero | * This method initializes yComboBox
|
286 | *
|
||
287 | * @return javax.swing.JComboBox
|
||
288 | */
|
||
289 | 3525 | caballero | private JComboBox getYComboBox() { |
290 | if (yComboBox == null) { |
||
291 | yComboBox = new JComboBox(); |
||
292 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
||
293 | yComboBox.setModel(defaultModel); |
||
294 | 6225 | jmvivo | yComboBox.setBounds(92, 68, 290, 23); |
295 | 3525 | caballero | } |
296 | return yComboBox;
|
||
297 | } |
||
298 | |||
299 | /**
|
||
300 | 5113 | caballero | * This method initializes okButton
|
301 | *
|
||
302 | * @return javax.swing.JButton
|
||
303 | */
|
||
304 | 6225 | jmvivo | private AcceptCancelPanel getAcceptPanel() {
|
305 | if (acceptPanel == null) { |
||
306 | acceptPanel = new AcceptCancelPanel(
|
||
307 | new java.awt.event.ActionListener() {
|
||
308 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
309 | System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
||
310 | createNewLayerFromDataSource(); |
||
311 | // y sale.
|
||
312 | if (PluginServices.getMainFrame() == null) |
||
313 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
314 | else
|
||
315 | PluginServices.getMDIManager().closeView(AddEventThemePanel.this); |
||
316 | } |
||
317 | }, |
||
318 | new java.awt.event.ActionListener() {
|
||
319 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
320 | if (PluginServices.getMainFrame() == null) |
||
321 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
322 | else
|
||
323 | PluginServices.getMDIManager().closeView(AddEventThemePanel.this); |
||
324 | } |
||
325 | } |
||
326 | ); |
||
327 | acceptPanel.setBounds(0, 100, getWidth()-6, 30); |
||
328 | 3525 | caballero | } |
329 | 6225 | jmvivo | return acceptPanel;
|
330 | 3525 | caballero | } |
331 | } // @jve:decl-index=0:visual-constraint="10,10" |