root / org.gvsig.chart / trunk / org.gvsig.chart / org.gvsig.chart.app / org.gvsig.chart.app.legendplugin / src / main / java / org / gvsig / project / documents / view / legend / gui / ChartLegendPanelBars.java @ 571
History | View | Annotate | Download (33.4 KB)
1 |
package org.gvsig.project.documents.view.legend.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.Font; |
8 |
import java.awt.event.ActionEvent; |
9 |
import java.awt.event.ActionListener; |
10 |
import java.sql.Types; |
11 |
import java.util.ArrayList; |
12 |
import java.util.Iterator; |
13 |
import java.util.List; |
14 |
import java.util.Random; |
15 |
|
16 |
import javax.swing.BorderFactory; |
17 |
import javax.swing.DefaultListModel; |
18 |
import javax.swing.ImageIcon; |
19 |
import javax.swing.JButton; |
20 |
import javax.swing.JCheckBox; |
21 |
import javax.swing.JLabel; |
22 |
import javax.swing.JList; |
23 |
import javax.swing.JPanel; |
24 |
import javax.swing.JScrollPane; |
25 |
import javax.swing.border.TitledBorder; |
26 |
|
27 |
import org.gvsig.andami.IconThemeHelper; |
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.messages.NotificationManager; |
30 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
31 |
import org.gvsig.app.gui.styling.JComboBoxColorScheme; |
32 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
33 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
34 |
import org.gvsig.app.project.documents.view.legend.gui.MultipleAttributes; |
35 |
import org.gvsig.chart.ChartLocator; |
36 |
import org.gvsig.chart.ChartManager; |
37 |
import org.gvsig.chart.ChartProperties; |
38 |
import org.gvsig.chart.ChartService; |
39 |
import org.gvsig.chart.legend.IBarsChartLegend; |
40 |
import org.gvsig.chart.legend.IChartLegend; |
41 |
import org.gvsig.chart.legend.symbols.IChartSymbol; |
42 |
import org.gvsig.fmap.dal.exception.DataException; |
43 |
import org.gvsig.fmap.dal.exception.ReadException; |
44 |
import org.gvsig.fmap.dal.feature.Feature; |
45 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
46 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
47 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
48 |
import org.gvsig.fmap.dal.feature.FeatureType; |
49 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
50 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
51 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
52 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
53 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
54 |
import org.gvsig.project.documents.view.legend.BarsChartLegend; |
55 |
import org.gvsig.tools.dataTypes.DataTypes; |
56 |
import org.gvsig.tools.dispose.DisposableIterator; |
57 |
import org.gvsig.tools.service.ServiceException; |
58 |
|
59 |
public class ChartLegendPanelBars extends JPanel implements ILegendPanel { |
60 |
|
61 |
/**
|
62 |
*
|
63 |
*/
|
64 |
private static final long serialVersionUID = -5433774351402039533L; |
65 |
// private PreviewBarSymbol previewPanel = null;
|
66 |
private FLyrVect layer;
|
67 |
private int shapeType; |
68 |
private IChartLegend auxLegend; // @jve:decl-index=0: |
69 |
private IChartLegend theLegend;
|
70 |
private JPanel centerPanel = null; // @jve:decl-index=0:visual-constraint="10,10" |
71 |
private JScrollPane jScrollPane = null; |
72 |
private JList jFieldList = null; |
73 |
private final Random rand = new Random(System.currentTimeMillis()); |
74 |
private JPanel buttons = null; |
75 |
private JButton addButton = null; |
76 |
private JButton removeButton = null; |
77 |
private JButton addAllButton = null; |
78 |
private JButton removeAllButton = null; |
79 |
private JPanel pCentral = null; |
80 |
private FieldsTable fieldsTable = null; // @jve:decl-index=0:visual-constraint="746,10" |
81 |
private JPanel northPanel = null; |
82 |
private JPanel southPanel = null; |
83 |
|
84 |
private JButton bSize = null; |
85 |
private JPanel symbolPanel = null; |
86 |
private JLabel lBackgroundSymbol = null; |
87 |
|
88 |
private JSymbolPreviewButton bSymbolBackground = null; |
89 |
private JComboBoxColorScheme colorCombo = null; |
90 |
private JLabel lColorSchema = null; |
91 |
|
92 |
private JCheckBox ckOnlySelection = null; |
93 |
private JPanel eastPanel; |
94 |
private JPanel outlinePanel; |
95 |
private JLabel jLabel; |
96 |
private JCheckBox jCheckBox; |
97 |
private JCheckBox jShowAxis; |
98 |
private JPanel jPanel; |
99 |
private JLabel jLabel1; |
100 |
private JPanel jPanel1; |
101 |
private JNumberSpinner comboWidth;
|
102 |
private JPanel dimensionPanel; |
103 |
private JCheckBox ck3D; |
104 |
private ColorChooserPanel colorButton;
|
105 |
|
106 |
/**
|
107 |
* This is the default constructor
|
108 |
*/
|
109 |
public ChartLegendPanelBars() {
|
110 |
super();
|
111 |
initialize(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* This method initializes this
|
116 |
*
|
117 |
* @return void
|
118 |
*/
|
119 |
private void initialize() { |
120 |
this.setPreferredSize(new Dimension(732, 354)); |
121 |
this.setLayout(new BorderLayout()); |
122 |
this.add(getCenterPanel(), BorderLayout.CENTER); |
123 |
this.add(getSouthPanel(), BorderLayout.SOUTH); |
124 |
this.add(getEastPanel(), BorderLayout.EAST); |
125 |
|
126 |
} |
127 |
|
128 |
private JPanel getEastPanel() { |
129 |
if (eastPanel == null) { |
130 |
eastPanel = new JPanel(); |
131 |
eastPanel.setLayout(new BorderLayout()); |
132 |
eastPanel.setPreferredSize(new Dimension(150, 52)); |
133 |
// eastPanel.add(getPreviewChart(), BorderLayout.NORTH);
|
134 |
eastPanel.add(getOutlinePanel(), BorderLayout.CENTER);
|
135 |
eastPanel.add(getDimensionPanel(), BorderLayout.SOUTH);
|
136 |
} |
137 |
return eastPanel;
|
138 |
} |
139 |
|
140 |
private JPanel getDimensionPanel() { |
141 |
if (dimensionPanel == null) { |
142 |
dimensionPanel = new JPanel(); |
143 |
dimensionPanel.setLayout(new BorderLayout()); |
144 |
dimensionPanel.setBorder(BorderFactory.createTitledBorder(null, |
145 |
PluginServices.getText(this, "dimension"), |
146 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
147 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
148 |
Font.BOLD, 12), new Color(51, 51, 51))); |
149 |
dimensionPanel.setPreferredSize(new Dimension(150, 50)); |
150 |
dimensionPanel.add(getCk3D(), BorderLayout.NORTH);
|
151 |
} |
152 |
return dimensionPanel;
|
153 |
} |
154 |
|
155 |
private JCheckBox getCk3D() { |
156 |
if (ck3D == null) { |
157 |
ck3D = new JCheckBox(); |
158 |
ck3D.setText(PluginServices.getText(this, "display_3d")); |
159 |
} |
160 |
return ck3D;
|
161 |
} |
162 |
|
163 |
private JPanel getOutlinePanel() { |
164 |
if (outlinePanel == null) { |
165 |
jLabel = new JLabel(); |
166 |
jLabel.setText(PluginServices.getText(this, "color")); |
167 |
outlinePanel = new JPanel(); |
168 |
outlinePanel.setLayout(new BorderLayout()); |
169 |
outlinePanel.setBorder(BorderFactory.createTitledBorder(null, |
170 |
PluginServices.getText(this, "background_color"), |
171 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
172 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
173 |
Font.BOLD, 12), new Color(51, 51, 51))); |
174 |
outlinePanel.setPreferredSize(new Dimension(150, 115)); |
175 |
outlinePanel.add(getJCheckBox(), BorderLayout.NORTH);
|
176 |
outlinePanel.add(getJPanel(), BorderLayout.CENTER);
|
177 |
//outlinePanel.add(getJPanel1(), BorderLayout.SOUTH);
|
178 |
} |
179 |
return outlinePanel;
|
180 |
} |
181 |
|
182 |
private JPanel getJPanel() { |
183 |
if (jPanel == null) { |
184 |
jPanel = new JPanel(); |
185 |
jPanel.setLayout(new FlowLayout()); |
186 |
jPanel.add(jLabel, null);
|
187 |
jPanel.add(getColorButton(), null);
|
188 |
} |
189 |
return jPanel;
|
190 |
} |
191 |
|
192 |
private ColorChooserPanel getColorButton() {
|
193 |
if (colorButton == null) { |
194 |
colorButton = new ColorChooserPanel(true); |
195 |
colorButton.setColor(Color.black);
|
196 |
} |
197 |
return colorButton;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* This method initializes jPanel1
|
202 |
*
|
203 |
* @return javax.swing.JPanel
|
204 |
*/
|
205 |
private JPanel getJPanel1() { |
206 |
if (jPanel1 == null) { |
207 |
jLabel1 = new JLabel(); |
208 |
jLabel1.setText(PluginServices.getText(this, "width")); |
209 |
jPanel1 = new JPanel(); |
210 |
jPanel1.setLayout(new FlowLayout()); |
211 |
jPanel1.add(jLabel1, null);
|
212 |
jPanel1.add(getComboWidth(), null);
|
213 |
} |
214 |
return jPanel1;
|
215 |
} |
216 |
|
217 |
private JNumberSpinner getComboWidth() {
|
218 |
if (comboWidth == null) { |
219 |
comboWidth = new JNumberSpinner(String.valueOf(1), 3, 0, Integer.MAX_VALUE, 1); |
220 |
} |
221 |
return comboWidth;
|
222 |
} |
223 |
|
224 |
private JCheckBox getShowAxis() { |
225 |
if (jShowAxis == null) { |
226 |
jShowAxis = new JCheckBox(); |
227 |
jShowAxis.setText(PluginServices.getText(this, "show_axis")); |
228 |
} |
229 |
return jShowAxis;
|
230 |
} |
231 |
|
232 |
private JCheckBox getJCheckBox() { |
233 |
if (jCheckBox == null) { |
234 |
jCheckBox = new JCheckBox(); |
235 |
jCheckBox.setText(PluginServices.getText(this, "Show")); |
236 |
} |
237 |
return jCheckBox;
|
238 |
} |
239 |
|
240 |
private JPanel getSouthPanel() { |
241 |
if (southPanel == null) { |
242 |
southPanel = new JPanel(); |
243 |
southPanel.setLayout(new FlowLayout()); |
244 |
southPanel.setPreferredSize(new Dimension(241, 90)); |
245 |
southPanel.add(getSymbolPanel(), null);
|
246 |
southPanel.add(getNorthPanel(), null);
|
247 |
southPanel.add(getBSize(), null);
|
248 |
southPanel.add(getCkOnlySelection(), null);
|
249 |
} |
250 |
return southPanel;
|
251 |
} |
252 |
|
253 |
private JPanel getSymbolPanel() { |
254 |
if (symbolPanel == null) { |
255 |
lBackgroundSymbol = new JLabel(); |
256 |
lBackgroundSymbol.setText(PluginServices.getText(this,
|
257 |
"background_symbol"));
|
258 |
lBackgroundSymbol.setText(PluginServices.getText(this,
|
259 |
"show_axis"));
|
260 |
symbolPanel = new JPanel(); |
261 |
symbolPanel.setLayout(new FlowLayout()); |
262 |
symbolPanel.setPreferredSize(new Dimension(241, 40)); |
263 |
// symbolPanel.add(lBackgroundSymbol, null);
|
264 |
// symbolPanel.add(getBackgroundSymbol(), null);
|
265 |
symbolPanel.add(getShowAxis(), null);
|
266 |
|
267 |
} |
268 |
return symbolPanel;
|
269 |
} |
270 |
|
271 |
// private PreviewPieSymbol getPreviewChart() {
|
272 |
// if (previewPanel == null) {
|
273 |
// previewPanel = new PreviewPieSymbol();
|
274 |
// previewPanel.setLayout(new BorderLayout());
|
275 |
// previewPanel.setBorder(BorderFactory.createTitledBorder(null,
|
276 |
// PluginServices.getText(this, "preview_chart"),
|
277 |
// TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new
|
278 |
// Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
|
279 |
// previewPanel.setPreferredSize(new Dimension(150, 100));
|
280 |
// }
|
281 |
// return previewPanel;
|
282 |
// }
|
283 |
private JSymbolPreviewButton getBackgroundSymbol() {
|
284 |
if (bSymbolBackground == null) { |
285 |
bSymbolBackground = new JSymbolPreviewButton(shapeType);
|
286 |
bSymbolBackground.setPreferredSize(new Dimension(110, 20)); |
287 |
// bSymbolBackground.addActionListener(new ActionListener() {
|
288 |
// public void actionPerformed(ActionEvent e) {
|
289 |
// // getPreviewChart().setBackgroundSymbol(bSymbolBackground.getSymbol());
|
290 |
// // getPreviewChart().repaint();
|
291 |
// }
|
292 |
// });
|
293 |
} |
294 |
return bSymbolBackground;
|
295 |
} |
296 |
|
297 |
private JButton getBSize() { |
298 |
if (bSize == null) { |
299 |
bSize = new JButton(); |
300 |
bSize.setText(PluginServices.getText(this, "size")); |
301 |
bSize.setPreferredSize(new Dimension(100, 30)); |
302 |
bSize.setMaximumSize(new Dimension(100, 30)); |
303 |
bSize.addActionListener((ActionEvent e) -> {
|
304 |
PluginServices.getMDIManager().addCentredWindow( |
305 |
new SizePanel(layer, (IChartLegend) getLegend()));
|
306 |
}); |
307 |
} |
308 |
return bSize;
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* This method initializes centerPanel
|
313 |
*
|
314 |
* @return javax.swing.JPanel
|
315 |
*/
|
316 |
private JPanel getCenterPanel() { |
317 |
if (centerPanel == null) { |
318 |
centerPanel = new JPanel(); |
319 |
centerPanel.setLayout(new BorderLayout()); |
320 |
centerPanel.setPreferredSize(new Dimension(350, 300)); |
321 |
centerPanel.add(getJScrollPane(), BorderLayout.WEST);
|
322 |
centerPanel.add(getButtons(), BorderLayout.CENTER);
|
323 |
centerPanel.add(getFieldsTable(), java.awt.BorderLayout.EAST); |
324 |
} |
325 |
return centerPanel;
|
326 |
} |
327 |
|
328 |
private JPanel getPCentral() { |
329 |
if (pCentral == null) { |
330 |
pCentral = new JPanel(); |
331 |
pCentral.setLayout(new FlowLayout()); |
332 |
pCentral.setPreferredSize(new Dimension(50, 185)); |
333 |
pCentral.add(getRemoveAllButton(), null);
|
334 |
pCentral.add(getAddAllButton(), null);
|
335 |
pCentral.add(getRemoveButton(), null);
|
336 |
pCentral.add(getAddButton(), null);
|
337 |
} |
338 |
return pCentral;
|
339 |
} |
340 |
|
341 |
private JButton getAddButton() { |
342 |
if (addButton == null) { |
343 |
addButton = new JButton(); |
344 |
addButton.setText(">");
|
345 |
addButton.setPreferredSize(new Dimension(50, 40)); |
346 |
addButton.addActionListener((java.awt.event.ActionEvent e) -> { |
347 |
Object[] fields = getJFieldList().getSelectedValues(); |
348 |
Color[] colorScheme = colorCombo.getSelectedColors(); |
349 |
|
350 |
Color[] colors = new Color[colorScheme.length]; |
351 |
System.arraycopy(colorScheme, 0, colors, 0, colorScheme.length); |
352 |
for (Object field : fields) { |
353 |
getFieldsTable().addTableRecord(colorScheme[rand.nextInt(colorScheme.length)], (String) field, (String) field); |
354 |
((DefaultListModel) getJFieldList().getModel()).removeElement(field);
|
355 |
} |
356 |
}); |
357 |
} |
358 |
return addButton;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* This method initializes northPanel
|
363 |
*
|
364 |
* @return javax.swing.JPanel
|
365 |
*/
|
366 |
private JPanel getNorthPanel() { |
367 |
if (northPanel == null) { |
368 |
lColorSchema = new JLabel(); |
369 |
lColorSchema.setText(PluginServices.getText(this, "color_schema")); |
370 |
northPanel = new JPanel(); |
371 |
northPanel.setLayout(new FlowLayout()); |
372 |
northPanel.add(lColorSchema, null);
|
373 |
northPanel.add(getColorCombo()); |
374 |
} |
375 |
return northPanel;
|
376 |
} |
377 |
|
378 |
private JComboBoxColorScheme getColorCombo() {
|
379 |
if (colorCombo == null) { |
380 |
colorCombo = new JComboBoxColorScheme(false); |
381 |
} |
382 |
return colorCombo;
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* This method initializes removeButton
|
387 |
*
|
388 |
* @return javax.swing.JButton
|
389 |
*/
|
390 |
private JButton getRemoveButton() { |
391 |
if (removeButton == null) { |
392 |
removeButton = new JButton(); |
393 |
removeButton.setPreferredSize(new Dimension(50, 40)); |
394 |
removeButton.setText("<");
|
395 |
removeButton.addActionListener((java.awt.event.ActionEvent e) -> { |
396 |
int[] index = getFieldsTable().getSelectedRows(); |
397 |
String[] fields = new String[index.length]; |
398 |
for (int i = 0; i < index.length; i++) { |
399 |
fields[i] = (String) getFieldsTable().getFieldValue(
|
400 |
index[i], 1);
|
401 |
} |
402 |
for (String field : fields) { |
403 |
((DefaultListModel) getJFieldList().getModel()).addElement(field);
|
404 |
} |
405 |
getFieldsTable().removeSelectedRows(); |
406 |
}); |
407 |
} |
408 |
return removeButton;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* This method initializes addAllButton
|
413 |
*
|
414 |
* @return javax.swing.JButton
|
415 |
*/
|
416 |
private JButton getAddAllButton() { |
417 |
if (addAllButton == null) { |
418 |
addAllButton = new JButton(); |
419 |
addAllButton.setPreferredSize(new Dimension(50, 40)); |
420 |
addAllButton.setText(">>");
|
421 |
addAllButton.addActionListener((java.awt.event.ActionEvent e) -> { |
422 |
Object[] fields = ((DefaultListModel) getJFieldList() |
423 |
.getModel()).toArray(); |
424 |
|
425 |
Color[] colorScheme = colorCombo.getSelectedColors(); |
426 |
|
427 |
Color[] colors = new Color[colorScheme.length]; |
428 |
System.arraycopy(colorScheme, 0, colors, 0, colorScheme.length); |
429 |
for (Object field : fields) { |
430 |
getFieldsTable().addTableRecord(colorScheme[rand.nextInt(colorScheme.length)], (String) field, (String) field); |
431 |
((DefaultListModel) getJFieldList().getModel()).removeElement(field);
|
432 |
} |
433 |
}); |
434 |
} |
435 |
return addAllButton;
|
436 |
} |
437 |
|
438 |
/**
|
439 |
* This method initializes removeAllButton
|
440 |
*
|
441 |
* @return javax.swing.JButton
|
442 |
*/
|
443 |
private JButton getRemoveAllButton() { |
444 |
if (removeAllButton == null) { |
445 |
removeAllButton = new JButton(); |
446 |
removeAllButton.setPreferredSize(new Dimension(50, 40)); |
447 |
removeAllButton.setText("<<");
|
448 |
// removeAllButton
|
449 |
// .addActionListener(new java.awt.event.ActionListener() {
|
450 |
// public void actionPerformed(java.awt.event.ActionEvent e) {
|
451 |
// fillFieldNames();
|
452 |
// getFieldsTable().removeAllItems();
|
453 |
// actualizePreviewSymbol();
|
454 |
// }
|
455 |
// });
|
456 |
} |
457 |
return removeAllButton;
|
458 |
} |
459 |
|
460 |
private void fillFieldNames() { |
461 |
FeatureStore rs; |
462 |
((DefaultListModel) getJFieldList().getModel()).removeAllElements();
|
463 |
try {
|
464 |
rs = ((FLyrVect) layer).getFeatureStore(); |
465 |
ArrayList<String> names = new ArrayList<String>(); |
466 |
Iterator iterator = rs.getDefaultFeatureType().iterator();
|
467 |
DefaultListModel cM = new DefaultListModel(); |
468 |
while (iterator.hasNext()) {
|
469 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator |
470 |
.next(); |
471 |
if (descriptor.getDataType().isNumeric()) {
|
472 |
names.add(descriptor.getName()); |
473 |
cM.addElement(descriptor.getName()); |
474 |
} |
475 |
} |
476 |
|
477 |
getJFieldList().setModel(cM); |
478 |
|
479 |
} catch (DataException e) {
|
480 |
NotificationManager.addError( |
481 |
PluginServices.getText(this, "recovering_recordset"), e); |
482 |
} |
483 |
|
484 |
} |
485 |
|
486 |
private JPanel getButtons() { |
487 |
if (buttons == null) { |
488 |
FlowLayout flowLayout = new FlowLayout(); |
489 |
flowLayout.setHgap(5);
|
490 |
flowLayout.setAlignment(FlowLayout.CENTER);
|
491 |
flowLayout.setVgap(1);
|
492 |
buttons = new JPanel(); |
493 |
buttons.setPreferredSize(new Dimension(60, 50)); |
494 |
buttons.setLayout(flowLayout); |
495 |
buttons.add(getPCentral(), null);
|
496 |
} |
497 |
return buttons;
|
498 |
} |
499 |
|
500 |
private FieldsTable getFieldsTable() {
|
501 |
if (fieldsTable == null) { |
502 |
fieldsTable = new FieldsTable();
|
503 |
fieldsTable.setPreferredSize(new Dimension(250, 300)); |
504 |
// fieldsTable.addColorChange(new ColorChange() {
|
505 |
// public void actionChange() {
|
506 |
// // actualizePreviewSymbol();
|
507 |
// }
|
508 |
//
|
509 |
// });
|
510 |
} |
511 |
return fieldsTable;
|
512 |
} |
513 |
|
514 |
private JScrollPane getJScrollPane() { |
515 |
if (jScrollPane == null) { |
516 |
jScrollPane = new JScrollPane(); |
517 |
jScrollPane.setBorder(BorderFactory.createTitledBorder(null, |
518 |
PluginServices.getText(this, "fields"), |
519 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
520 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
521 |
Font.BOLD, 12), new Color(51, 51, 51))); |
522 |
jScrollPane.setPreferredSize(new Dimension(150, 150)); |
523 |
jScrollPane.setViewportView(getJFieldList()); |
524 |
} |
525 |
return jScrollPane;
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* This method initializes jFieldList
|
530 |
*
|
531 |
* @return javax.swing.JList
|
532 |
*/
|
533 |
private JList getJFieldList() { |
534 |
if (jFieldList == null) { |
535 |
DefaultListModel dlm = new DefaultListModel(); |
536 |
jFieldList = new JList(); |
537 |
jFieldList.setSize(new Dimension(150, 150)); |
538 |
jFieldList.setModel(dlm); |
539 |
} |
540 |
return jFieldList;
|
541 |
} |
542 |
|
543 |
public String getDescription() { |
544 |
return PluginServices.getText(this, "draw_bar_chart_for_each_feature"); |
545 |
} |
546 |
|
547 |
public ImageIcon getIcon() { |
548 |
return IconThemeHelper.getImageIcon("legend-bar-chart"); |
549 |
} |
550 |
|
551 |
/*
|
552 |
* (non-Javadoc)
|
553 |
*
|
554 |
* @see
|
555 |
* org.gvsig.app.project.documents.view.legend.gui.ILegendPanel#getLegend()
|
556 |
*/
|
557 |
public ILegend getLegend() {
|
558 |
if (auxLegend == null) { |
559 |
auxLegend = (IChartLegend) MapContextLocator.getMapContextManager() |
560 |
.createLegend(IChartLegend.BARSCHART_LEGEND_NAME); |
561 |
} |
562 |
auxLegend.setOutlineShow(getJCheckBox().isSelected()); |
563 |
auxLegend.setOutlineColor(getColorButton().getColor()); |
564 |
auxLegend.setOutlineWidth(getComboWidth().getInteger()); |
565 |
auxLegend.setIs3D(getCk3D().isSelected()); |
566 |
|
567 |
if (getFieldsTable() != null) { |
568 |
int rowCount = getFieldsTable().getRowCount();
|
569 |
if (rowCount > 0) { |
570 |
String[] fields = new String[rowCount]; |
571 |
String[] labels = new String[rowCount]; |
572 |
Color[] colors = new Color[rowCount]; |
573 |
int[] types = new int[rowCount]; |
574 |
for (int i = 0; i < fields.length; i++) { |
575 |
colors[i] = ((JPanel) getFieldsTable().getFieldValue(i, 0)) |
576 |
.getBackground(); |
577 |
fields[i] = (String) getFieldsTable().getFieldValue(i, 1); |
578 |
labels[i] = (String) getFieldsTable().getFieldValue(i, 2); |
579 |
//No es necesario para nada, pero si no lo inicializamos, peta el clonado de la leyenda (en AbstractClassifiedVectorLegend)
|
580 |
types[i] = DataTypes.STRING; |
581 |
} |
582 |
auxLegend.setClassifyingFieldNames(fields); |
583 |
//No es necesario para nada, pero si no lo inicializamos, peta el clonado de la leyenda (en AbstractClassifiedVectorLegend)
|
584 |
auxLegend.setClassifyingFieldTypes(types); |
585 |
auxLegend.setFields(fields); |
586 |
auxLegend.setLabels(labels); |
587 |
auxLegend.setColors(colors); |
588 |
|
589 |
if (auxLegend.getSizeOption() == IChartSymbol.SIZEFIELD) {
|
590 |
int classifyingCount = fields.length + 2; |
591 |
if (auxLegend.getFieldNormalize().equals("---")) { |
592 |
classifyingCount = fields.length + 1;
|
593 |
} |
594 |
String[] classifyingFields = new String[classifyingCount]; |
595 |
for (int i = 0; i < fields.length; i++) { |
596 |
classifyingFields[i] = fields[i]; |
597 |
} |
598 |
if (!auxLegend.getFieldNormalize().equals("---")) { |
599 |
classifyingFields[classifyingCount - 2] = auxLegend
|
600 |
.getFieldNormalize(); |
601 |
} |
602 |
classifyingFields[classifyingCount - 1] = auxLegend.getFieldSize();
|
603 |
|
604 |
auxLegend.setClassifyingFieldNames(classifyingFields); |
605 |
} else {
|
606 |
if (fields != null && fields.length > 0) { |
607 |
auxLegend.setClassifyingFieldNames(fields); |
608 |
} |
609 |
} |
610 |
// /////////////////////////////////////////////
|
611 |
double min = Double.MAX_VALUE; |
612 |
double max = Double.MIN_VALUE; |
613 |
|
614 |
if (auxLegend.getSizeOption() == IChartSymbol.SIZEFIELD) {
|
615 |
try {
|
616 |
FeatureStore fs = layer.getFeatureStore(); |
617 |
FeatureType ft = fs.getDefaultFeatureType(); |
618 |
FeatureAttributeDescriptor[] atts = ft
|
619 |
.getAttributeDescriptors(); |
620 |
ArrayList<String> auxNames = new ArrayList<String>(); |
621 |
FeatureSet fset = fs.getFeatureSet(); |
622 |
DisposableIterator it = fset.fastIterator(); |
623 |
long rows = fs.getFeatureCount();
|
624 |
int index = ft.getAttributeDescriptor(auxLegend.getFieldSize())
|
625 |
.getIndex(); |
626 |
while (it.hasNext()) {
|
627 |
Feature f = ((Feature) it.next()).getCopy(); |
628 |
double dob = f.getDouble(index);
|
629 |
if (dob < min) {
|
630 |
min = dob; |
631 |
} |
632 |
if (dob > max) {
|
633 |
max = dob; |
634 |
} |
635 |
} |
636 |
it.dispose(); |
637 |
auxLegend.setMinFeature(min); |
638 |
auxLegend.setMaxFeature(max); |
639 |
|
640 |
} catch (DataException e) {
|
641 |
// TODO Auto-generated catch block
|
642 |
e.printStackTrace(); |
643 |
} |
644 |
|
645 |
} else if (auxLegend.getSizeOption() == IChartSymbol.SIZESUM) { |
646 |
try {
|
647 |
|
648 |
FeatureStore fs = layer.getFeatureStore(); |
649 |
FeatureType ft = fs.getDefaultFeatureType(); |
650 |
FeatureAttributeDescriptor[] atts = ft
|
651 |
.getAttributeDescriptors(); |
652 |
ArrayList<String> auxNames = new ArrayList<String>(); |
653 |
FeatureSet fset = fs.getFeatureSet(); |
654 |
DisposableIterator it = fset.fastIterator(); |
655 |
long rows = fs.getFeatureCount();
|
656 |
String[] names = auxLegend.getClassifyingFieldNames(); |
657 |
int[] indexes = new int[names.length]; |
658 |
for (int i = 0; i < names.length; i++) { |
659 |
indexes[i] = ft.getAttributeDescriptor(names[i]).getIndex(); |
660 |
} |
661 |
|
662 |
while (it.hasNext()) {
|
663 |
Feature f = ((Feature) it.next()).getCopy(); |
664 |
double dob = 0; |
665 |
for (int i = 0; i < indexes.length; i++) { |
666 |
dob += f.getDouble(indexes[i]); |
667 |
} |
668 |
if (dob < min) {
|
669 |
min = dob; |
670 |
} |
671 |
if (dob > max) {
|
672 |
max = dob; |
673 |
} |
674 |
} |
675 |
it.dispose(); |
676 |
auxLegend.setMinFeature(min); |
677 |
auxLegend.setMaxFeature(max); |
678 |
|
679 |
} catch (DataException e) {
|
680 |
// TODO Auto-generated catch block
|
681 |
e.printStackTrace(); |
682 |
} |
683 |
|
684 |
} |
685 |
|
686 |
auxLegend.setOnlySelection(getCkOnlySelection().isSelected()); |
687 |
auxLegend.setIs3D(getCk3D().isSelected()); |
688 |
// ////////////////////////////////////////////
|
689 |
|
690 |
auxLegend.useDefaultSymbol(true);
|
691 |
|
692 |
// TODO: DEVOLVER LA LEYENDA CORRECTA!!!
|
693 |
// TODO: ESTO HAY QUE HACERLO BIEN. LA IDEA ES GENERAR CORRECTAMENTE
|
694 |
// EL CHARTDATASET, PERO NO CON LOS REQUIREDFIELDS.
|
695 |
// Ahora los campos son como las filas con las que trabajabamos
|
696 |
// antes.
|
697 |
IChartSymbol symbol = (IChartSymbol) MapContextLocator |
698 |
.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME); |
699 |
|
700 |
ChartManager cm = ChartLocator.getServiceManager().getChartManager(); |
701 |
ChartProperties props; |
702 |
try {
|
703 |
props = cm.createProperties("BarsChart");
|
704 |
if (auxLegend.is3D()) {
|
705 |
props.setChartDimension(true);
|
706 |
props.setChartRenderer("BarsChartRenderer3DBasic");
|
707 |
} else {
|
708 |
props.setChartDimension(false);
|
709 |
props.setChartRenderer("BarsChartRendererBasic");
|
710 |
} |
711 |
auxLegend.setColors(colors); |
712 |
|
713 |
props.setHasPlotOutline(auxLegend.isOutlineShow()); |
714 |
props.setIsLegendVisible(false);
|
715 |
props.setPlotBackgroundColor(auxLegend.getOutlineColor()); |
716 |
if (getJCheckBox().isSelected()) {
|
717 |
float alpha = colorButton.getAlpha() / 100; |
718 |
if (alpha > 1) { |
719 |
props.setPlotBackgroundAlpha(1.0f);
|
720 |
} else {
|
721 |
props.setPlotBackgroundAlpha(alpha); |
722 |
} |
723 |
} else {
|
724 |
props.setPlotBackgroundAlpha(0.0f);
|
725 |
} |
726 |
props.setIsMandatoryChart(jShowAxis.isSelected()); |
727 |
props.setIsXYPlotChart(false);
|
728 |
props.setChartDimension(auxLegend.is3D()); |
729 |
|
730 |
ChartService cs = cm.createChart(props); |
731 |
cs.setIsAChartSymbol(true);
|
732 |
|
733 |
// Fijamos los colores dentro del ChartSymbol para hacerlo solo una vez
|
734 |
if (cs.getRenderer() != null) { |
735 |
List<Color> colorsArray = new ArrayList<Color>(); |
736 |
for (int i = 0; i < fields.length; i++) { |
737 |
cs.getRenderer().setSeriesPaint(i, auxLegend.getColors()[i]); |
738 |
colorsArray.add(auxLegend.getColors()[i]); |
739 |
} |
740 |
cs.setCategoriesPaint(colorsArray); |
741 |
} |
742 |
|
743 |
//auxLegend.setSize(260);
|
744 |
// TODO: REVISAR QU? PASA CUANDO HAY SELECCION. EL SIMBOLO QUE DEVUELVE NO ES CORRECTO
|
745 |
// symbol.setColor(Color.BLACK);
|
746 |
symbol.setChart(cs); |
747 |
auxLegend.setDefaultSymbol(symbol); |
748 |
|
749 |
} catch (ServiceException e) {
|
750 |
// TODO Auto-generated catch block
|
751 |
e.printStackTrace(); |
752 |
} |
753 |
|
754 |
} |
755 |
} |
756 |
|
757 |
this.theLegend = auxLegend;
|
758 |
return theLegend;
|
759 |
} |
760 |
|
761 |
public Class getLegendClass() { |
762 |
return BarsChartLegend.class;
|
763 |
} |
764 |
|
765 |
public JPanel getPanel() { |
766 |
return this; |
767 |
} |
768 |
|
769 |
public Class getParentClass() { |
770 |
return MultipleAttributes.class;
|
771 |
} |
772 |
|
773 |
public String getTitle() { |
774 |
return PluginServices.getText(this, "bar_legend"); |
775 |
} |
776 |
|
777 |
public boolean isSuitableFor(FLayer layer) { |
778 |
return (layer instanceof FLyrVect); |
779 |
} |
780 |
|
781 |
public void setData(FLayer layer, ILegend legend) { |
782 |
this.layer = (FLyrVect) layer;
|
783 |
try {
|
784 |
shapeType = this.layer.getShapeType();
|
785 |
} catch (ReadException e) {
|
786 |
e.printStackTrace(); |
787 |
} |
788 |
//getBackgroundSymbol().setShapeType(shapeType);
|
789 |
|
790 |
fieldsTable = getFieldsTable(); |
791 |
|
792 |
fieldsTable.setSize(new Dimension(235, 129)); |
793 |
fillFieldNames(); |
794 |
|
795 |
fieldsTable.removeAllItems(); |
796 |
|
797 |
if (legend instanceof IBarsChartLegend) { |
798 |
// TODO: PROVISIONAL. CREAMOS SIEMPRE LA LEYENDA PORQUE NO LA PODEMOS CLONAR TODAVIA.
|
799 |
// auxLegend = (IChartLegend) legend.cloneLegend();
|
800 |
IBarsChartLegend barsChartLegend = (IBarsChartLegend) legend; |
801 |
|
802 |
getJCheckBox().setSelected(barsChartLegend.isOutlineShow()); |
803 |
getColorButton().setColor(barsChartLegend.getOutlineColor()); |
804 |
getComboWidth().setInteger(barsChartLegend.getOutlineWidth()); |
805 |
|
806 |
getCk3D().setSelected(barsChartLegend.is3D()); |
807 |
getCkOnlySelection().setSelected(barsChartLegend.isOnlySelection()); |
808 |
|
809 |
String[] fields = barsChartLegend.getClassifyingFieldNames(); |
810 |
String[] labels = barsChartLegend.getFieldLabels(); |
811 |
if (fields != null) { |
812 |
if (labels != null && labels.length != fields.length) { |
813 |
String[] aux = new String[fields.length]; |
814 |
for (int i = 0; i < fields.length; i++) { |
815 |
aux[i] = fields[i]; |
816 |
} |
817 |
labels = aux; |
818 |
} |
819 |
Color[] colors = new Color[fields.length]; |
820 |
for (int i = 0; i < fields.length; i++) { |
821 |
colors[i] = ((IBarsChartLegend) legend).getSymbolByValue(fields[i]).getColor(); |
822 |
} |
823 |
|
824 |
if (colors != null) { |
825 |
getFieldsTable().fillTableFromSymbolList(colors, fields, labels); |
826 |
} |
827 |
// getPreviewChart().setSections(fields, colors);
|
828 |
for (int i = 0; i < fields.length; i++) { |
829 |
((DefaultListModel) getJFieldList().getModel())
|
830 |
.removeElement(fields[i]); |
831 |
} |
832 |
} |
833 |
} |
834 |
} |
835 |
|
836 |
private boolean isNumericField(int fieldType) { |
837 |
switch (fieldType) {
|
838 |
case Types.BIGINT: |
839 |
case Types.DECIMAL: |
840 |
case Types.DOUBLE: |
841 |
case Types.FLOAT: |
842 |
case Types.INTEGER: |
843 |
case Types.NUMERIC: |
844 |
case Types.REAL: |
845 |
case Types.SMALLINT: |
846 |
case Types.TINYINT: |
847 |
return true; |
848 |
default:
|
849 |
return false; |
850 |
} |
851 |
|
852 |
} |
853 |
|
854 |
/**
|
855 |
* This method initializes ckOnlySelection
|
856 |
*
|
857 |
* @return javax.swing.JCheckBox
|
858 |
*/
|
859 |
private JCheckBox getCkOnlySelection() { |
860 |
if (ckOnlySelection == null) { |
861 |
ckOnlySelection = new JCheckBox(); |
862 |
ckOnlySelection.setText(PluginServices.getText(this,
|
863 |
"only_selection"));
|
864 |
} |
865 |
return ckOnlySelection;
|
866 |
} |
867 |
|
868 |
} // @jve:decl-index=0:visual-constraint="10,10"
|