root / trunk / extensions / extSymbology / src / com / iver / cit / gvsig / project / documents / view / legend / gui / VectorialFilterExpression.java @ 20768
History | View | Annotate | Download (12 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.event.ActionEvent; |
45 |
import java.awt.event.ActionListener; |
46 |
import java.io.File; |
47 |
import java.io.IOException; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import javax.swing.ImageIcon; |
51 |
import javax.swing.JCheckBox; |
52 |
import javax.swing.JOptionPane; |
53 |
import javax.swing.JPanel; |
54 |
|
55 |
import org.gvsig.gui.beans.swing.JButton; |
56 |
import org.gvsig.symbology.fmap.rendering.VectorialFilterExpressionLegend; |
57 |
import org.gvsig.symbology.fmap.symbols.PictureFillSymbol; |
58 |
|
59 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
60 |
import com.iver.andami.PluginServices; |
61 |
import com.iver.andami.messages.NotificationManager; |
62 |
import com.iver.andami.ui.mdiManager.IWindow; |
63 |
import com.iver.cit.gvsig.fmap.core.FShape; |
64 |
import com.iver.cit.gvsig.fmap.core.styles.IMarkerFillPropertiesStyle; |
65 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
68 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
69 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
70 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
71 |
|
72 |
/**
|
73 |
* Implements the JPanel that shows the properties of a VectorialFilterExpressionLegend
|
74 |
* in order to allows the user to modify its characteristics
|
75 |
*
|
76 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
|
77 |
*
|
78 |
*/
|
79 |
public class VectorialFilterExpression extends JPanel implements ILegendPanel,ActionListener { |
80 |
private static final long serialVersionUID = -7187473609965942511L; |
81 |
private VectorialFilterExpressionLegend theLegend;
|
82 |
private ClassifiableVectorial layer;
|
83 |
private PictureFillSymbol previewSymbol;
|
84 |
private JPanel pnlCenter; |
85 |
private SymbolTable symbolTable;
|
86 |
private JButton btnAddExpression; |
87 |
private JButton btnModExpression; |
88 |
private JButton btnRemoveExpression; |
89 |
private JCheckBox useDefaultSymbol; |
90 |
private int shapeType; |
91 |
/**
|
92 |
* This is the default constructor
|
93 |
*/
|
94 |
public VectorialFilterExpression() {
|
95 |
super();
|
96 |
initialize(); |
97 |
} |
98 |
|
99 |
|
100 |
/**
|
101 |
* This method initializes this
|
102 |
*/
|
103 |
private void initialize() { |
104 |
|
105 |
pnlCenter = new JPanel(); |
106 |
pnlCenter.setLayout(new BorderLayout()); |
107 |
|
108 |
JPanel pnlButtons = new JPanel(); |
109 |
|
110 |
useDefaultSymbol = new JCheckBox(PluginServices.getText(this, "use_default_symbol")); |
111 |
useDefaultSymbol.setActionCommand("USE_DEFAULT_SYMBOL");
|
112 |
useDefaultSymbol.addActionListener(this);
|
113 |
pnlButtons.add(useDefaultSymbol); |
114 |
|
115 |
btnAddExpression = new JButton(PluginServices.getText(this, "new_filter_expression")); |
116 |
btnAddExpression.setActionCommand("NEW_EXPRESSION");
|
117 |
btnAddExpression.addActionListener(this);
|
118 |
pnlButtons.add(btnAddExpression); |
119 |
|
120 |
btnModExpression = new JButton(PluginServices.getText(this, "modify_filter_expression")); |
121 |
btnModExpression.setActionCommand("MODIFY_EXPRESSION");
|
122 |
btnModExpression.addActionListener(this);
|
123 |
pnlButtons.add(btnModExpression); |
124 |
|
125 |
btnRemoveExpression = new JButton(PluginServices.getText(this, "delete_filter_expression")); |
126 |
btnRemoveExpression.setActionCommand("REMOVE");
|
127 |
btnRemoveExpression.addActionListener(this);
|
128 |
pnlButtons.add(btnRemoveExpression); |
129 |
|
130 |
this.setLayout(new BorderLayout()); |
131 |
this.add(pnlCenter, BorderLayout.CENTER); |
132 |
this.add(pnlButtons, BorderLayout.SOUTH); |
133 |
|
134 |
} |
135 |
|
136 |
|
137 |
public String getDescription() { |
138 |
return PluginServices.getText(this,"shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + "."; |
139 |
} |
140 |
|
141 |
public ISymbol getIconSymbol() {
|
142 |
if (previewSymbol == null) { |
143 |
try {
|
144 |
previewSymbol = new PictureFillSymbol();
|
145 |
previewSymbol.setImage( new File( |
146 |
this.getClass().getClassLoader().
|
147 |
getResource("images/ValoresUnicos.png").
|
148 |
getFile()).toURL()); |
149 |
previewSymbol.getMarkerFillProperties(). |
150 |
setFillStyle( |
151 |
IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL); |
152 |
} catch (IOException e) { |
153 |
return null; |
154 |
} |
155 |
} |
156 |
return previewSymbol;
|
157 |
} |
158 |
|
159 |
public ILegend getLegend() {
|
160 |
theLegend.clear(); |
161 |
fillSymbolListFromTable(); |
162 |
return theLegend;
|
163 |
} |
164 |
/**
|
165 |
* Fills the list of symbols of the legend
|
166 |
*
|
167 |
*/
|
168 |
private void fillSymbolListFromTable() { |
169 |
Object clave;
|
170 |
ISymbol theSymbol; |
171 |
boolean bRestoValores = false; |
172 |
int hasta;
|
173 |
|
174 |
FLyrVect m = (FLyrVect) layer; |
175 |
try {
|
176 |
|
177 |
if(theLegend.getClassifyingFieldNames() != null) { |
178 |
String[] fNames= theLegend.getClassifyingFieldNames(); |
179 |
int[] fieldTypes = new int[theLegend.getClassifyingFieldNames().length]; |
180 |
|
181 |
for (int i = 0; i < theLegend.getClassifyingFieldNames().length; i++) { |
182 |
int fieldIndex = m.getSource().getRecordset().getFieldIndexByName(fNames[i]);
|
183 |
fieldTypes[i]= m.getSource().getRecordset().getFieldType(fieldIndex); |
184 |
} |
185 |
|
186 |
theLegend.setClassifyingFieldTypes(fieldTypes); |
187 |
} |
188 |
} catch (ReadDriverException e) {
|
189 |
NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e); |
190 |
} |
191 |
|
192 |
|
193 |
if (bRestoValores) {
|
194 |
hasta = symbolTable.getRowCount() - 1;
|
195 |
} else {
|
196 |
hasta = symbolTable.getRowCount(); |
197 |
} |
198 |
|
199 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
200 |
clave = symbolTable.getFieldValue(row, 1);
|
201 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
202 |
theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2)); |
203 |
theLegend.addSymbol(clave, theSymbol); |
204 |
} |
205 |
|
206 |
if (bRestoValores) {
|
207 |
theSymbol = (ISymbol) symbolTable.getFieldValue(hasta, 0);
|
208 |
theLegend.setDefaultSymbol(theSymbol); |
209 |
} |
210 |
|
211 |
|
212 |
} |
213 |
|
214 |
public Class getLegendClass() { |
215 |
return VectorialFilterExpressionLegend.class;
|
216 |
} |
217 |
|
218 |
public JPanel getPanel() { |
219 |
return this; |
220 |
} |
221 |
|
222 |
public Class getParentClass() { |
223 |
return Categories.class;
|
224 |
} |
225 |
|
226 |
public String getTitle() { |
227 |
return PluginServices.getText(this,"expressions"); |
228 |
} |
229 |
|
230 |
public boolean isSuitableFor(FLayer layer) { |
231 |
|
232 |
FLyrVect lVect = (FLyrVect) layer; |
233 |
try {
|
234 |
return lVect.getShapeType() != FShape.MULTI;
|
235 |
} catch (ReadDriverException e) {
|
236 |
return false; |
237 |
} |
238 |
|
239 |
} |
240 |
|
241 |
public void setData(FLayer lyr, ILegend legend) { |
242 |
this.layer = (ClassifiableVectorial) lyr;
|
243 |
shapeType = 0;
|
244 |
|
245 |
try {
|
246 |
shapeType = this.layer.getShapeType();
|
247 |
} catch (ReadDriverException e) {
|
248 |
NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e); |
249 |
} |
250 |
|
251 |
if (symbolTable != null) |
252 |
pnlCenter.remove(symbolTable); |
253 |
|
254 |
symbolTable = new SymbolTable(this, "expressions", shapeType); |
255 |
pnlCenter.add(symbolTable, BorderLayout.CENTER);
|
256 |
|
257 |
if (legend instanceof VectorialFilterExpressionLegend) { |
258 |
theLegend = (VectorialFilterExpressionLegend) legend; |
259 |
symbolTable.fillTableFromSymbolList(theLegend.getSymbols(), |
260 |
theLegend.getValues(), theLegend.getDescriptions()); |
261 |
useDefaultSymbol.setSelected(theLegend.isUseDefaultSymbol()); |
262 |
} else {
|
263 |
theLegend = new VectorialFilterExpressionLegend();
|
264 |
theLegend.setShapeType(shapeType); |
265 |
useDefaultSymbol.setSelected(false);
|
266 |
theLegend.useDefaultSymbol(useDefaultSymbol.isSelected()); |
267 |
} |
268 |
} |
269 |
|
270 |
public void actionPerformed(ActionEvent e) { |
271 |
if (e.getActionCommand() == "NEW_EXPRESSION") { |
272 |
ExpressionCreator newExpression = new ExpressionCreator((FLyrVect) this.layer ); |
273 |
PluginServices.getMDIManager().addWindow((IWindow) newExpression); |
274 |
String expression = ((ExpressionCreator) newExpression).getExpression();
|
275 |
if(newExpression.getFieldNamesExpression() != null) |
276 |
addClassFieldNames(newExpression.getFieldNamesExpression()); |
277 |
|
278 |
if(expression != null) |
279 |
if(expression.compareTo("") != 0) { |
280 |
symbolTable.addTableRecord(newExpression.getSymbolForExpression(), expression, newExpression.getDescriptionForExpression()); |
281 |
theLegend.addSymbol(expression, newExpression.getSymbolForExpression()); |
282 |
} |
283 |
repaint(); |
284 |
} |
285 |
else if (e.getActionCommand() == "MODIFY_EXPRESSION") { |
286 |
|
287 |
if(symbolTable.getSelectedRowElements() == null) { |
288 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "select_one_row")+".\n"); |
289 |
} |
290 |
|
291 |
else {
|
292 |
ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0];
|
293 |
String expression = (String) symbolTable.getSelectedRowElements()[1]; |
294 |
String myDesc = (String) symbolTable.getSelectedRowElements()[2]; |
295 |
|
296 |
ExpressionCreator newExpression = new ExpressionCreator((FLyrVect) this.layer ); |
297 |
newExpression.setExpression(expression); |
298 |
newExpression.setDescriptionForExpression(myDesc); |
299 |
newExpression.setSymbolForExpression(mySymbol); |
300 |
PluginServices.getMDIManager().addWindow((IWindow) newExpression); |
301 |
|
302 |
expression = ((ExpressionCreator) newExpression).getExpression(); |
303 |
if(expression != null) |
304 |
if(expression.compareTo("") != 0) { |
305 |
symbolTable.removeSelectedRows(); |
306 |
theLegend.delSymbol(expression); |
307 |
symbolTable.addTableRecord(newExpression.getSymbolForExpression(), ((ExpressionCreator) newExpression).getExpression(), newExpression.getDescriptionForExpression()); |
308 |
theLegend.addSymbol(((ExpressionCreator) newExpression).getExpression(), newExpression.getSymbolForExpression()); |
309 |
repaint(); |
310 |
} |
311 |
} |
312 |
} |
313 |
else if (e.getActionCommand() == "USE_DEFAULT_SYMBOL" ) { |
314 |
if(theLegend != null) { |
315 |
theLegend.useDefaultSymbol(useDefaultSymbol.isSelected()); |
316 |
repaint(); |
317 |
} |
318 |
} |
319 |
else if (e.getActionCommand() == "REMOVE") { |
320 |
if(symbolTable.getSelectedRowElements() == null) { |
321 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "select_one_row")+".\n"); |
322 |
} |
323 |
else
|
324 |
symbolTable.removeSelectedRows(); |
325 |
} |
326 |
} |
327 |
/**
|
328 |
* Adds new classifying field names to the legend when a new expression is
|
329 |
* created or an existing one is modified
|
330 |
* @param fieldNamesExpression
|
331 |
*/
|
332 |
private void addClassFieldNames(Object[] fieldNamesExpression) { |
333 |
boolean appears = false; |
334 |
ArrayList<String> myFieldNames = new ArrayList<String>(); |
335 |
|
336 |
if (theLegend.getClassifyingFieldNames() != null) { |
337 |
|
338 |
for (int i = 0; i < theLegend.getClassifyingFieldNames().length; i++) { |
339 |
myFieldNames.add(theLegend.getClassifyingFieldNames()[i]); |
340 |
} |
341 |
for (int i = 0; i < fieldNamesExpression.length; i++) { |
342 |
appears = false;
|
343 |
for (int j = 0; j < theLegend.getClassifyingFieldNames().length; j++) { |
344 |
if (theLegend.getClassifyingFieldNames()[j].compareTo((String) fieldNamesExpression[i]) == 0) |
345 |
appears = true;
|
346 |
} |
347 |
if(!appears) {
|
348 |
myFieldNames.add((String) fieldNamesExpression[i]);
|
349 |
} |
350 |
} |
351 |
|
352 |
theLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new |
353 |
String[myFieldNames.size()]));
|
354 |
} |
355 |
|
356 |
else {
|
357 |
for (int i = 0; i < fieldNamesExpression.length; i++) { |
358 |
myFieldNames.add((String) fieldNamesExpression[i]);
|
359 |
} |
360 |
theLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new |
361 |
String[myFieldNames.size()]));
|
362 |
} |
363 |
} |
364 |
|
365 |
|
366 |
public ImageIcon getIcon() { |
367 |
// TODO Auto-generated method stub
|
368 |
return null; |
369 |
} |
370 |
|
371 |
|
372 |
} |