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 / ChartLegendPanelPie.java @ 99
History | View | Annotate | Download (32.6 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.Random; |
14 |
|
15 |
import javax.swing.BorderFactory; |
16 |
import javax.swing.DefaultListModel; |
17 |
import javax.swing.ImageIcon; |
18 |
import javax.swing.JButton; |
19 |
import javax.swing.JCheckBox; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JList; |
22 |
import javax.swing.JPanel; |
23 |
import javax.swing.JScrollPane; |
24 |
import javax.swing.border.TitledBorder; |
25 |
import javax.swing.event.ChangeEvent; |
26 |
import javax.swing.event.ChangeListener; |
27 |
|
28 |
import org.gvsig.andami.IconThemeHelper; |
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.messages.NotificationManager; |
31 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
32 |
import org.gvsig.app.gui.styling.JComboBoxColorScheme; |
33 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
34 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
35 |
import org.gvsig.app.project.documents.view.legend.gui.MultipleAttributes; |
36 |
import org.gvsig.chart.ChartLocator; |
37 |
import org.gvsig.chart.ChartManager; |
38 |
import org.gvsig.chart.ChartProperties; |
39 |
import org.gvsig.chart.ChartService; |
40 |
import org.gvsig.chart.legend.IChartLegend; |
41 |
import org.gvsig.chart.legend.IPieChartLegend; |
42 |
import org.gvsig.chart.legend.symbols.IChartSymbol; |
43 |
import org.gvsig.fmap.dal.exception.DataException; |
44 |
import org.gvsig.fmap.dal.exception.ReadException; |
45 |
import org.gvsig.fmap.dal.feature.Feature; |
46 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
47 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
48 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
49 |
import org.gvsig.fmap.dal.feature.FeatureType; |
50 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
51 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
52 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
54 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
55 |
import org.gvsig.project.documents.view.legend.PieChartLegend; |
56 |
import org.gvsig.tools.dispose.DisposableIterator; |
57 |
import org.gvsig.tools.service.ServiceException; |
58 |
|
59 |
public class ChartLegendPanelPie extends JPanel implements ILegendPanel { |
60 |
|
61 |
/**
|
62 |
*
|
63 |
*/
|
64 |
private static final long serialVersionUID = -5009857246030623420L; |
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 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 ChartLegendPanelPie() {
|
110 |
super();
|
111 |
initialize(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* This method initializes this
|
116 |
*
|
117 |
* @return void
|
118 |
*/
|
119 |
private void initialize() { |
120 |
this.setSize(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.setEnabled(false);
|
159 |
ck3D.setText(PluginServices.getText(this, "display_3d")); |
160 |
ck3D.addChangeListener(new ChangeListener() { |
161 |
public void stateChanged(ChangeEvent e) { |
162 |
// getPreviewChart().set3D(ck3D.isSelected());
|
163 |
// getPreviewChart().repaint();
|
164 |
// auxLegend.setIs3D(ck3D.isSelected());
|
165 |
} |
166 |
|
167 |
}); |
168 |
} |
169 |
return ck3D;
|
170 |
} |
171 |
|
172 |
private JPanel getOutlinePanel() { |
173 |
if (outlinePanel == null) { |
174 |
jLabel = new JLabel(); |
175 |
jLabel.setText(PluginServices.getText(this, "color")); |
176 |
outlinePanel = new JPanel(); |
177 |
outlinePanel.setLayout(new BorderLayout()); |
178 |
outlinePanel.setBorder(BorderFactory.createTitledBorder(null, |
179 |
PluginServices.getText(this, "background_color"), |
180 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
181 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
182 |
Font.BOLD, 12), new Color(51, 51, 51))); |
183 |
outlinePanel.setPreferredSize(new Dimension(150, 115)); |
184 |
outlinePanel.add(getJCheckBox(), BorderLayout.NORTH);
|
185 |
outlinePanel.add(getJPanel(), BorderLayout.CENTER);
|
186 |
//outlinePanel.add(getJPanel1(), BorderLayout.SOUTH);
|
187 |
} |
188 |
return outlinePanel;
|
189 |
} |
190 |
|
191 |
private JPanel getJPanel() { |
192 |
if (jPanel == null) { |
193 |
jPanel = new JPanel(); |
194 |
jPanel.setLayout(new FlowLayout()); |
195 |
jPanel.add(jLabel, null);
|
196 |
jPanel.add(getColorButton(), null);
|
197 |
} |
198 |
return jPanel;
|
199 |
} |
200 |
|
201 |
private ColorChooserPanel getColorButton() {
|
202 |
if (colorButton == null) { |
203 |
colorButton = new ColorChooserPanel(true); |
204 |
colorButton.setColor(Color.black);
|
205 |
colorButton.addActionListener(new ActionListener() { |
206 |
public void actionPerformed(ActionEvent e) { |
207 |
// getPreviewChart().setOutLineColor(colorButton.getColor());
|
208 |
// getPreviewChart().repaint();
|
209 |
auxLegend.setOutlineColor(colorButton.getColor()); |
210 |
} |
211 |
}); |
212 |
} |
213 |
return colorButton;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* This method initializes jPanel1
|
218 |
*
|
219 |
* @return javax.swing.JPanel
|
220 |
*/
|
221 |
private JPanel getJPanel1() { |
222 |
if (jPanel1 == null) { |
223 |
jLabel1 = new JLabel(); |
224 |
jLabel1.setText(PluginServices.getText(this, "width")); |
225 |
jPanel1 = new JPanel(); |
226 |
jPanel1.setLayout(new FlowLayout()); |
227 |
jPanel1.add(jLabel1, null);
|
228 |
jPanel1.add(getComboWidth(), null);
|
229 |
} |
230 |
return jPanel1;
|
231 |
} |
232 |
|
233 |
private JNumberSpinner getComboWidth() {
|
234 |
if (comboWidth == null) { |
235 |
comboWidth = new JNumberSpinner(String.valueOf(1), 3, 0, Integer.MAX_VALUE, 1); |
236 |
|
237 |
comboWidth.addActionListener(new ActionListener() { |
238 |
public void actionPerformed(ActionEvent e) { |
239 |
// getPreviewChart().setOutlineWidth(comboWidth.getInteger());
|
240 |
// getPreviewChart().repaint();
|
241 |
auxLegend.setOutlineWidth(comboWidth.getInteger()); |
242 |
} |
243 |
|
244 |
}); |
245 |
} |
246 |
return comboWidth;
|
247 |
} |
248 |
|
249 |
private JCheckBox getShowAxis() { |
250 |
if (jShowAxis == null) { |
251 |
jShowAxis = new JCheckBox(); |
252 |
jShowAxis.setEnabled(false);
|
253 |
jShowAxis.setText(PluginServices.getText(this, "show_axis")); |
254 |
} |
255 |
return jShowAxis;
|
256 |
} |
257 |
|
258 |
private JCheckBox getJCheckBox() { |
259 |
if (jCheckBox == null) { |
260 |
jCheckBox = new JCheckBox(); |
261 |
jCheckBox.setText(PluginServices.getText(this, "Show")); |
262 |
jCheckBox.addChangeListener(new ChangeListener() { |
263 |
public void stateChanged(ChangeEvent e) { |
264 |
// getPreviewChart().setOutlineShow(jCheckBox.isSelected());
|
265 |
// getPreviewChart().repaint();
|
266 |
auxLegend.setOutlineShow(jCheckBox.isSelected()); |
267 |
} |
268 |
|
269 |
}); |
270 |
} |
271 |
return jCheckBox;
|
272 |
} |
273 |
|
274 |
private JPanel getSouthPanel() { |
275 |
if (southPanel == null) { |
276 |
southPanel = new JPanel(); |
277 |
southPanel.setLayout(new FlowLayout()); |
278 |
southPanel.setPreferredSize(new Dimension(241, 90)); |
279 |
southPanel.add(getSymbolPanel(), null);
|
280 |
southPanel.add(getNorthPanel(), null);
|
281 |
southPanel.add(getBSize(), null);
|
282 |
southPanel.add(getCkOnlySelection(), null);
|
283 |
} |
284 |
return southPanel;
|
285 |
} |
286 |
|
287 |
private JPanel getSymbolPanel() { |
288 |
if (symbolPanel == null) { |
289 |
lBackgroundSymbol = new JLabel(); |
290 |
lBackgroundSymbol.setText(PluginServices.getText(this,
|
291 |
"background_symbol"));
|
292 |
lBackgroundSymbol.setText(PluginServices.getText(this,
|
293 |
"show_axis"));
|
294 |
symbolPanel = new JPanel(); |
295 |
symbolPanel.setLayout(new FlowLayout()); |
296 |
symbolPanel.setPreferredSize(new Dimension(241, 40)); |
297 |
// symbolPanel.add(lBackgroundSymbol, null);
|
298 |
// symbolPanel.add(getBackgroundSymbol(), null);
|
299 |
symbolPanel.add(getShowAxis(), null);
|
300 |
|
301 |
} |
302 |
return symbolPanel;
|
303 |
} |
304 |
|
305 |
// private PreviewPieSymbol getPreviewChart() {
|
306 |
// if (previewPanel == null) {
|
307 |
// previewPanel = new PreviewPieSymbol();
|
308 |
// previewPanel.setLayout(new BorderLayout());
|
309 |
// previewPanel.setBorder(BorderFactory.createTitledBorder(null,
|
310 |
// PluginServices.getText(this, "preview_chart"),
|
311 |
// TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new
|
312 |
// Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
|
313 |
// previewPanel.setPreferredSize(new Dimension(150, 100));
|
314 |
// }
|
315 |
// return previewPanel;
|
316 |
// }
|
317 |
|
318 |
private JSymbolPreviewButton getBackgroundSymbol() {
|
319 |
if (bSymbolBackground == null) { |
320 |
bSymbolBackground = new JSymbolPreviewButton(shapeType);
|
321 |
bSymbolBackground.setPreferredSize(new Dimension(110, 20)); |
322 |
bSymbolBackground.addActionListener(new ActionListener() { |
323 |
public void actionPerformed(ActionEvent e) { |
324 |
// getPreviewChart().setBackgroundSymbol(bSymbolBackground.getSymbol());
|
325 |
// getPreviewChart().repaint();
|
326 |
} |
327 |
}); |
328 |
} |
329 |
return bSymbolBackground;
|
330 |
} |
331 |
|
332 |
private JButton getBSize() { |
333 |
if (bSize == null) { |
334 |
bSize = new JButton(); |
335 |
bSize.setText(PluginServices.getText(this, "size")); |
336 |
bSize.setPreferredSize(new Dimension(100, 30)); |
337 |
bSize.setMaximumSize(new Dimension(100, 30)); |
338 |
bSize.addActionListener(new ActionListener() { |
339 |
public void actionPerformed(ActionEvent e) { |
340 |
PluginServices.getMDIManager().addCentredWindow( |
341 |
new SizePanel(layer, auxLegend));
|
342 |
} |
343 |
|
344 |
}); |
345 |
} |
346 |
return bSize;
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* This method initializes centerPanel
|
351 |
*
|
352 |
* @return javax.swing.JPanel
|
353 |
*/
|
354 |
private JPanel getCenterPanel() { |
355 |
if (centerPanel == null) { |
356 |
centerPanel = new JPanel(); |
357 |
centerPanel.setLayout(new BorderLayout()); |
358 |
centerPanel.setPreferredSize(new Dimension(350, 300)); |
359 |
centerPanel.add(getJScrollPane(), BorderLayout.WEST);
|
360 |
centerPanel.add(getButtons(), BorderLayout.CENTER);
|
361 |
centerPanel.add(getFieldsTable(), java.awt.BorderLayout.EAST); |
362 |
} |
363 |
return centerPanel;
|
364 |
} |
365 |
|
366 |
private JPanel getPCentral() { |
367 |
if (pCentral == null) { |
368 |
pCentral = new JPanel(); |
369 |
pCentral.setLayout(new FlowLayout()); |
370 |
pCentral.setPreferredSize(new Dimension(50, 185)); |
371 |
pCentral.add(getRemoveAllButton(), null);
|
372 |
pCentral.add(getAddAllButton(), null);
|
373 |
pCentral.add(getRemoveButton(), null);
|
374 |
pCentral.add(getAddButton(), null);
|
375 |
} |
376 |
return pCentral;
|
377 |
} |
378 |
|
379 |
private JButton getAddButton() { |
380 |
if (addButton == null) { |
381 |
addButton = new JButton(); |
382 |
addButton.setText(">");
|
383 |
addButton.setPreferredSize(new Dimension(50, 40)); |
384 |
addButton.addActionListener(new java.awt.event.ActionListener() {
|
385 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
386 |
Object[] fields = getJFieldList().getSelectedValues(); |
387 |
Color[] colorScheme = colorCombo.getSelectedColors(); |
388 |
|
389 |
Color[] colors = new Color[colorScheme.length]; |
390 |
for (int i = 0; i < colorScheme.length; i++) { |
391 |
colors[i] = colorScheme[i]; |
392 |
} |
393 |
for (int i = 0; i < fields.length; i++) { |
394 |
getFieldsTable().addTableRecord( |
395 |
colorScheme[rand.nextInt(colorScheme.length)], |
396 |
(String) fields[i], (String) fields[i]); |
397 |
((DefaultListModel) getJFieldList().getModel())
|
398 |
.removeElement(fields[i]); |
399 |
} |
400 |
actualizePreviewSymbol(); |
401 |
} |
402 |
}); |
403 |
} |
404 |
return addButton;
|
405 |
} |
406 |
|
407 |
/**
|
408 |
* This method initializes northPanel
|
409 |
*
|
410 |
* @return javax.swing.JPanel
|
411 |
*/
|
412 |
private JPanel getNorthPanel() { |
413 |
if (northPanel == null) { |
414 |
lColorSchema = new JLabel(); |
415 |
lColorSchema.setText(PluginServices.getText(this, "color_schema")); |
416 |
northPanel = new JPanel(); |
417 |
northPanel.setLayout(new FlowLayout()); |
418 |
northPanel.add(lColorSchema, null);
|
419 |
northPanel.add(getColorCombo()); |
420 |
} |
421 |
return northPanel;
|
422 |
} |
423 |
|
424 |
private JComboBoxColorScheme getColorCombo() {
|
425 |
if (colorCombo == null) { |
426 |
colorCombo = new JComboBoxColorScheme(false); |
427 |
} |
428 |
return colorCombo;
|
429 |
} |
430 |
|
431 |
/**
|
432 |
* This method initializes removeButton
|
433 |
*
|
434 |
* @return javax.swing.JButton
|
435 |
*/
|
436 |
private JButton getRemoveButton() { |
437 |
if (removeButton == null) { |
438 |
removeButton = new JButton(); |
439 |
removeButton.setPreferredSize(new Dimension(50, 40)); |
440 |
removeButton.setText("<");
|
441 |
removeButton.addActionListener(new java.awt.event.ActionListener() {
|
442 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
443 |
int[] index = getFieldsTable().getSelectedRows(); |
444 |
String[] fields = new String[index.length]; |
445 |
for (int i = 0; i < index.length; i++) { |
446 |
fields[i] = (String) getFieldsTable().getFieldValue(
|
447 |
index[i], 1);
|
448 |
} |
449 |
for (int i = 0; i < fields.length; i++) { |
450 |
((DefaultListModel) getJFieldList().getModel())
|
451 |
.addElement(fields[i]); |
452 |
} |
453 |
getFieldsTable().removeSelectedRows(); |
454 |
actualizePreviewSymbol(); |
455 |
} |
456 |
}); |
457 |
} |
458 |
return removeButton;
|
459 |
} |
460 |
|
461 |
/**
|
462 |
* This method initializes addAllButton
|
463 |
*
|
464 |
* @return javax.swing.JButton
|
465 |
*/
|
466 |
private JButton getAddAllButton() { |
467 |
if (addAllButton == null) { |
468 |
addAllButton = new JButton(); |
469 |
addAllButton.setPreferredSize(new Dimension(50, 40)); |
470 |
addAllButton.setText(">>");
|
471 |
addAllButton.addActionListener(new java.awt.event.ActionListener() {
|
472 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
473 |
Object[] fields = ((DefaultListModel) getJFieldList() |
474 |
.getModel()).toArray(); |
475 |
|
476 |
Color[] colorScheme = colorCombo.getSelectedColors(); |
477 |
|
478 |
Color[] colors = new Color[colorScheme.length]; |
479 |
for (int i = 0; i < colorScheme.length; i++) { |
480 |
colors[i] = colorScheme[i]; |
481 |
} |
482 |
for (int i = 0; i < fields.length; i++) { |
483 |
getFieldsTable().addTableRecord( |
484 |
colorScheme[rand.nextInt(colorScheme.length)], |
485 |
(String) fields[i], (String) fields[i]); |
486 |
((DefaultListModel) getJFieldList().getModel())
|
487 |
.removeElement(fields[i]); |
488 |
} |
489 |
actualizePreviewSymbol(); |
490 |
} |
491 |
}); |
492 |
} |
493 |
return addAllButton;
|
494 |
} |
495 |
|
496 |
private void actualizePreviewSymbol() { |
497 |
int count = getFieldsTable().getRowCount();
|
498 |
String[] fieldsTable = new String[count]; |
499 |
for (int i = 0; i < count; i++) { |
500 |
fieldsTable[i] = (String) getFieldsTable().getFieldValue(i, 1); |
501 |
} |
502 |
String[] labelsTable = new String[count]; |
503 |
for (int i = 0; i < count; i++) { |
504 |
labelsTable[i] = (String) getFieldsTable().getFieldValue(i, 2); |
505 |
} |
506 |
Color[] colorsTable = new Color[count]; |
507 |
for (int i = 0; i < count; i++) { |
508 |
colorsTable[i] = ((JPanel) getFieldsTable().getFieldValue(i, 0)) |
509 |
.getBackground(); |
510 |
} |
511 |
// getPreviewChart().setSections(fieldsTable, colorsTable);
|
512 |
// getPreviewChart().repaint();
|
513 |
// auxLegend.setFieldNames(fieldsTable);
|
514 |
// auxLegend.setLabels(labelsTable);
|
515 |
// auxLegend.setColors(colorsTable);
|
516 |
|
517 |
} |
518 |
|
519 |
/**
|
520 |
* This method initializes removeAllButton
|
521 |
*
|
522 |
* @return javax.swing.JButton
|
523 |
*/
|
524 |
private JButton getRemoveAllButton() { |
525 |
if (removeAllButton == null) { |
526 |
removeAllButton = new JButton(); |
527 |
removeAllButton.setPreferredSize(new Dimension(50, 40)); |
528 |
removeAllButton.setText("<<");
|
529 |
removeAllButton |
530 |
.addActionListener(new java.awt.event.ActionListener() {
|
531 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
532 |
fillFieldNames(); |
533 |
getFieldsTable().removeAllItems(); |
534 |
actualizePreviewSymbol(); |
535 |
} |
536 |
}); |
537 |
} |
538 |
return removeAllButton;
|
539 |
} |
540 |
|
541 |
private void fillFieldNames() { |
542 |
FeatureStore rs; |
543 |
((DefaultListModel) getJFieldList().getModel()).removeAllElements();
|
544 |
try {
|
545 |
rs = ((FLyrVect) layer).getFeatureStore(); |
546 |
ArrayList<String> names = new ArrayList<String>(); |
547 |
Iterator iterator = rs.getDefaultFeatureType().iterator();
|
548 |
DefaultListModel cM = new DefaultListModel(); |
549 |
while (iterator.hasNext()) {
|
550 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator |
551 |
.next(); |
552 |
if (descriptor.getDataType().isNumeric()) {
|
553 |
names.add(descriptor.getName()); |
554 |
cM.addElement(descriptor.getName()); |
555 |
} |
556 |
} |
557 |
|
558 |
getJFieldList().setModel(cM); |
559 |
|
560 |
} catch (DataException e) {
|
561 |
NotificationManager.addError( |
562 |
PluginServices.getText(this, "recovering_recordset"), e); |
563 |
} |
564 |
|
565 |
} |
566 |
|
567 |
private JPanel getButtons() { |
568 |
if (buttons == null) { |
569 |
FlowLayout flowLayout = new FlowLayout(); |
570 |
flowLayout.setHgap(5);
|
571 |
flowLayout.setAlignment(FlowLayout.CENTER);
|
572 |
flowLayout.setVgap(1);
|
573 |
buttons = new JPanel(); |
574 |
buttons.setPreferredSize(new Dimension(60, 50)); |
575 |
buttons.setLayout(flowLayout); |
576 |
buttons.add(getPCentral(), null);
|
577 |
} |
578 |
return buttons;
|
579 |
} |
580 |
|
581 |
private FieldsTable getFieldsTable() {
|
582 |
if (fieldsTable == null) { |
583 |
fieldsTable = new FieldsTable();
|
584 |
fieldsTable.setPreferredSize(new Dimension(250, 300)); |
585 |
fieldsTable.addColorChange(new ColorChange() {
|
586 |
public void actionChange() { |
587 |
// actualizePreviewSymbol();
|
588 |
} |
589 |
|
590 |
}); |
591 |
} |
592 |
return fieldsTable;
|
593 |
} |
594 |
|
595 |
private JScrollPane getJScrollPane() { |
596 |
if (jScrollPane == null) { |
597 |
jScrollPane = new JScrollPane(); |
598 |
jScrollPane.setBorder(BorderFactory.createTitledBorder(null, |
599 |
PluginServices.getText(this, "fields"), |
600 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
601 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
602 |
Font.BOLD, 12), new Color(51, 51, 51))); |
603 |
jScrollPane.setPreferredSize(new Dimension(150, 150)); |
604 |
jScrollPane.setViewportView(getJFieldList()); |
605 |
} |
606 |
return jScrollPane;
|
607 |
} |
608 |
|
609 |
/**
|
610 |
* This method initializes jFieldList
|
611 |
*
|
612 |
* @return javax.swing.JList
|
613 |
*/
|
614 |
private JList getJFieldList() { |
615 |
if (jFieldList == null) { |
616 |
DefaultListModel dlm = new DefaultListModel(); |
617 |
jFieldList = new JList(); |
618 |
jFieldList.setSize(new Dimension(150, 150)); |
619 |
jFieldList.setModel(dlm); |
620 |
} |
621 |
return jFieldList;
|
622 |
} |
623 |
|
624 |
// private ChartDataSet createDataSet() {
|
625 |
// ChartDataSet dataSet = ChartLocator.getServiceManager()
|
626 |
// .getChartManager().createChartDataSet();
|
627 |
// Object[] key = { "McPato2", "BurgerRey2", "McPato2", "BurgerRey2",
|
628 |
// "BurgerRey2", "McPato2", "McPato2", "BurgerRey2", "McPato2",
|
629 |
// "BurgerRey2" };
|
630 |
// Object[] y = { 1000, "500", 2000, 1000, 3000, 1500, 4000, 2000, 5000,
|
631 |
// "2500" };
|
632 |
// Object[] x = { 5, 5, 4, 4, "cat3", "xS3", 6, 6, 1, 1 };
|
633 |
//
|
634 |
// ArrayList<Object> auxX = new ArrayList<Object>();
|
635 |
// ArrayList<Object> auxY = new ArrayList<Object>();
|
636 |
// ArrayList<Object> auxKey = new ArrayList<Object>();
|
637 |
// for (int i = 0; i < y.length; i++) {
|
638 |
// auxKey.add(key[i]);
|
639 |
// auxX.add(x[i]);
|
640 |
// auxY.add(y[i]);
|
641 |
// }
|
642 |
//
|
643 |
// dataSet.setKeyField("groupby");
|
644 |
// dataSet.setColumnField("series");
|
645 |
// dataSet.setRowField("categories");
|
646 |
//
|
647 |
// // dataSet.addData("groupby", auxKey.iterator());
|
648 |
// dataSet.addData("IDARC", auxX.iterator());
|
649 |
// dataSet.addData("PCT", auxY.iterator());
|
650 |
//
|
651 |
// return dataSet;
|
652 |
// }
|
653 |
//
|
654 |
// protected void createTestLegend() {
|
655 |
// System.out.println("Creando leyenda de prueba.");
|
656 |
// this.theLegend = (IChartLegend) MapContextLocator
|
657 |
// .getMapContextManager().createLegend(IChartLegend.PIECHART_LEGEND_NAME);
|
658 |
//
|
659 |
// IChartSymbol symbol = (IChartSymbol) MapContextLocator
|
660 |
// .getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME);
|
661 |
//
|
662 |
// ChartManager cm = ChartLocator.getServiceManager().getChartManager();
|
663 |
// ChartProperties props;
|
664 |
// try {
|
665 |
// props = cm.createProperties("PieChart");
|
666 |
// int iF = 0;
|
667 |
// FeatureType ft = layer.getFeatureStore().getDefaultFeatureType();
|
668 |
// FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
|
669 |
// ArrayList<String> auxNames = new ArrayList<String>();
|
670 |
// // Buscamos tantos campos num?ricos como requierdFields (esto es una
|
671 |
// // prueba, obviamente)
|
672 |
// List<RequiredField> rqfs = props.getRequiredFields();
|
673 |
// for (int i = 0; i < atts.length; i++) {
|
674 |
// if (atts[i].getDataType().isNumeric()) {
|
675 |
// auxNames.add(atts[i].getName());
|
676 |
// rqfs.get(iF).setValue(atts[i].getName());
|
677 |
// iF++;
|
678 |
// if (iF >= props.getRequiredFields().size())
|
679 |
// break;
|
680 |
// }
|
681 |
// }
|
682 |
// String[] fieldNames = auxNames.toArray(new String[0]);
|
683 |
// // fieldNames[0] = "IDARC";
|
684 |
// // fieldNames[1] = "PCT";
|
685 |
// // fieldNames[2] = "COST";
|
686 |
// theLegend.setClassifyingFieldNames(fieldNames);
|
687 |
//
|
688 |
// // for (RequiredField rqf : props.getRequiredFields()) {
|
689 |
// // rqf.setValue(fieldNames[iF++]);
|
690 |
// // }
|
691 |
// ChartService cs = cm.createChart(props);
|
692 |
// ChartDataSet ds = createDataSet();
|
693 |
// cs.setChartDataSet(ds);
|
694 |
// symbol.setChart(cs);
|
695 |
// symbol.setSize(130);
|
696 |
// theLegend.setDefaultSymbol(symbol);
|
697 |
// theLegend.addSymbol("1", symbol);
|
698 |
//
|
699 |
// } catch (ServiceException e) {
|
700 |
// // TODO Auto-generated catch block
|
701 |
// e.printStackTrace();
|
702 |
// } catch (DataException e) {
|
703 |
// // TODO Auto-generated catch block
|
704 |
// e.printStackTrace();
|
705 |
// }
|
706 |
//
|
707 |
// }
|
708 |
|
709 |
public String getDescription() { |
710 |
return PluginServices.getText(this, "draw_bar_chart_for_each_feature"); |
711 |
} |
712 |
|
713 |
public ImageIcon getIcon() { |
714 |
return IconThemeHelper.getImageIcon("legend-pie-chart"); |
715 |
} |
716 |
|
717 |
/*
|
718 |
* (non-Javadoc)
|
719 |
*
|
720 |
* @see
|
721 |
* org.gvsig.app.project.documents.view.legend.gui.ILegendPanel#getLegend()
|
722 |
*/
|
723 |
public ILegend getLegend() {
|
724 |
if (auxLegend == null) { |
725 |
auxLegend = (IChartLegend) MapContextLocator.getMapContextManager() |
726 |
.createLegend(IChartLegend.PIECHART_LEGEND_NAME); |
727 |
} |
728 |
//ISymbol backgroundSymbol = getBackgroundSymbol().getSymbol();
|
729 |
//auxLegend.setBackgroundSymbol(backgroundSymbol);
|
730 |
auxLegend.setOutlineShow(getJCheckBox().isSelected()); |
731 |
auxLegend.setOutlineColor(getColorButton().getColor()); |
732 |
auxLegend.setOutlineWidth(getComboWidth().getInteger()); |
733 |
auxLegend.setIs3D(getCk3D().isSelected()); |
734 |
|
735 |
int rowCount = getFieldsTable().getRowCount();
|
736 |
String[] fields = new String[rowCount]; |
737 |
String[] labels = new String[rowCount]; |
738 |
Color[] colors = new Color[rowCount]; |
739 |
for (int i = 0; i < fields.length; i++) { |
740 |
colors[i] = ((JPanel) getFieldsTable().getFieldValue(i, 0)) |
741 |
.getBackground(); |
742 |
fields[i] = (String) getFieldsTable().getFieldValue(i, 1); |
743 |
labels[i] = (String) getFieldsTable().getFieldValue(i, 2); |
744 |
} |
745 |
auxLegend.setClassifyingFieldNames(fields); |
746 |
auxLegend.setFields(fields); |
747 |
auxLegend.setLabels(labels); |
748 |
auxLegend.setColors(colors); |
749 |
|
750 |
if (auxLegend.getSizeOption() == IChartSymbol.SIZEFIELD) {
|
751 |
int classifyingCount = fields.length + 2; |
752 |
if (auxLegend.getFieldNormalize().equals("---")) { |
753 |
classifyingCount = fields.length + 1;
|
754 |
} |
755 |
String[] classifyingFields = new String[classifyingCount]; |
756 |
for (int i = 0; i < fields.length; i++) { |
757 |
classifyingFields[i] = fields[i]; |
758 |
} |
759 |
if (!auxLegend.getFieldNormalize().equals("---")) { |
760 |
classifyingFields[classifyingCount - 2] = auxLegend
|
761 |
.getFieldNormalize(); |
762 |
} |
763 |
classifyingFields[classifyingCount - 1] = auxLegend.getFieldSize();
|
764 |
|
765 |
auxLegend.setClassifyingFieldNames(classifyingFields); |
766 |
} else {
|
767 |
if (fields != null && fields.length > 0) |
768 |
auxLegend.setClassifyingFieldNames(fields); |
769 |
} |
770 |
// /////////////////////////////////////////////
|
771 |
double min = Double.MAX_VALUE; |
772 |
double max = Double.MIN_VALUE; |
773 |
|
774 |
if (auxLegend.getSizeOption() == IChartSymbol.SIZEFIELD) {
|
775 |
try {
|
776 |
FeatureStore fs = layer.getFeatureStore(); |
777 |
FeatureType ft = fs.getDefaultFeatureType(); |
778 |
FeatureAttributeDescriptor[] atts = ft
|
779 |
.getAttributeDescriptors(); |
780 |
ArrayList<String> auxNames = new ArrayList<String>(); |
781 |
FeatureSet fset = fs.getFeatureSet(); |
782 |
DisposableIterator it = fset.fastIterator(); |
783 |
long rows = fs.getFeatureCount();
|
784 |
int index = ft.getAttributeDescriptor(auxLegend.getFieldSize())
|
785 |
.getIndex(); |
786 |
while (it.hasNext()) {
|
787 |
Feature f = (Feature) it.next(); |
788 |
double dob = f.getDouble(index);
|
789 |
if (dob < min)
|
790 |
min = dob; |
791 |
if (dob > max)
|
792 |
max = dob; |
793 |
} |
794 |
it.dispose(); |
795 |
auxLegend.setMinFeature(min); |
796 |
auxLegend.setMaxFeature(max); |
797 |
|
798 |
} catch (DataException e) {
|
799 |
// TODO Auto-generated catch block
|
800 |
e.printStackTrace(); |
801 |
} |
802 |
|
803 |
} else if (auxLegend.getSizeOption() == IChartSymbol.SIZESUM) { |
804 |
try {
|
805 |
|
806 |
FeatureStore fs = layer.getFeatureStore(); |
807 |
FeatureType ft = fs.getDefaultFeatureType(); |
808 |
FeatureAttributeDescriptor[] atts = ft
|
809 |
.getAttributeDescriptors(); |
810 |
ArrayList<String> auxNames = new ArrayList<String>(); |
811 |
FeatureSet fset = fs.getFeatureSet(); |
812 |
DisposableIterator it = fset.fastIterator(); |
813 |
long rows = fs.getFeatureCount();
|
814 |
String[] names = auxLegend.getClassifyingFieldNames(); |
815 |
int[] indexes = new int[names.length]; |
816 |
for (int i = 0; i < names.length; i++) { |
817 |
indexes[i] = ft.getAttributeDescriptor(names[i]).getIndex(); |
818 |
} |
819 |
|
820 |
while (it.hasNext()) {
|
821 |
Feature f = (Feature) it.next(); |
822 |
double dob = 0; |
823 |
for (int i = 0; i < indexes.length; i++) { |
824 |
dob += f.getDouble(indexes[i]); |
825 |
} |
826 |
if (dob < min)
|
827 |
min = dob; |
828 |
if (dob > max)
|
829 |
max = dob; |
830 |
} |
831 |
it.dispose(); |
832 |
auxLegend.setMinFeature(min); |
833 |
auxLegend.setMaxFeature(max); |
834 |
|
835 |
} catch (DataException e) {
|
836 |
// TODO Auto-generated catch block
|
837 |
e.printStackTrace(); |
838 |
} |
839 |
|
840 |
} |
841 |
// ////////////////////////////////////////////
|
842 |
|
843 |
auxLegend.useDefaultSymbol(true);
|
844 |
|
845 |
// TODO: DEVOLVER LA LEYENDA CORRECTA!!!
|
846 |
// TODO: ESTO HAY QUE HACERLO BIEN. LA IDEA ES GENERAR CORRECTAMENTE
|
847 |
// EL CHARTDATASET, PERO NO CON LOS REQUIREDFIELDS.
|
848 |
// Ahora los campos son como las filas con las que trabajabamos
|
849 |
// antes.
|
850 |
|
851 |
IChartSymbol symbol = (IChartSymbol) MapContextLocator |
852 |
.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME); |
853 |
|
854 |
ChartManager cm = ChartLocator.getServiceManager().getChartManager(); |
855 |
ChartProperties props; |
856 |
try {
|
857 |
props = cm.createProperties("PieChart");
|
858 |
if(auxLegend.is3D()){
|
859 |
props.setChartDimension(true);
|
860 |
props.setChartRenderer("PieChartRenderer3DBasic");
|
861 |
}else{
|
862 |
props.setChartDimension(false);
|
863 |
props.setChartRenderer("PieChartRendererBasic");
|
864 |
} |
865 |
|
866 |
auxLegend.setColors(colors); |
867 |
// auxLegend.setClassifyingFieldNames(fields);
|
868 |
|
869 |
props.setHasPlotOutline(auxLegend.isOutlineShow()); |
870 |
props.setIsLegendVisible(false);
|
871 |
props.setPlotBackgroundColor(auxLegend.getOutlineColor()); |
872 |
if(getJCheckBox().isSelected()){
|
873 |
float alpha = colorButton.getAlpha()/100; |
874 |
if(alpha>1) |
875 |
props.setPlotBackgroundAlpha(1.0f);
|
876 |
else
|
877 |
props.setPlotBackgroundAlpha(alpha); |
878 |
}else{
|
879 |
props.setPlotBackgroundAlpha(0.0f);
|
880 |
} |
881 |
props.setChartName("");
|
882 |
props.setChartDimension(auxLegend.is3D()); |
883 |
|
884 |
ChartService cs = cm.createChart(props); |
885 |
cs.setIsAChartSymbol(true);
|
886 |
|
887 |
// Fijamos los colores dentro del ChartSymbol para hacerlo solo una vez
|
888 |
if (cs.getRenderer() != null) { |
889 |
for (int i=0; i < fields.length; i++) { |
890 |
cs.getRenderer().setSeriesPaint(i, auxLegend.getColors()[i]); |
891 |
} |
892 |
} |
893 |
|
894 |
//auxLegend.setSize(260);
|
895 |
// TODO: REVISAR QU? PASA CUANDO HAY SELECCION. EL SIMBOLO QUE DEVUELVE NO ES CORRECTO
|
896 |
// symbol.setColor(Color.BLACK);
|
897 |
symbol.setChart(cs); |
898 |
//symbol.setSize(260);
|
899 |
auxLegend.setDefaultSymbol(symbol); |
900 |
try {
|
901 |
if (auxLegend.getValues().length == 0) { |
902 |
// Para evitar lo del error "No es posible aplicar una leyenda vac?a"
|
903 |
auxLegend.addSymbol("-1asr12", symbol);
|
904 |
} |
905 |
} catch (Exception e) { |
906 |
// TODO: ARREGLAR ESTO
|
907 |
e.printStackTrace(); |
908 |
} |
909 |
|
910 |
} catch (ServiceException e) {
|
911 |
// TODO Auto-generated catch block
|
912 |
e.printStackTrace(); |
913 |
} |
914 |
|
915 |
// }
|
916 |
this.theLegend = auxLegend;
|
917 |
return theLegend;
|
918 |
} |
919 |
|
920 |
public Class getLegendClass() { |
921 |
return PieChartLegend.class;
|
922 |
} |
923 |
|
924 |
public JPanel getPanel() { |
925 |
return this; |
926 |
} |
927 |
|
928 |
public Class getParentClass() { |
929 |
return MultipleAttributes.class;
|
930 |
} |
931 |
|
932 |
public String getTitle() { |
933 |
return PluginServices.getText(this, "pie_legend"); |
934 |
} |
935 |
|
936 |
public boolean isSuitableFor(FLayer layer) { |
937 |
return (layer instanceof FLyrVect); |
938 |
} |
939 |
|
940 |
public void setData(FLayer layer, ILegend legend) { |
941 |
this.layer = (FLyrVect) layer;
|
942 |
try {
|
943 |
shapeType = this.layer.getShapeType();
|
944 |
} catch (ReadException e) {
|
945 |
e.printStackTrace(); |
946 |
} |
947 |
//getBackgroundSymbol().setShapeType(shapeType);
|
948 |
|
949 |
fieldsTable = getFieldsTable(); |
950 |
|
951 |
fieldsTable.setSize(new Dimension(235, 129)); |
952 |
fillFieldNames(); |
953 |
|
954 |
fieldsTable.removeAllItems(); |
955 |
|
956 |
if (legend instanceof IPieChartLegend) { |
957 |
// TODO: PROVISIONAL. CREAMOS SIEMPRE LA LEYENDA PORQUE NO LA PODEMOS CLONAR TODAVIA.
|
958 |
// auxLegend = (IChartLegend) legend.cloneLegend();
|
959 |
auxLegend = (IPieChartLegend) legend; |
960 |
|
961 |
|
962 |
getJCheckBox().setSelected(auxLegend.isOutlineShow()); |
963 |
// if (getColorButton().getGraphics()!=null)
|
964 |
getColorButton().setColor(auxLegend.getOutlineColor()); |
965 |
// getPreviewChart().setOutLineColor(auxLegend.getOutlineColor());
|
966 |
// getPreviewChart().setOutlineWidth(auxLegend.getOutlineWidth());
|
967 |
// getPreviewChart().setOutlineShow(auxLegend.isOutlineShow());
|
968 |
getComboWidth().setInteger(auxLegend.getOutlineWidth()); |
969 |
|
970 |
getCk3D().setSelected(auxLegend.is3D()); |
971 |
getCkOnlySelection().setSelected(auxLegend.isOnlySelection()); |
972 |
|
973 |
String[] fields = auxLegend.getClassifyingFieldNames(); |
974 |
String[] labels = auxLegend.getFieldLabels(); |
975 |
if(labels.length!= fields.length){
|
976 |
String[] aux = new String[fields.length]; |
977 |
for(int i=0; i<fields.length;i++){ |
978 |
aux[i] = fields[i]; |
979 |
} |
980 |
labels = aux; |
981 |
} |
982 |
Color[] colors = auxLegend.getColors(); |
983 |
if (colors != null) |
984 |
getFieldsTable().fillTableFromSymbolList(colors, fields, labels); |
985 |
// getPreviewChart().setSections(fields, colors);
|
986 |
if (fields != null) { |
987 |
for (int i = 0; i < fields.length; i++) { |
988 |
((DefaultListModel) getJFieldList().getModel())
|
989 |
.removeElement(fields[i]); |
990 |
} |
991 |
} |
992 |
} else {
|
993 |
auxLegend = (IChartLegend) MapContextLocator.getMapContextManager() |
994 |
.createLegend(IChartLegend.PIECHART_LEGEND_NAME); |
995 |
|
996 |
// ISymbol
|
997 |
// backgroundSymbol=(ISymbol)SymbologyFactory.createSymbolFromXML(legend.getDefaultSymbol().getXMLEntity(),null);
|
998 |
// auxLegend.setBackgroundSymbol(backgroundSymbol);
|
999 |
} |
1000 |
//getBackgroundSymbol().setSymbol(auxLegend.getBackgroundSymbol());
|
1001 |
// getPreviewChart().setBackgroundSymbol(auxLegend.getBackgroundSymbol());
|
1002 |
} |
1003 |
|
1004 |
private boolean isNumericField(int fieldType) { |
1005 |
switch (fieldType) {
|
1006 |
case Types.BIGINT: |
1007 |
case Types.DECIMAL: |
1008 |
case Types.DOUBLE: |
1009 |
case Types.FLOAT: |
1010 |
case Types.INTEGER: |
1011 |
case Types.NUMERIC: |
1012 |
case Types.REAL: |
1013 |
case Types.SMALLINT: |
1014 |
case Types.TINYINT: |
1015 |
return true; |
1016 |
default:
|
1017 |
return false; |
1018 |
} |
1019 |
|
1020 |
} |
1021 |
|
1022 |
/**
|
1023 |
* This method initializes ckOnlySelection
|
1024 |
*
|
1025 |
* @return javax.swing.JCheckBox
|
1026 |
*/
|
1027 |
private JCheckBox getCkOnlySelection() { |
1028 |
if (ckOnlySelection == null) { |
1029 |
ckOnlySelection = new JCheckBox(); |
1030 |
ckOnlySelection.setText(PluginServices.getText(this,
|
1031 |
"only_selection"));
|
1032 |
ckOnlySelection |
1033 |
.addChangeListener(new javax.swing.event.ChangeListener() {
|
1034 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
1035 |
auxLegend.setOnlySelection(ckOnlySelection |
1036 |
.isSelected()); |
1037 |
} |
1038 |
}); |
1039 |
} |
1040 |
return ckOnlySelection;
|
1041 |
} |
1042 |
|
1043 |
} // @jve:decl-index=0:visual-constraint="10,10"
|