root / trunk / extensions / extSymbology / src / com / iver / cit / gvsig / project / documents / view / legend / gui / VectorFilterExpression.java @ 29131
History | View | Annotate | Download (15.7 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
import java.io.File; |
48 |
import java.io.IOException; |
49 |
import java.util.ArrayList; |
50 |
|
51 |
import javax.swing.BoxLayout; |
52 |
import javax.swing.ImageIcon; |
53 |
import javax.swing.JCheckBox; |
54 |
import javax.swing.JOptionPane; |
55 |
import javax.swing.JPanel; |
56 |
|
57 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
58 |
import org.gvsig.gui.beans.swing.JBlank; |
59 |
import org.gvsig.gui.beans.swing.JButton; |
60 |
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend; |
61 |
import org.gvsig.symbology.fmap.symbols.PictureFillSymbol; |
62 |
|
63 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.andami.messages.NotificationManager; |
66 |
import com.iver.andami.ui.mdiManager.IWindow; |
67 |
import com.iver.cit.gvsig.fmap.core.FShape; |
68 |
import com.iver.cit.gvsig.fmap.core.styles.IMarkerFillPropertiesStyle; |
69 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
72 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
73 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
74 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
75 |
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue; |
76 |
import com.iver.utiles.swing.JComboBox; |
77 |
|
78 |
/**
|
79 |
* Implements the JPanel that shows the properties of a VectorialFilterExpressionLegend
|
80 |
* in order to allows the user to modify its characteristics
|
81 |
*
|
82 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
|
83 |
*
|
84 |
*/
|
85 |
public class VectorFilterExpression extends JPanel implements ILegendPanel,ActionListener { |
86 |
private static final long serialVersionUID = -7187473609965942511L; |
87 |
private VectorFilterExpressionLegend theLegend;
|
88 |
VectorFilterExpressionLegend auxLegend; |
89 |
private ClassifiableVectorial layer;
|
90 |
private PictureFillSymbol previewSymbol;
|
91 |
private JPanel pnlCenter; |
92 |
private JPanel pnlMovBut; |
93 |
private SymbolTable symbolTable;
|
94 |
private JButton btnAddExpression; |
95 |
private JButton btnModExpression; |
96 |
private JButton btnRemoveExpression; |
97 |
private JButton moveUp; |
98 |
private JButton moveDown; |
99 |
private int shapeType; |
100 |
protected JCheckBox chkdefaultvalues = null; |
101 |
protected JSymbolPreviewButton defaultSymbolPrev;
|
102 |
private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel(); |
103 |
|
104 |
/**
|
105 |
* This is the default constructor
|
106 |
*/
|
107 |
public VectorFilterExpression() {
|
108 |
super();
|
109 |
initialize(); |
110 |
} |
111 |
|
112 |
|
113 |
/**
|
114 |
* This method initializes this
|
115 |
*/
|
116 |
private void initialize() { |
117 |
|
118 |
pnlCenter = new JPanel(); |
119 |
pnlCenter.setLayout(new BorderLayout()); |
120 |
|
121 |
JPanel pnlButtons = new JPanel(); |
122 |
btnAddExpression = new JButton(PluginServices.getText(this, "new_filter_expression")); |
123 |
btnAddExpression.setActionCommand("NEW_EXPRESSION");
|
124 |
btnAddExpression.addActionListener(this);
|
125 |
pnlButtons.add(btnAddExpression); |
126 |
|
127 |
btnModExpression = new JButton(PluginServices.getText(this, "modify_filter_expression")); |
128 |
btnModExpression.setActionCommand("MODIFY_EXPRESSION");
|
129 |
btnModExpression.addActionListener(this);
|
130 |
pnlButtons.add(btnModExpression); |
131 |
|
132 |
btnRemoveExpression = new JButton(PluginServices.getText(this, "delete_filter_expression")); |
133 |
btnRemoveExpression.setActionCommand("REMOVE");
|
134 |
btnRemoveExpression.addActionListener(this);
|
135 |
pnlButtons.add(btnRemoveExpression); |
136 |
defaultSymbolPanel.add(getChkDefaultvalues()); |
137 |
pnlCenter.add(defaultSymbolPanel,BorderLayout.NORTH);
|
138 |
|
139 |
this.setLayout(new BorderLayout()); |
140 |
this.add(pnlCenter, BorderLayout.CENTER); |
141 |
this.add(pnlButtons, BorderLayout.SOUTH); |
142 |
|
143 |
|
144 |
} |
145 |
public void getDefaultSymbolPrev(int shapeType) { |
146 |
if(defaultSymbolPrev == null){ |
147 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
|
148 |
defaultSymbolPrev.setPreferredSize(new Dimension(110,20)); |
149 |
defaultSymbolPanel.add(defaultSymbolPrev,null);
|
150 |
} |
151 |
} |
152 |
|
153 |
public String getDescription() { |
154 |
return PluginServices.getText(this,"shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + "."; |
155 |
} |
156 |
|
157 |
public ISymbol getIconSymbol() {
|
158 |
if (previewSymbol == null) { |
159 |
try {
|
160 |
previewSymbol = new PictureFillSymbol();
|
161 |
previewSymbol.setImage( new File( |
162 |
this.getClass().getClassLoader().
|
163 |
getResource("images/ValoresUnicos.png").
|
164 |
getFile()).toURL()); |
165 |
previewSymbol.getMarkerFillProperties(). |
166 |
setFillStyle( |
167 |
IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL); |
168 |
} catch (IOException e) { |
169 |
return null; |
170 |
} |
171 |
} |
172 |
return previewSymbol;
|
173 |
} |
174 |
|
175 |
public ILegend getLegend() {
|
176 |
auxLegend.clear(); |
177 |
fillSymbolListFromTable(); |
178 |
|
179 |
try {
|
180 |
theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend(); |
181 |
|
182 |
} catch (XMLException e) {
|
183 |
e.printStackTrace(); |
184 |
} |
185 |
if(defaultSymbolPrev.getSymbol() != null) |
186 |
theLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol()); |
187 |
|
188 |
theLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
189 |
return theLegend;
|
190 |
} |
191 |
/**
|
192 |
* Fills the list of symbols of the legend
|
193 |
*
|
194 |
*/
|
195 |
private void fillSymbolListFromTable() { |
196 |
Object clave;
|
197 |
ISymbol theSymbol; |
198 |
boolean bRestoValores = false; |
199 |
int hasta;
|
200 |
|
201 |
FLyrVect m = (FLyrVect) layer; |
202 |
try {
|
203 |
|
204 |
if(auxLegend.getClassifyingFieldNames() != null) { |
205 |
String[] fNames= auxLegend.getClassifyingFieldNames(); |
206 |
int[] fieldTypes = new int[auxLegend.getClassifyingFieldNames().length]; |
207 |
|
208 |
for (int i = 0; i < auxLegend.getClassifyingFieldNames().length; i++) { |
209 |
int fieldIndex = m.getSource().getRecordset().getFieldIndexByName(fNames[i]);
|
210 |
fieldTypes[i]= m.getSource().getRecordset().getFieldType(fieldIndex); |
211 |
} |
212 |
|
213 |
auxLegend.setClassifyingFieldTypes(fieldTypes); |
214 |
} |
215 |
} catch (ReadDriverException e) {
|
216 |
NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e); |
217 |
} |
218 |
|
219 |
auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
220 |
if (bRestoValores) {
|
221 |
hasta = symbolTable.getRowCount() - 1;
|
222 |
} else {
|
223 |
hasta = symbolTable.getRowCount(); |
224 |
} |
225 |
|
226 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
227 |
clave = symbolTable.getFieldValue(row, 1);
|
228 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
229 |
theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2)); |
230 |
auxLegend.addSymbol(clave, theSymbol); |
231 |
} |
232 |
if(chkdefaultvalues.isSelected()){
|
233 |
if(defaultSymbolPrev.getSymbol() != null){ |
234 |
String description = PluginServices.getText(this,"default"); |
235 |
defaultSymbolPrev.getSymbol().setDescription(description); |
236 |
auxLegend.addSymbol(new NullIntervalValue(), defaultSymbolPrev.getSymbol());
|
237 |
} |
238 |
} |
239 |
|
240 |
} |
241 |
|
242 |
public Class getLegendClass() { |
243 |
return VectorFilterExpressionLegend.class;
|
244 |
} |
245 |
|
246 |
public JPanel getPanel() { |
247 |
return this; |
248 |
} |
249 |
|
250 |
public Class getParentClass() { |
251 |
return Categories.class;
|
252 |
} |
253 |
|
254 |
public String getTitle() { |
255 |
return PluginServices.getText(this,"expressions"); |
256 |
} |
257 |
|
258 |
public boolean isSuitableFor(FLayer layer) { |
259 |
|
260 |
FLyrVect lVect = (FLyrVect) layer; |
261 |
try {
|
262 |
return (lVect.getShapeType()%FShape.Z) != FShape.MULTI;
|
263 |
} catch (ReadDriverException e) {
|
264 |
return false; |
265 |
} |
266 |
|
267 |
} |
268 |
|
269 |
public void setData(FLayer lyr, ILegend legend) { |
270 |
this.layer = (ClassifiableVectorial) lyr;
|
271 |
shapeType = 0;
|
272 |
|
273 |
try {
|
274 |
shapeType = this.layer.getShapeType();
|
275 |
} catch (ReadDriverException e) {
|
276 |
NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e); |
277 |
} |
278 |
|
279 |
if (symbolTable != null) |
280 |
pnlCenter.remove(symbolTable); |
281 |
if (pnlMovBut != null) |
282 |
pnlCenter.remove(pnlMovBut); |
283 |
|
284 |
getDefaultSymbolPrev(shapeType); |
285 |
|
286 |
symbolTable = new SymbolTable(this, "expressions", shapeType); |
287 |
pnlCenter.add(symbolTable, BorderLayout.CENTER);
|
288 |
pnlCenter.add(getPnlMovBut(),BorderLayout.EAST);
|
289 |
|
290 |
|
291 |
if (legend instanceof VectorFilterExpressionLegend) { |
292 |
try {
|
293 |
auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend(); |
294 |
} catch (XMLException e) {
|
295 |
// TODO Auto-generated catch block
|
296 |
e.printStackTrace(); |
297 |
} |
298 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
299 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
300 |
} else {
|
301 |
auxLegend = new VectorFilterExpressionLegend();
|
302 |
auxLegend.setShapeType(shapeType); |
303 |
} |
304 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
305 |
} |
306 |
|
307 |
private JPanel getPnlMovBut() { |
308 |
if(pnlMovBut == null){ |
309 |
pnlMovBut = new JPanel(); |
310 |
pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS)); |
311 |
pnlMovBut.add(new JBlank(1, 70)); |
312 |
pnlMovBut.add(moveUp = new JButton(PluginServices.getIconTheme().get("up-arrow"))); |
313 |
moveUp.setSize(new Dimension(15,15)); |
314 |
pnlMovBut.add(new JBlank(1,10)); |
315 |
pnlMovBut.add(moveDown = new JButton(PluginServices.getIconTheme().get("down-arrow"))); |
316 |
pnlMovBut.add(new JBlank(1, 70)); |
317 |
moveDown.setActionCommand("MOVE-DOWN");
|
318 |
moveUp.setActionCommand("MOVE-UP");
|
319 |
moveDown.addActionListener(this);
|
320 |
moveUp.addActionListener(this);
|
321 |
} |
322 |
return pnlMovBut;
|
323 |
} |
324 |
|
325 |
public void actionPerformed(ActionEvent e) { |
326 |
int[] indices = null; |
327 |
|
328 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
329 |
indices = symbolTable.getSelectedRows(); |
330 |
} |
331 |
|
332 |
if(e.getActionCommand() == "MOVE-UP"){ |
333 |
if (indices.length>0) { |
334 |
int classIndex = indices[0]; |
335 |
int targetPos = Math.max(0, classIndex-1); |
336 |
symbolTable.moveUpRows(classIndex, targetPos,indices.length); |
337 |
} |
338 |
} |
339 |
|
340 |
if(e.getActionCommand() == "MOVE-DOWN"){ |
341 |
if (indices.length>0) { |
342 |
int classIndex = indices[indices.length-1]; |
343 |
int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1); |
344 |
symbolTable.moveDownRows(classIndex, targetPos,indices.length); |
345 |
} |
346 |
} |
347 |
|
348 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
349 |
ArrayList orders = new ArrayList(); |
350 |
|
351 |
for (int i = 0; i < symbolTable.getRowCount(); i++) { |
352 |
orders.add(symbolTable.getFieldValue(i,1).toString());
|
353 |
} |
354 |
} |
355 |
if (e.getActionCommand() == "NEW_EXPRESSION") { |
356 |
ExpressionCreator newExpression = new ExpressionCreator((FLyrVect) this.layer ); |
357 |
PluginServices.getMDIManager().addWindow((IWindow) newExpression); |
358 |
String expression = ((ExpressionCreator) newExpression).getExpression();
|
359 |
if(newExpression.getFieldNamesExpression() != null) |
360 |
addClassFieldNames(newExpression.getFieldNamesExpression()); |
361 |
|
362 |
if(expression != null) |
363 |
if(expression.compareTo("") != 0) { |
364 |
auxLegend.addSymbol(expression, newExpression.getSymbolForExpression()); |
365 |
symbolTable.removeAllItems(); |
366 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
367 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
368 |
} |
369 |
repaint(); |
370 |
} |
371 |
else if (e.getActionCommand() == "MODIFY_EXPRESSION") { |
372 |
|
373 |
if(symbolTable.getSelectedRowElements() == null) { |
374 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "select_one_row")+".\n"); |
375 |
} |
376 |
|
377 |
else {
|
378 |
ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0];
|
379 |
String expression = (String) symbolTable.getSelectedRowElements()[1]; |
380 |
String myDesc = (String) symbolTable.getSelectedRowElements()[2]; |
381 |
|
382 |
ExpressionCreator newExpression = new ExpressionCreator((FLyrVect) this.layer ); |
383 |
newExpression.setExpression(expression); |
384 |
newExpression.setDescriptionForExpression(myDesc); |
385 |
newExpression.setSymbolForExpression(mySymbol); |
386 |
PluginServices.getMDIManager().addWindow((IWindow) newExpression); |
387 |
|
388 |
if(expression != null) |
389 |
if(expression.compareTo("") != 0 && newExpression.getExpression()!=null) { |
390 |
auxLegend.delSymbol(mySymbol); |
391 |
auxLegend.addSymbol(((ExpressionCreator) newExpression).getExpression(), newExpression.getSymbolForExpression()); |
392 |
symbolTable.removeAllItems(); |
393 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
394 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
395 |
|
396 |
repaint(); |
397 |
} |
398 |
} |
399 |
} |
400 |
|
401 |
else if (e.getActionCommand() == "REMOVE") { |
402 |
if(symbolTable.getSelectedRowElements() == null) { |
403 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "select_one_row")+".\n"); |
404 |
} |
405 |
else{
|
406 |
ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0];
|
407 |
auxLegend.delSymbol(mySymbol); |
408 |
symbolTable.removeAllItems(); |
409 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
410 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
411 |
|
412 |
repaint(); |
413 |
} |
414 |
} |
415 |
} |
416 |
/**
|
417 |
* Adds new classifying field names to the legend when a new expression is
|
418 |
* created or an existing one is modified
|
419 |
* @param fieldNamesExpression
|
420 |
*/
|
421 |
private void addClassFieldNames(Object[] fieldNamesExpression) { |
422 |
boolean appears = false; |
423 |
ArrayList<String> myFieldNames = new ArrayList<String>(); |
424 |
|
425 |
if (auxLegend.getClassifyingFieldNames() != null) { |
426 |
|
427 |
for (int i = 0; i < auxLegend.getClassifyingFieldNames().length; i++) { |
428 |
myFieldNames.add(auxLegend.getClassifyingFieldNames()[i]); |
429 |
} |
430 |
for (int i = 0; i < fieldNamesExpression.length; i++) { |
431 |
appears = false;
|
432 |
for (int j = 0; j < auxLegend.getClassifyingFieldNames().length; j++) { |
433 |
if (auxLegend.getClassifyingFieldNames()[j].compareTo((String) fieldNamesExpression[i]) == 0) |
434 |
appears = true;
|
435 |
} |
436 |
if(!appears) {
|
437 |
myFieldNames.add((String) fieldNamesExpression[i]);
|
438 |
} |
439 |
} |
440 |
|
441 |
auxLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new |
442 |
String[myFieldNames.size()]));
|
443 |
} |
444 |
|
445 |
else {
|
446 |
for (int i = 0; i < fieldNamesExpression.length; i++) { |
447 |
myFieldNames.add((String) fieldNamesExpression[i]);
|
448 |
} |
449 |
auxLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new |
450 |
String[myFieldNames.size()]));
|
451 |
} |
452 |
} |
453 |
|
454 |
|
455 |
public ImageIcon getIcon() { |
456 |
return new ImageIcon(this.getClass().getClassLoader(). |
457 |
getResource("images/FilterExpressions.png"));
|
458 |
} |
459 |
/**
|
460 |
* This method initializes chkdefaultvalues
|
461 |
*
|
462 |
* @return javax.swing.JCheckBox
|
463 |
*/
|
464 |
protected JCheckBox getChkDefaultvalues() { |
465 |
if (chkdefaultvalues == null) { |
466 |
chkdefaultvalues = new JCheckBox(); |
467 |
chkdefaultvalues.setText(PluginServices.getText(this,
|
468 |
"resto_valores")+": "); |
469 |
chkdefaultvalues.setBounds(new java.awt.Rectangle(342, 26, 141, 20)); |
470 |
chkdefaultvalues.setSelected(false);
|
471 |
chkdefaultvalues.addActionListener(new java.awt.event.ActionListener() {
|
472 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
473 |
if (chkdefaultvalues.isSelected()) {
|
474 |
auxLegend.useDefaultSymbol(true);
|
475 |
} else {
|
476 |
auxLegend.useDefaultSymbol(false);
|
477 |
} |
478 |
} |
479 |
}); |
480 |
} |
481 |
|
482 |
return chkdefaultvalues;
|
483 |
} |
484 |
|
485 |
} |