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