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 | 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.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 | 57 | jbadia | import org.gvsig.gui.beans.swing.JNumberSpinner; |
54 | 12 | jbadia | import org.gvsig.project.documents.view.legend.BarsChartLegend; |
55 | 381 | fdiaz | import org.gvsig.tools.dataTypes.DataTypes; |
56 | 12 | jbadia | import org.gvsig.tools.dispose.DisposableIterator; |
57 | import org.gvsig.tools.service.ServiceException; |
||
58 | |||
59 | public class ChartLegendPanelBars extends JPanel implements ILegendPanel { |
||
60 | |||
61 | 570 | fdiaz | /**
|
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 | 571 | fdiaz | private final Random rand = new Random(System.currentTimeMillis()); |
74 | 570 | fdiaz | 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 | 12 | jbadia | |
84 | 570 | fdiaz | private JButton bSize = null; |
85 | private JPanel symbolPanel = null; |
||
86 | private JLabel lBackgroundSymbol = null; |
||
87 | 12 | jbadia | |
88 | 570 | fdiaz | private JSymbolPreviewButton bSymbolBackground = null; |
89 | private JComboBoxColorScheme colorCombo = null; |
||
90 | private JLabel lColorSchema = null; |
||
91 | 12 | jbadia | |
92 | 570 | fdiaz | 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 | 12 | jbadia | |
106 | 570 | fdiaz | /**
|
107 | * This is the default constructor
|
||
108 | */
|
||
109 | public ChartLegendPanelBars() {
|
||
110 | super();
|
||
111 | initialize(); |
||
112 | } |
||
113 | 12 | jbadia | |
114 | 570 | fdiaz | /**
|
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 | 12 | jbadia | |
126 | 570 | fdiaz | } |
127 | 12 | jbadia | |
128 | 570 | fdiaz | 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 | 12 | jbadia | |
140 | 570 | fdiaz | 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 | 12 | jbadia | |
155 | 570 | fdiaz | 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 | 12 | jbadia | |
163 | 570 | fdiaz | 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 | 12 | jbadia | |
182 | 570 | fdiaz | 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 | 12 | jbadia | |
192 | 570 | fdiaz | private ColorChooserPanel getColorButton() {
|
193 | if (colorButton == null) { |
||
194 | colorButton = new ColorChooserPanel(true); |
||
195 | colorButton.setColor(Color.black);
|
||
196 | } |
||
197 | return colorButton;
|
||
198 | } |
||
199 | 12 | jbadia | |
200 | 570 | fdiaz | /**
|
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 | 12 | jbadia | |
217 | 570 | fdiaz | private JNumberSpinner getComboWidth() {
|
218 | if (comboWidth == null) { |
||
219 | 57 | jbadia | comboWidth = new JNumberSpinner(String.valueOf(1), 3, 0, Integer.MAX_VALUE, 1); |
220 | 570 | fdiaz | } |
221 | return comboWidth;
|
||
222 | } |
||
223 | 12 | jbadia | |
224 | 570 | fdiaz | 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 | 369 | fdiaz | |
232 | 570 | fdiaz | private JCheckBox getJCheckBox() { |
233 | if (jCheckBox == null) { |
||
234 | jCheckBox = new JCheckBox(); |
||
235 | jCheckBox.setText(PluginServices.getText(this, "Show")); |
||
236 | } |
||
237 | return jCheckBox;
|
||
238 | } |
||
239 | 12 | jbadia | |
240 | 570 | fdiaz | 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 | 12 | jbadia | |
253 | 570 | fdiaz | 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 | 12 | jbadia | // symbolPanel.add(lBackgroundSymbol, null);
|
264 | // symbolPanel.add(getBackgroundSymbol(), null);
|
||
265 | 570 | fdiaz | symbolPanel.add(getShowAxis(), null);
|
266 | 12 | jbadia | |
267 | 570 | fdiaz | } |
268 | return symbolPanel;
|
||
269 | } |
||
270 | 12 | jbadia | |
271 | 570 | fdiaz | // 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 | 381 | fdiaz | // bSymbolBackground.addActionListener(new ActionListener() {
|
288 | // public void actionPerformed(ActionEvent e) {
|
||
289 | // // getPreviewChart().setBackgroundSymbol(bSymbolBackground.getSymbol());
|
||
290 | // // getPreviewChart().repaint();
|
||
291 | // }
|
||
292 | // });
|
||
293 | 570 | fdiaz | } |
294 | return bSymbolBackground;
|
||
295 | } |
||
296 | 12 | jbadia | |
297 | 570 | fdiaz | 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 | 571 | fdiaz | bSize.addActionListener((ActionEvent e) -> {
|
304 | PluginServices.getMDIManager().addCentredWindow( |
||
305 | new SizePanel(layer, (IChartLegend) getLegend()));
|
||
306 | 570 | fdiaz | }); |
307 | } |
||
308 | return bSize;
|
||
309 | } |
||
310 | 12 | jbadia | |
311 | 570 | fdiaz | /**
|
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 | 12 | jbadia | |
328 | 570 | fdiaz | 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 | 12 | jbadia | |
341 | 570 | fdiaz | private JButton getAddButton() { |
342 | if (addButton == null) { |
||
343 | addButton = new JButton(); |
||
344 | addButton.setText(">");
|
||
345 | addButton.setPreferredSize(new Dimension(50, 40)); |
||
346 | 571 | fdiaz | 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 | 570 | fdiaz | } |
356 | }); |
||
357 | } |
||
358 | return addButton;
|
||
359 | } |
||
360 | 12 | jbadia | |
361 | 570 | fdiaz | /**
|
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 | 12 | jbadia | |
378 | 570 | fdiaz | private JComboBoxColorScheme getColorCombo() {
|
379 | if (colorCombo == null) { |
||
380 | colorCombo = new JComboBoxColorScheme(false); |
||
381 | } |
||
382 | return colorCombo;
|
||
383 | } |
||
384 | 12 | jbadia | |
385 | 570 | fdiaz | /**
|
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 | 571 | fdiaz | 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 | 570 | fdiaz | } |
402 | 571 | fdiaz | for (String field : fields) { |
403 | ((DefaultListModel) getJFieldList().getModel()).addElement(field);
|
||
404 | } |
||
405 | getFieldsTable().removeSelectedRows(); |
||
406 | 570 | fdiaz | }); |
407 | } |
||
408 | return removeButton;
|
||
409 | } |
||
410 | 12 | jbadia | |
411 | 570 | fdiaz | /**
|
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 | 571 | fdiaz | 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 | 570 | fdiaz | } |
433 | }); |
||
434 | } |
||
435 | return addAllButton;
|
||
436 | } |
||
437 | 12 | jbadia | |
438 | 570 | fdiaz | /**
|
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 | 381 | fdiaz | // 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 | 570 | fdiaz | } |
457 | return removeAllButton;
|
||
458 | } |
||
459 | 12 | jbadia | |
460 | 570 | fdiaz | 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 | 12 | jbadia | |
477 | 570 | fdiaz | getJFieldList().setModel(cM); |
478 | 12 | jbadia | |
479 | 570 | fdiaz | } catch (DataException e) {
|
480 | NotificationManager.addError( |
||
481 | PluginServices.getText(this, "recovering_recordset"), e); |
||
482 | } |
||
483 | 12 | jbadia | |
484 | 570 | fdiaz | } |
485 | 12 | jbadia | |
486 | 570 | fdiaz | 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 | 12 | jbadia | |
500 | 570 | fdiaz | private FieldsTable getFieldsTable() {
|
501 | if (fieldsTable == null) { |
||
502 | fieldsTable = new FieldsTable();
|
||
503 | fieldsTable.setPreferredSize(new Dimension(250, 300)); |
||
504 | 381 | fdiaz | // fieldsTable.addColorChange(new ColorChange() {
|
505 | // public void actionChange() {
|
||
506 | // // actualizePreviewSymbol();
|
||
507 | // }
|
||
508 | //
|
||
509 | // });
|
||
510 | 570 | fdiaz | } |
511 | return fieldsTable;
|
||
512 | } |
||
513 | 12 | jbadia | |
514 | 570 | fdiaz | 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 | 12 | jbadia | |
528 | 570 | fdiaz | /**
|
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 | 12 | jbadia | |
543 | 570 | fdiaz | public String getDescription() { |
544 | return PluginServices.getText(this, "draw_bar_chart_for_each_feature"); |
||
545 | } |
||
546 | 12 | jbadia | |
547 | 570 | fdiaz | public ImageIcon getIcon() { |
548 | return IconThemeHelper.getImageIcon("legend-bar-chart"); |
||
549 | } |
||
550 | 12 | jbadia | |
551 | 570 | fdiaz | /*
|
552 | 12 | jbadia | * (non-Javadoc)
|
553 | 369 | fdiaz | *
|
554 | 12 | jbadia | * @see
|
555 | * org.gvsig.app.project.documents.view.legend.gui.ILegendPanel#getLegend()
|
||
556 | 570 | fdiaz | */
|
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 | 12 | jbadia | |
567 | 570 | fdiaz | 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 | 12 | jbadia | |
589 | 570 | fdiaz | 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 | 381 | fdiaz | |
604 | 570 | fdiaz | 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 | 12 | jbadia | |
614 | 570 | fdiaz | 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 | 12 | jbadia | |
640 | 570 | fdiaz | } catch (DataException e) {
|
641 | // TODO Auto-generated catch block
|
||
642 | e.printStackTrace(); |
||
643 | } |
||
644 | 12 | jbadia | |
645 | 570 | fdiaz | } else if (auxLegend.getSizeOption() == IChartSymbol.SIZESUM) { |
646 | try {
|
||
647 | 12 | jbadia | |
648 | 570 | fdiaz | 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 | 12 | jbadia | |
662 | 570 | fdiaz | 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 | 12 | jbadia | |
679 | 570 | fdiaz | } catch (DataException e) {
|
680 | // TODO Auto-generated catch block
|
||
681 | e.printStackTrace(); |
||
682 | } |
||
683 | 12 | jbadia | |
684 | 570 | fdiaz | } |
685 | 12 | jbadia | |
686 | 570 | fdiaz | auxLegend.setOnlySelection(getCkOnlySelection().isSelected()); |
687 | auxLegend.setIs3D(getCk3D().isSelected()); |
||
688 | // ////////////////////////////////////////////
|
||
689 | 381 | fdiaz | |
690 | 570 | fdiaz | auxLegend.useDefaultSymbol(true);
|
691 | 12 | jbadia | |
692 | 570 | fdiaz | // 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 | 12 | jbadia | |
700 | 570 | fdiaz | 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 | 12 | jbadia | |
713 | 570 | fdiaz | props.setHasPlotOutline(auxLegend.isOutlineShow()); |
714 | props.setIsLegendVisible(false);
|
||
715 | props.setPlotBackgroundColor(auxLegend.getOutlineColor()); |
||
716 | 571 | fdiaz | 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 | 570 | fdiaz | props.setIsMandatoryChart(jShowAxis.isSelected()); |
727 | props.setIsXYPlotChart(false);
|
||
728 | props.setChartDimension(auxLegend.is3D()); |
||
729 | 12 | jbadia | |
730 | 570 | fdiaz | ChartService cs = cm.createChart(props); |
731 | cs.setIsAChartSymbol(true);
|
||
732 | 12 | jbadia | |
733 | 570 | fdiaz | // 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 | 12 | jbadia | |
743 | 570 | fdiaz | //auxLegend.setSize(260);
|
744 | // TODO: REVISAR QU? PASA CUANDO HAY SELECCION. EL SIMBOLO QUE DEVUELVE NO ES CORRECTO
|
||
745 | 12 | jbadia | // symbol.setColor(Color.BLACK);
|
746 | 570 | fdiaz | symbol.setChart(cs); |
747 | auxLegend.setDefaultSymbol(symbol); |
||
748 | 12 | jbadia | |
749 | 570 | fdiaz | } catch (ServiceException e) {
|
750 | // TODO Auto-generated catch block
|
||
751 | e.printStackTrace(); |
||
752 | } |
||
753 | 12 | jbadia | |
754 | 570 | fdiaz | } |
755 | } |
||
756 | 12 | jbadia | |
757 | 570 | fdiaz | this.theLegend = auxLegend;
|
758 | return theLegend;
|
||
759 | } |
||
760 | 12 | jbadia | |
761 | 570 | fdiaz | public Class getLegendClass() { |
762 | return BarsChartLegend.class;
|
||
763 | } |
||
764 | 12 | jbadia | |
765 | 570 | fdiaz | public JPanel getPanel() { |
766 | return this; |
||
767 | } |
||
768 | 12 | jbadia | |
769 | 570 | fdiaz | public Class getParentClass() { |
770 | return MultipleAttributes.class;
|
||
771 | } |
||
772 | 12 | jbadia | |
773 | 570 | fdiaz | public String getTitle() { |
774 | return PluginServices.getText(this, "bar_legend"); |
||
775 | } |
||
776 | 12 | jbadia | |
777 | 570 | fdiaz | public boolean isSuitableFor(FLayer layer) { |
778 | return (layer instanceof FLyrVect); |
||
779 | } |
||
780 | 12 | jbadia | |
781 | 570 | fdiaz | 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 | 12 | jbadia | |
790 | 570 | fdiaz | fieldsTable = getFieldsTable(); |
791 | 12 | jbadia | |
792 | 570 | fdiaz | fieldsTable.setSize(new Dimension(235, 129)); |
793 | fillFieldNames(); |
||
794 | 12 | jbadia | |
795 | 570 | fdiaz | fieldsTable.removeAllItems(); |
796 | |||
797 | if (legend instanceof IBarsChartLegend) { |
||
798 | // TODO: PROVISIONAL. CREAMOS SIEMPRE LA LEYENDA PORQUE NO LA PODEMOS CLONAR TODAVIA.
|
||
799 | 12 | jbadia | // auxLegend = (IChartLegend) legend.cloneLegend();
|
800 | 570 | fdiaz | IBarsChartLegend barsChartLegend = (IBarsChartLegend) legend; |
801 | 12 | jbadia | |
802 | 570 | fdiaz | getJCheckBox().setSelected(barsChartLegend.isOutlineShow()); |
803 | getColorButton().setColor(barsChartLegend.getOutlineColor()); |
||
804 | getComboWidth().setInteger(barsChartLegend.getOutlineWidth()); |
||
805 | 12 | jbadia | |
806 | 570 | fdiaz | getCk3D().setSelected(barsChartLegend.is3D()); |
807 | getCkOnlySelection().setSelected(barsChartLegend.isOnlySelection()); |
||
808 | 12 | jbadia | |
809 | 570 | fdiaz | 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 | 12 | jbadia | |
824 | 570 | fdiaz | 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 | 382 | fdiaz | } |
833 | 570 | fdiaz | } |
834 | } |
||
835 | 382 | fdiaz | |
836 | 570 | fdiaz | 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 | 12 | jbadia | |
852 | 570 | fdiaz | } |
853 | 12 | jbadia | |
854 | 570 | fdiaz | /**
|
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 | 12 | jbadia | |
868 | } // @jve:decl-index=0:visual-constraint="10,10" |