root / org.gvsig.legend.quantitybycategory.app.mainplugin / trunk / org.gvsig.legend.quantitybycategory.app.mainplugin / src / main / java / org / gvsig / symbology / gui / layerproperties / QuantityByCategoryPanel.java @ 365
History | View | Annotate | Download (20.9 KB)
1 |
package org.gvsig.symbology.gui.layerproperties; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.GridLayout; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.util.ArrayList; |
8 |
import java.util.List; |
9 |
|
10 |
import javax.swing.BorderFactory; |
11 |
import javax.swing.DefaultComboBoxModel; |
12 |
import javax.swing.ImageIcon; |
13 |
import javax.swing.JButton; |
14 |
import javax.swing.JComboBox; |
15 |
import javax.swing.JComponent; |
16 |
import javax.swing.JOptionPane; |
17 |
import javax.swing.JPanel; |
18 |
|
19 |
import org.slf4j.Logger; |
20 |
import org.slf4j.LoggerFactory; |
21 |
|
22 |
import org.gvsig.andami.IconThemeHelper; |
23 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
24 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
25 |
import org.gvsig.app.ApplicationLocator; |
26 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
27 |
import org.gvsig.app.project.documents.view.legend.gui.MultipleAttributes; |
28 |
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable; |
29 |
import org.gvsig.app.project.documents.view.legend.gui.VectorialInterval; |
30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
32 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
33 |
import org.gvsig.fmap.dal.feature.FeatureType; |
34 |
import org.gvsig.fmap.geom.Geometry; |
35 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
38 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend; |
39 |
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval; |
40 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
41 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend; |
42 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
43 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
44 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
45 |
import org.gvsig.i18n.Messages; |
46 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialIntervalLegend; |
47 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
48 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
49 |
import org.gvsig.symbology.fmap.rendering.GraduatedSymbolsLegend; |
50 |
import org.gvsig.symbology.fmap.rendering.QuantityByCategoryLegend; |
51 |
|
52 |
|
53 |
/**
|
54 |
* Implements the panel of a legend where the user can compare two different characteristics
|
55 |
* of a region in the map. These two "fields" will be compared, on one side,
|
56 |
* using a color for the region and , on the other side, using a graduated symbol.
|
57 |
* Both methods will change (the color or the size of the symbol) depending on
|
58 |
* the value of the fields.
|
59 |
*
|
60 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
61 |
*/
|
62 |
public class QuantityByCategoryPanel extends JPanel |
63 |
implements ILegendPanel, ActionListener { |
64 |
|
65 |
private static final long serialVersionUID = 5098346573350040756L; |
66 |
private static final Logger logger = |
67 |
LoggerFactory.getLogger(QuantityByCategoryPanel.class); |
68 |
|
69 |
private JPanel pnlNorth; |
70 |
private JPanel pnlSouth; |
71 |
private JPanel pnlButtons; |
72 |
private GridBagLayoutPanel pnlFields;
|
73 |
private JPanel pnlColorAndSymbol; |
74 |
private JComboBox cmbColorField; |
75 |
private JComboBox cmbGraduatedSymbolField; |
76 |
private JButton btnColor; |
77 |
private JButton btnSymbol; |
78 |
// private JButton btnDelete;
|
79 |
// private JButton btnDeleteAll;
|
80 |
private QuantityByCategoryLegend legend;
|
81 |
private QuantityByCategoryLegend oldLegend;
|
82 |
private FLayer layer;
|
83 |
private SymbolTable symbolTable;
|
84 |
/**
|
85 |
* Constructor method
|
86 |
*/
|
87 |
public QuantityByCategoryPanel() {
|
88 |
super();
|
89 |
initialize(); |
90 |
} |
91 |
/**
|
92 |
* This method initializes this
|
93 |
*/
|
94 |
private void initialize() { |
95 |
this.setLayout(new BorderLayout()); |
96 |
this.setSize(490, 300); |
97 |
this.add(getPnlNorth(), BorderLayout.NORTH); |
98 |
this.add(getPnlSouth(),BorderLayout.CENTER); |
99 |
// this.add(getPnlButtons(),BorderLayout.SOUTH);
|
100 |
} |
101 |
/**
|
102 |
* Obtains the south panel
|
103 |
*
|
104 |
* @return JPanel
|
105 |
*/
|
106 |
private JPanel getPnlSouth() { |
107 |
if (pnlSouth == null) { |
108 |
pnlSouth = new JPanel(); |
109 |
pnlSouth.setLayout(new BorderLayout()); |
110 |
} |
111 |
return pnlSouth;
|
112 |
} |
113 |
/**
|
114 |
* Obtains the panel where the buttons will be placed
|
115 |
*
|
116 |
* @return JPanel
|
117 |
*/
|
118 |
// private JPanel getPnlButtons() {
|
119 |
// if(pnlButtons == null) {
|
120 |
// pnlButtons = new JPanel();
|
121 |
// pnlButtons.add(getButDel());
|
122 |
// pnlButtons.add(getButDelAll());
|
123 |
// }
|
124 |
// return pnlButtons;
|
125 |
// }
|
126 |
/**
|
127 |
* Obtains the button that is used to delete all the rows of the symbolTable
|
128 |
*
|
129 |
* @return JButton
|
130 |
*/
|
131 |
// private JButton getButDelAll() {
|
132 |
// if (btnDeleteAll == null) {
|
133 |
// btnDeleteAll = new JButton();
|
134 |
// btnDeleteAll.addActionListener(this);
|
135 |
// btnDeleteAll.setText(PluginServices.getText(this, "Quitar_todos"));
|
136 |
// }
|
137 |
// return btnDeleteAll;
|
138 |
// }
|
139 |
/**
|
140 |
* Obtains the button that is used to delete a row of the symbolTable
|
141 |
*
|
142 |
* @return JButton
|
143 |
*/
|
144 |
// private JButton getButDel() {
|
145 |
// if (btnDelete == null) {
|
146 |
// btnDelete = new JButton();
|
147 |
// btnDelete.addActionListener(this);
|
148 |
// btnDelete.setText(PluginServices.getText(this, "Quitar"));
|
149 |
// }
|
150 |
//
|
151 |
// return btnDelete;
|
152 |
// }
|
153 |
/**
|
154 |
* Obtains the north panel
|
155 |
*
|
156 |
* @return JPanel
|
157 |
*/
|
158 |
private JPanel getPnlNorth() { |
159 |
if (pnlNorth == null) { |
160 |
pnlNorth = new JPanel(new GridLayout(1, 2)); |
161 |
pnlNorth.add(getPnlFields()); |
162 |
pnlNorth.add(getPnlColorAndSymbol()); |
163 |
} |
164 |
|
165 |
return pnlNorth;
|
166 |
} |
167 |
/**
|
168 |
* Obtains the panel where the user has the options to select the variation to be applied
|
169 |
*
|
170 |
* @return JPanel
|
171 |
*/
|
172 |
private JPanel getPnlColorAndSymbol() { |
173 |
if (pnlColorAndSymbol == null) { |
174 |
pnlColorAndSymbol = new JPanel(); |
175 |
pnlColorAndSymbol.setBorder( |
176 |
BorderFactory.createTitledBorder(
|
177 |
null, Messages.getText("variation_by"))); |
178 |
pnlColorAndSymbol.add(getBtnColor()); |
179 |
pnlColorAndSymbol.add(getBtnSymbol()); |
180 |
} |
181 |
|
182 |
return pnlColorAndSymbol;
|
183 |
} |
184 |
/**
|
185 |
* Creates the button which is used to selecte the variation by symbol
|
186 |
*
|
187 |
* @return JButton
|
188 |
*/
|
189 |
private JButton getBtnSymbol() { |
190 |
if (btnSymbol == null) { |
191 |
btnSymbol = new JButton(Messages.getText("symbol")); |
192 |
btnSymbol.addActionListener(this);
|
193 |
} |
194 |
return btnSymbol;
|
195 |
} |
196 |
/**
|
197 |
* Creates the button which is used to selecte the variation by color ramp
|
198 |
*
|
199 |
* @return JButton
|
200 |
*/
|
201 |
private JButton getBtnColor() { |
202 |
if (btnColor == null) { |
203 |
btnColor = new JButton(Messages.getText("color_ramp")); |
204 |
btnColor.addActionListener(this);
|
205 |
} |
206 |
|
207 |
return btnColor;
|
208 |
} |
209 |
/**
|
210 |
* Creates the panel where the JComboBoxes to select the fields for the variation will be placed
|
211 |
*
|
212 |
* @return GridBagLayoutPanel
|
213 |
*/
|
214 |
private GridBagLayoutPanel getPnlFields() {
|
215 |
if (pnlFields == null) { |
216 |
pnlFields = new GridBagLayoutPanel();
|
217 |
pnlFields.setBorder( |
218 |
BorderFactory.createTitledBorder(
|
219 |
null, Messages.getText("value_fields"))); |
220 |
pnlFields.addComponent( |
221 |
Messages.getText("color_field"), getCmbColorField());
|
222 |
pnlFields.addComponent( |
223 |
Messages.getText("symbol_field") ,getCmbGraduatedField());
|
224 |
} |
225 |
|
226 |
return pnlFields;
|
227 |
} |
228 |
/**
|
229 |
* Creates a JComboBox where the user will select the field for the symbol variation
|
230 |
*
|
231 |
* @return JComboBox
|
232 |
*/
|
233 |
private JComboBox getCmbGraduatedField() { |
234 |
if (cmbGraduatedSymbolField == null) { |
235 |
cmbGraduatedSymbolField = new JComboBox(); |
236 |
cmbGraduatedSymbolField.addActionListener(this);
|
237 |
} |
238 |
return cmbGraduatedSymbolField;
|
239 |
} |
240 |
/**
|
241 |
* Creates a JComboBox where the user will select the field for the color ramp variation
|
242 |
*
|
243 |
* @return JComboBox
|
244 |
*/
|
245 |
private JComboBox getCmbColorField() { |
246 |
if (cmbColorField == null) { |
247 |
cmbColorField = new JComboBox(); |
248 |
cmbColorField.addActionListener(this);
|
249 |
} |
250 |
return cmbColorField;
|
251 |
} |
252 |
|
253 |
public void setData(FLayer lyr, ILegend legend) { |
254 |
this.layer = lyr;
|
255 |
this.oldLegend = null; |
256 |
|
257 |
if (symbolTable != null) |
258 |
pnlSouth.remove(symbolTable); |
259 |
|
260 |
|
261 |
symbolTable = new SymbolTable(
|
262 |
this, SymbolTable.INTERVALS_TYPE, Geometry.TYPES.GEOMETRY);
|
263 |
|
264 |
pnlSouth.add(symbolTable,BorderLayout.CENTER);
|
265 |
fillFieldNames(); |
266 |
|
267 |
|
268 |
if (legend instanceof QuantityByCategoryLegend) { |
269 |
this.oldLegend = (QuantityByCategoryLegend) legend.cloneLegend();
|
270 |
cmbColorField.setSelectedItem(this.oldLegend.getColorRampLegend().getClassifyingFieldNames()[0]); |
271 |
cmbGraduatedSymbolField.setSelectedItem( |
272 |
this.oldLegend.getGraduatedSymbolsLegend()
|
273 |
.getClassifyingFieldNames()[0]);
|
274 |
symbolTable.removeAllItems(); |
275 |
|
276 |
this.fillTableSkipDefault(this.oldLegend); |
277 |
|
278 |
} else {
|
279 |
this.oldLegend = new QuantityByCategoryLegend(); |
280 |
String[] fnn = { |
281 |
(String) getCmbColorField().getSelectedItem(),
|
282 |
(String) getCmbGraduatedField().getSelectedItem() };
|
283 |
|
284 |
this.oldLegend.setClassifyingFieldNames(fnn);
|
285 |
|
286 |
try {
|
287 |
FLyrVect lv = (FLyrVect) lyr; |
288 |
this.setFieldTypesFromFieldNames(lv, this.oldLegend, fnn); |
289 |
this.oldLegend.setShapeType(lv.getShapeType());
|
290 |
} catch (Exception exc) { |
291 |
logger.info("Error while setting data in legend panel", exc);
|
292 |
ApplicationLocator.getManager().messageDialog( |
293 |
Messages.getText("error_trying_to_access_to_the_layer"),
|
294 |
Messages.getText("error"),
|
295 |
JOptionPane.ERROR_MESSAGE);
|
296 |
} |
297 |
} |
298 |
} |
299 |
|
300 |
private void setFieldTypesFromFieldNames( |
301 |
FLyrVect vect, |
302 |
QuantityByCategoryLegend leg, |
303 |
String[] nn) throws DataException { |
304 |
|
305 |
FeatureStore fsto = (FeatureStore) vect.getDataStore(); |
306 |
FeatureType fty = fsto.getDefaultFeatureType(); |
307 |
int[] fieldTypes = new int[nn.length]; |
308 |
FeatureAttributeDescriptor attdesc = null;
|
309 |
|
310 |
for (int i = 0; i < nn.length; i++) { |
311 |
attdesc = fty.getAttributeDescriptor(nn[i]); |
312 |
fieldTypes[i]= attdesc.getDataType().getType(); |
313 |
} |
314 |
leg.setClassifyingFieldTypes(fieldTypes); |
315 |
} |
316 |
|
317 |
|
318 |
|
319 |
private void fillSymbolListFromTable() { |
320 |
|
321 |
ISymbol theSymbol; |
322 |
IInterval theInterval = null;
|
323 |
// Borramos las anteriores listas:
|
324 |
this.oldLegend.clear();
|
325 |
|
326 |
FLyrVect vect = (FLyrVect) layer; |
327 |
try {
|
328 |
|
329 |
String[] fNames = this.oldLegend.getClassifyingFieldNames(); |
330 |
if (fNames != null) { |
331 |
setFieldTypesFromFieldNames(vect, this.oldLegend, fNames);
|
332 |
} |
333 |
} catch (DataException e) {
|
334 |
|
335 |
logger.info("Error while fillSymbolListFromTablel", e);
|
336 |
ApplicationLocator.getManager().messageDialog( |
337 |
Messages.getText("could_not_setup_legend"),
|
338 |
Messages.getText("error"),
|
339 |
JOptionPane.ERROR_MESSAGE);
|
340 |
return;
|
341 |
} |
342 |
|
343 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
344 |
|
345 |
theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
|
346 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
347 |
theSymbol.setDescription((String) symbolTable.getFieldValue(
|
348 |
row, 2));
|
349 |
|
350 |
if (theSymbol instanceof IFillSymbol) { |
351 |
this.oldLegend.getColorRampLegend().addSymbol(theInterval, theSymbol);
|
352 |
} else if (theSymbol instanceof IMarkerSymbol){ |
353 |
this.oldLegend.getGraduatedSymbolsLegend().addSymbol(theInterval, theSymbol);
|
354 |
} |
355 |
|
356 |
} |
357 |
|
358 |
if(oldLegend.getColorRampLegend().isUseDefaultSymbol())
|
359 |
this.oldLegend.getColorRampLegend().addSymbol(
|
360 |
null, oldLegend.getColorRampLegend().getDefaultSymbol());
|
361 |
if(oldLegend.getGraduatedSymbolsLegend().isUseDefaultSymbol())
|
362 |
this.oldLegend.getGraduatedSymbolsLegend().addSymbol(
|
363 |
null, oldLegend.getGraduatedSymbolsLegend().getDefaultSymbol());
|
364 |
} |
365 |
|
366 |
public ILegend getLegend() {
|
367 |
fillSymbolListFromTable(); |
368 |
this.legend = (QuantityByCategoryLegend) this.oldLegend.cloneLegend(); |
369 |
return this.legend; |
370 |
} |
371 |
|
372 |
public String getDescription() { |
373 |
return Messages.getText("draw_quantities_for_each_category"); |
374 |
} |
375 |
|
376 |
public ImageIcon getIcon() { |
377 |
ImageIcon ii = IconThemeHelper.getImageIcon(
|
378 |
"legend-overview-quantity-by-category");
|
379 |
return ii;
|
380 |
} |
381 |
|
382 |
public Class getParentClass() { |
383 |
return MultipleAttributes.class;
|
384 |
} |
385 |
|
386 |
public String getTitle() { |
387 |
return Messages.getText("quantity_by_category"); |
388 |
} |
389 |
|
390 |
public JPanel getPanel() { |
391 |
return this; |
392 |
} |
393 |
|
394 |
public Class getLegendClass() { |
395 |
return QuantityByCategoryLegend.class;
|
396 |
} |
397 |
|
398 |
public void actionPerformed(ActionEvent e) { |
399 |
JComponent c = (JComponent) e.getSource(); |
400 |
|
401 |
if (c.equals(getBtnColor())) {
|
402 |
VectorialIntervalLegend colorRamp = this.oldLegend.getColorRampLegend();
|
403 |
String fieldName = (String) getCmbColorField().getSelectedItem(); |
404 |
if (!fieldName.equals(colorRamp.getClassifyingFieldNames()[0])) { |
405 |
// if classification field has changed, clear the legend
|
406 |
colorRamp.setClassifyingFieldNames(new String[] {fieldName}); |
407 |
colorRamp.clear(); |
408 |
} |
409 |
// create a new modal window to edit the color ramp legend
|
410 |
VectorialInterval legPanel = new VectorialInterval();
|
411 |
legPanel.setData(layer, colorRamp); |
412 |
InnerWindow window = new InnerWindow(legPanel);
|
413 |
|
414 |
ApplicationLocator.getManager().getUIManager().addWindow(window); |
415 |
|
416 |
cmbColorField.setSelectedItem(colorRamp.getClassifyingFieldNames()[0].toString());
|
417 |
ILegend newLegend = window.getLegend(); |
418 |
if (newLegend != null) { |
419 |
|
420 |
if (newLegend instanceof VectorialIntervalLegend) { |
421 |
this.oldLegend.getColorRampLegend().clear();
|
422 |
this.oldLegend.setColorRampLegend(
|
423 |
(VectorialIntervalLegend) newLegend); |
424 |
} else {
|
425 |
ApplicationLocator.getManager().messageDialog( |
426 |
Messages.getText("could_not_setup_legend"),
|
427 |
Messages.getText("error"),
|
428 |
JOptionPane.ERROR_MESSAGE);
|
429 |
} |
430 |
} |
431 |
symbolTable.removeAllItems(); |
432 |
this.fillTableSkipDefault(this.oldLegend); |
433 |
|
434 |
} else if (c.equals(getBtnSymbol())) { |
435 |
|
436 |
GraduatedSymbolsLegend graduatedSymbol = |
437 |
this.oldLegend.getGraduatedSymbolsLegend();
|
438 |
String fieldName = (String) getCmbGraduatedField().getSelectedItem(); |
439 |
if (!fieldName.equals(graduatedSymbol.getClassifyingFieldNames()[0])) { |
440 |
// if classification field has changed, clear the legend
|
441 |
graduatedSymbol.setClassifyingFieldNames(new String[] {fieldName}); |
442 |
|
443 |
ISymbol def = MapContextLocator.getSymbolManager(). |
444 |
createSymbol(Geometry.TYPES.POINT); |
445 |
graduatedSymbol.setDefaultSymbol(def); |
446 |
|
447 |
graduatedSymbol.setMinSymbolSize(1);
|
448 |
graduatedSymbol.setMaxSymbolSize(14);
|
449 |
graduatedSymbol.clear(); |
450 |
} |
451 |
// create a new modal window to edit the graduated symbol legend
|
452 |
GraduatedSymbolsPanel legPanel = new GraduatedSymbolsPanel(false); |
453 |
legPanel.setData(layer, graduatedSymbol); |
454 |
InnerWindow window = new InnerWindow(legPanel);
|
455 |
|
456 |
ApplicationLocator.getManager().getUIManager().addWindow(window); |
457 |
|
458 |
cmbGraduatedSymbolField.setSelectedItem(graduatedSymbol.getClassifyingFieldNames()[0].toString());
|
459 |
ILegend newLegend = window.getLegend(); |
460 |
if(newLegend != null) { |
461 |
|
462 |
if (newLegend instanceof GraduatedSymbolsLegend) { |
463 |
this.oldLegend.getGraduatedSymbolsLegend().clear();
|
464 |
this.oldLegend.setGraduateSymbolLegend(
|
465 |
(GraduatedSymbolsLegend) newLegend); |
466 |
} else {
|
467 |
ApplicationLocator.getManager().messageDialog( |
468 |
Messages.getText("could_not_setup_legend"),
|
469 |
Messages.getText("error"),
|
470 |
JOptionPane.ERROR_MESSAGE);
|
471 |
} |
472 |
} |
473 |
symbolTable.removeAllItems(); |
474 |
this.fillTableSkipDefault(this.oldLegend); |
475 |
} |
476 |
|
477 |
else if (c.equals(getCmbColorField())) { |
478 |
symbolTable.removeAllItems(); |
479 |
|
480 |
this.fillTableSkipDefault(
|
481 |
this.oldLegend.getGraduatedSymbolsLegend().getSymbols(),
|
482 |
this.oldLegend.getGraduatedSymbolsLegend().getValues(),
|
483 |
this.oldLegend.getDescriptions());
|
484 |
} |
485 |
|
486 |
else if (c.equals(getCmbGraduatedField())) { |
487 |
symbolTable.removeAllItems(); |
488 |
|
489 |
this.fillTableSkipDefault(
|
490 |
this.oldLegend.getColorRampLegend().getSymbols(),
|
491 |
this.oldLegend.getColorRampLegend().getValues(),
|
492 |
this.oldLegend.getDescriptions());
|
493 |
} |
494 |
|
495 |
// if (c.equals(getButDel())) {
|
496 |
// symbolTable.removeSelectedRows();
|
497 |
// }
|
498 |
//
|
499 |
// else if(c.equals(getButDelAll())) {
|
500 |
// symbolTable.removeAllItems();
|
501 |
// }
|
502 |
} |
503 |
private class InnerWindow extends JPanel implements IWindow { |
504 |
|
505 |
private ActionListener okAction = new ActionListener() { |
506 |
public void actionPerformed(ActionEvent e) { |
507 |
legend = panel.getLegend(); |
508 |
ApplicationLocator.getManager().getUIManager() |
509 |
.closeWindow(InnerWindow.this); |
510 |
} |
511 |
|
512 |
}, cancelAction = new ActionListener() { |
513 |
public void actionPerformed(ActionEvent e) { |
514 |
ApplicationLocator.getManager().getUIManager() |
515 |
.closeWindow(InnerWindow.this); |
516 |
} |
517 |
}; |
518 |
private ILegend legend;
|
519 |
private ILegendPanel panel;
|
520 |
private WindowInfo wi;
|
521 |
public InnerWindow(ILegendPanel panel) {
|
522 |
this.panel = panel;
|
523 |
this.setLayout(new BorderLayout()); |
524 |
add((JComponent) panel, BorderLayout.NORTH); |
525 |
add(new AcceptCancelPanel(okAction, cancelAction), BorderLayout.SOUTH); |
526 |
} |
527 |
|
528 |
public ILegend getLegend() {
|
529 |
return legend;
|
530 |
} |
531 |
|
532 |
public WindowInfo getWindowInfo() {
|
533 |
if (wi == null) { |
534 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
535 |
JComponent c = (JComponent) panel; |
536 |
wi.setWidth(c.getWidth()); |
537 |
wi.setHeight(c.getHeight()); |
538 |
wi.setTitle(panel.getTitle()); |
539 |
} |
540 |
return wi;
|
541 |
} |
542 |
|
543 |
public Object getWindowProfile() { |
544 |
return WindowInfo.DIALOG_PROFILE;
|
545 |
} |
546 |
|
547 |
|
548 |
} |
549 |
/**
|
550 |
* Fills the comboboxes that are placed in the panel with the
|
551 |
* classifying field names of the layer
|
552 |
*
|
553 |
*/
|
554 |
protected void fillFieldNames() { |
555 |
|
556 |
ArrayList<String> nomFields = null; |
557 |
FLyrVect vect = null;
|
558 |
|
559 |
try {
|
560 |
|
561 |
FeatureStore fsto = null;
|
562 |
FeatureType fty = null;
|
563 |
FeatureAttributeDescriptor[] atts = null; |
564 |
if (layer instanceof FLyrVect) { |
565 |
vect = (FLyrVect) layer; |
566 |
fsto = (FeatureStore) vect.getDataStore(); |
567 |
fty = fsto.getDefaultFeatureType(); |
568 |
atts = fty.getAttributeDescriptors(); |
569 |
} else {
|
570 |
ApplicationLocator.getManager().messageDialog( |
571 |
Messages.getText("error_trying_to_access_to_the_layer"),
|
572 |
Messages.getText("error"),
|
573 |
JOptionPane.ERROR_MESSAGE);
|
574 |
logger.info("Error while fillFieldNames, Unexpected layer class: "
|
575 |
+ layer); |
576 |
return;
|
577 |
} |
578 |
nomFields = new ArrayList<String>(); |
579 |
for (int i = 0; i < atts.length; i++) { |
580 |
if (atts[i].getDataType().isNumeric()) {
|
581 |
nomFields.add(atts[i].getName()); |
582 |
} |
583 |
} |
584 |
} catch (DataException e) {
|
585 |
ApplicationLocator.getManager().messageDialog( |
586 |
Messages.getText("error_trying_to_access_to_the_layer"),
|
587 |
Messages.getText("error"),
|
588 |
JOptionPane.ERROR_MESSAGE);
|
589 |
logger.info("Error while fillFieldNames", e);
|
590 |
nomFields = new ArrayList<String>(); |
591 |
} |
592 |
|
593 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray()); |
594 |
cmbColorField.setModel(cM); |
595 |
cM = new DefaultComboBoxModel(nomFields.toArray()); |
596 |
cmbGraduatedSymbolField.setModel(cM); |
597 |
|
598 |
symbolTable.removeAllItems(); |
599 |
} |
600 |
|
601 |
|
602 |
public boolean isSuitableFor(FLayer layer) { |
603 |
if (layer instanceof FLyrVect) { |
604 |
try {
|
605 |
FLyrVect vect = (FLyrVect) layer; |
606 |
int shpt = vect.getGeometryType().getType();
|
607 |
|
608 |
if (!QuantityByCategoryLegend.isPolygonal(shpt)) {
|
609 |
return false; |
610 |
} |
611 |
|
612 |
FeatureStore fsto = (FeatureStore) vect.getDataStore(); |
613 |
FeatureType fty = fsto.getDefaultFeatureType(); |
614 |
FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
|
615 |
|
616 |
for (int i = 0; i < atts.length; i++) { |
617 |
if (atts[i].getDataType().isNumeric()) {
|
618 |
return true; |
619 |
} |
620 |
} |
621 |
} catch (Exception e) { |
622 |
logger.info("Error while isSuitableFor.", e);
|
623 |
ApplicationLocator.getManager().message( |
624 |
Messages.getText("error"),
|
625 |
JOptionPane.ERROR_MESSAGE);
|
626 |
return false; |
627 |
} |
628 |
} |
629 |
return false; |
630 |
} |
631 |
|
632 |
|
633 |
// reemplazar esto por arriba
|
634 |
private void fillTableSkipDefault( |
635 |
IClassifiedLegend leg) { |
636 |
|
637 |
Object[] src_expr = leg.getValues(); |
638 |
ISymbol[] src_syms = leg.getSymbols();
|
639 |
String[] src_descs = leg.getDescriptions(); |
640 |
|
641 |
List syms = new ArrayList(); |
642 |
List vals = new ArrayList(); |
643 |
List descs = new ArrayList(); |
644 |
for (int i=0; i<src_expr.length; i++) { |
645 |
if (src_expr[i] instanceof IInterval) { |
646 |
syms.add(src_syms[i]); |
647 |
vals.add(src_expr[i]); |
648 |
descs.add(src_descs[i]); |
649 |
} |
650 |
} |
651 |
symbolTable.fillTableFromSymbolList( |
652 |
(ISymbol[]) syms.toArray(new ISymbol[0]), |
653 |
(Object[]) vals.toArray(new Object[0]), |
654 |
(String[]) descs.toArray(new String[0])); |
655 |
} |
656 |
|
657 |
private void fillTableSkipDefault( |
658 |
ISymbol[] src_syms,
|
659 |
Object[] src_expr, |
660 |
String[] src_descs) { |
661 |
|
662 |
List syms = new ArrayList(); |
663 |
List vals = new ArrayList(); |
664 |
List descs = new ArrayList(); |
665 |
for (int i=0; i<src_expr.length; i++) { |
666 |
if (src_expr[i] instanceof IInterval) { |
667 |
syms.add(src_syms[i]); |
668 |
vals.add(src_expr[i]); |
669 |
descs.add(src_descs[i]); |
670 |
} |
671 |
} |
672 |
symbolTable.fillTableFromSymbolList( |
673 |
(ISymbol[]) syms.toArray(new ISymbol[0]), |
674 |
(Object[]) vals.toArray(new Object[0]), |
675 |
(String[]) descs.toArray(new String[0])); |
676 |
} |
677 |
|
678 |
|
679 |
} |