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