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 / ChartLinkedLegendPanel.java @ 99
History | View | Annotate | Download (43.5 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.Component; |
6 |
import java.awt.Dimension; |
7 |
import java.awt.FlowLayout; |
8 |
import java.awt.Font; |
9 |
import java.awt.event.ActionEvent; |
10 |
import java.awt.event.ActionListener; |
11 |
import java.sql.Types; |
12 |
import java.util.ArrayList; |
13 |
import java.util.Iterator; |
14 |
import java.util.List; |
15 |
import java.util.Properties; |
16 |
import java.util.Random; |
17 |
|
18 |
import javax.swing.BorderFactory; |
19 |
import javax.swing.ButtonGroup; |
20 |
import javax.swing.DefaultComboBoxModel; |
21 |
import javax.swing.DefaultListModel; |
22 |
import javax.swing.ImageIcon; |
23 |
import javax.swing.JButton; |
24 |
import javax.swing.JCheckBox; |
25 |
import javax.swing.JComboBox; |
26 |
import javax.swing.JLabel; |
27 |
import javax.swing.JList; |
28 |
import javax.swing.JPanel; |
29 |
import javax.swing.JRadioButton; |
30 |
import javax.swing.JScrollPane; |
31 |
import javax.swing.JTextField; |
32 |
import javax.swing.border.TitledBorder; |
33 |
import javax.swing.event.ChangeEvent; |
34 |
import javax.swing.event.ChangeListener; |
35 |
|
36 |
import org.gvsig.andami.IconThemeHelper; |
37 |
import org.gvsig.andami.PluginServices; |
38 |
import org.gvsig.andami.messages.NotificationManager; |
39 |
import org.gvsig.app.ApplicationLocator; |
40 |
import org.gvsig.app.ApplicationManager; |
41 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
42 |
import org.gvsig.app.gui.styling.JComboBoxColorScheme; |
43 |
import org.gvsig.app.project.Project; |
44 |
import org.gvsig.app.project.ProjectManager; |
45 |
import org.gvsig.app.project.documents.Document; |
46 |
import org.gvsig.app.project.documents.table.TableDocument; |
47 |
import org.gvsig.app.project.documents.table.TableManager; |
48 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
49 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
50 |
import org.gvsig.app.project.documents.view.legend.gui.MultipleAttributes; |
51 |
import org.gvsig.chart.ChartLocator; |
52 |
import org.gvsig.chart.ChartManager; |
53 |
import org.gvsig.chart.ChartProperties; |
54 |
import org.gvsig.chart.ChartService; |
55 |
import org.gvsig.chart.legend.IChartLegend; |
56 |
import org.gvsig.chart.legend.ILinkedChartLegend; |
57 |
import org.gvsig.chart.legend.symbols.IChartSymbol; |
58 |
import org.gvsig.fmap.dal.exception.DataException; |
59 |
import org.gvsig.fmap.dal.exception.ReadException; |
60 |
import org.gvsig.fmap.dal.feature.Feature; |
61 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
62 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
63 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
64 |
import org.gvsig.fmap.dal.feature.FeatureType; |
65 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
66 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
67 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
68 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
70 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
71 |
import org.gvsig.project.documents.view.legend.LinkedChartLegend; |
72 |
import org.gvsig.tools.dispose.DisposableIterator; |
73 |
import org.gvsig.tools.service.ServiceException; |
74 |
|
75 |
public class ChartLinkedLegendPanel extends JPanel implements ILegendPanel { |
76 |
|
77 |
/**
|
78 |
*
|
79 |
*/
|
80 |
private static final long serialVersionUID = -5009857246030623420L; |
81 |
// private PreviewBarSymbol previewPanel = null;
|
82 |
private FLyrVect layer;
|
83 |
private int shapeType; |
84 |
private IChartLegend auxLegend; // @jve:decl-index=0: |
85 |
private IChartLegend theLegend;
|
86 |
private JPanel centerPanel = null; // @jve:decl-index=0:visual-constraint="10,10" |
87 |
private JScrollPane jScrollPane = null; |
88 |
private JList jFieldList = null; |
89 |
private Random rand = new Random(System.currentTimeMillis()); |
90 |
private JPanel buttons = null; |
91 |
private JButton addButton = null; |
92 |
private JButton removeButton = null; |
93 |
private JButton addAllButton = null; |
94 |
private JButton removeAllButton = null; |
95 |
private JPanel pCentral = null; |
96 |
private FieldsTable fieldsTable = null; // @jve:decl-index=0:visual-constraint="746,10" |
97 |
private JPanel northPanel = null; |
98 |
private JPanel southPanel = null; |
99 |
|
100 |
private JButton bSize = null; |
101 |
private JPanel symbolPanel = null; |
102 |
private JLabel lBackgroundSymbol = null; |
103 |
|
104 |
private JSymbolPreviewButton bSymbolBackground = null; |
105 |
private JComboBoxColorScheme colorCombo = null; |
106 |
private JLabel lColorSchema = null; |
107 |
|
108 |
private JCheckBox ckOnlySelection = null; |
109 |
private JPanel eastPanel; |
110 |
private JPanel outlinePanel; |
111 |
private JLabel jLabel; |
112 |
private JCheckBox jCheckBox; |
113 |
private JCheckBox jShowAxis; |
114 |
private JPanel jPanel; |
115 |
private JLabel jLabel1; |
116 |
private JPanel jPanel1; |
117 |
private JNumberSpinner comboWidth;
|
118 |
private JPanel dimensionPanel; |
119 |
private JCheckBox ck3D; |
120 |
private ColorChooserPanel colorButton;
|
121 |
private JPanel jLinkedPane; |
122 |
private JPanel jLinkedOriginPane; |
123 |
private JPanel jLinkedDestinationPane; |
124 |
private JTextField originTable; |
125 |
private JComboBox originField; |
126 |
private JCheckBox originSelection; |
127 |
private JCheckBox destinationSelection; |
128 |
private JComboBox destinationField; |
129 |
private JComboBox destinationTable; |
130 |
private JRadioButton PieCb; |
131 |
private JRadioButton BarsCb; |
132 |
private JPanel jChartTypePane; |
133 |
private JPanel fieldsPanel; |
134 |
private JComboBox timeField; |
135 |
|
136 |
/**
|
137 |
* This is the default constructor
|
138 |
*/
|
139 |
public ChartLinkedLegendPanel() {
|
140 |
super();
|
141 |
initialize(); |
142 |
} |
143 |
|
144 |
/**
|
145 |
* This method initializes this
|
146 |
*
|
147 |
* @return void
|
148 |
*/
|
149 |
private void initialize() { |
150 |
this.setSize(732, 354); |
151 |
this.setLayout(new BorderLayout()); |
152 |
this.add(getLinkedPanel(), BorderLayout.NORTH); |
153 |
this.add(getCenterPanel(), BorderLayout.CENTER); |
154 |
this.add(getSouthPanel(), BorderLayout.SOUTH); |
155 |
this.add(getEastPanel(), BorderLayout.EAST); |
156 |
|
157 |
// JButton btnTestLegend = new JButton("Crear leyenda de prueba!!");
|
158 |
// btnTestLegend.addActionListener(new ActionListener() {
|
159 |
// public void actionPerformed(ActionEvent e) {
|
160 |
// createTestLegend();
|
161 |
// }
|
162 |
// });
|
163 |
// add(btnTestLegend, BorderLayout.SOUTH);
|
164 |
|
165 |
initializeTableDocuments(); |
166 |
|
167 |
//fillDestinationFieldNames((String) destinationTable.getSelectedItem());
|
168 |
} |
169 |
|
170 |
private JPanel getEastPanel() { |
171 |
if (eastPanel == null) { |
172 |
eastPanel = new JPanel(); |
173 |
eastPanel.setLayout(new BorderLayout()); |
174 |
eastPanel.setPreferredSize(new Dimension(150, 52)); |
175 |
// eastPanel.add(getPreviewChart(), BorderLayout.NORTH);
|
176 |
eastPanel.add(getDimensionPanel(), BorderLayout.NORTH);
|
177 |
eastPanel.add(getOutlinePanel(), BorderLayout.CENTER);
|
178 |
eastPanel.add(getBSize(), BorderLayout.SOUTH);
|
179 |
} |
180 |
return eastPanel;
|
181 |
} |
182 |
|
183 |
private JPanel getDimensionPanel() { |
184 |
if (dimensionPanel == null) { |
185 |
dimensionPanel = new JPanel(); |
186 |
dimensionPanel.setLayout(new BorderLayout()); |
187 |
dimensionPanel.setBorder(BorderFactory.createTitledBorder(null, |
188 |
PluginServices.getText(this, "dimension"), |
189 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
190 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
191 |
Font.BOLD, 12), new Color(51, 51, 51))); |
192 |
dimensionPanel.setPreferredSize(new Dimension(150, 50)); |
193 |
dimensionPanel.add(getCk3D(), BorderLayout.NORTH);
|
194 |
} |
195 |
return dimensionPanel;
|
196 |
} |
197 |
|
198 |
private JCheckBox getCk3D() { |
199 |
if (ck3D == null) { |
200 |
ck3D = new JCheckBox(); |
201 |
ck3D.setEnabled(false);
|
202 |
ck3D.setText(PluginServices.getText(this, "display_3d")); |
203 |
ck3D.addChangeListener(new ChangeListener() { |
204 |
public void stateChanged(ChangeEvent e) { |
205 |
// getPreviewChart().set3D(ck3D.isSelected());
|
206 |
// getPreviewChart().repaint();
|
207 |
// auxLegend.setIs3D(ck3D.isSelected());
|
208 |
} |
209 |
|
210 |
}); |
211 |
} |
212 |
return ck3D;
|
213 |
} |
214 |
|
215 |
private JPanel getOutlinePanel() { |
216 |
if (outlinePanel == null) { |
217 |
jLabel = new JLabel(); |
218 |
jLabel.setText(PluginServices.getText(this, "color")); |
219 |
outlinePanel = new JPanel(); |
220 |
outlinePanel.setLayout(new BorderLayout()); |
221 |
outlinePanel.setBorder(BorderFactory.createTitledBorder(null, |
222 |
PluginServices.getText(this, "background_color"), |
223 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
224 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
225 |
Font.BOLD, 12), new Color(51, 51, 51))); |
226 |
outlinePanel.setPreferredSize(new Dimension(150, 115)); |
227 |
outlinePanel.add(getJCheckBox(), BorderLayout.NORTH);
|
228 |
outlinePanel.add(getJPanel(), BorderLayout.CENTER);
|
229 |
//outlinePanel.add(getJPanel1(), BorderLayout.SOUTH);
|
230 |
} |
231 |
return outlinePanel;
|
232 |
} |
233 |
|
234 |
private JPanel getJPanel() { |
235 |
if (jPanel == null) { |
236 |
jPanel = new JPanel(); |
237 |
jPanel.setLayout(new FlowLayout()); |
238 |
jPanel.add(jLabel, null);
|
239 |
jPanel.add(getColorButton(), null);
|
240 |
} |
241 |
return jPanel;
|
242 |
} |
243 |
|
244 |
private ColorChooserPanel getColorButton() {
|
245 |
if (colorButton == null) { |
246 |
colorButton = new ColorChooserPanel(true); |
247 |
colorButton.setColor(Color.black);
|
248 |
Dimension dim = colorButton.getPreferredSize();
|
249 |
colorButton.setPreferredSize(new Dimension(dim.width-10, dim.height)); |
250 |
colorButton.addActionListener(new ActionListener() { |
251 |
public void actionPerformed(ActionEvent e) { |
252 |
// getPreviewChart().setOutLineColor(colorButton.getColor());
|
253 |
// getPreviewChart().repaint();
|
254 |
auxLegend.setOutlineColor(colorButton.getColor()); |
255 |
} |
256 |
}); |
257 |
} |
258 |
return colorButton;
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* This method initializes jPanel1
|
263 |
*
|
264 |
* @return javax.swing.JPanel
|
265 |
*/
|
266 |
private JPanel getJPanel1() { |
267 |
if (jPanel1 == null) { |
268 |
jLabel1 = new JLabel(); |
269 |
jLabel1.setText(PluginServices.getText(this, "width")); |
270 |
jPanel1 = new JPanel(); |
271 |
jPanel1.setLayout(new FlowLayout()); |
272 |
jPanel1.add(jLabel1, null);
|
273 |
jPanel1.add(getComboWidth(), null);
|
274 |
} |
275 |
return jPanel1;
|
276 |
} |
277 |
|
278 |
private JNumberSpinner getComboWidth() {
|
279 |
if (comboWidth == null) { |
280 |
comboWidth = new JNumberSpinner(String.valueOf(1), 3, 0, Integer.MAX_VALUE, 1); |
281 |
comboWidth.addActionListener(new ActionListener() { |
282 |
public void actionPerformed(ActionEvent e) { |
283 |
// getPreviewChart().setOutlineWidth(comboWidth.getInteger());
|
284 |
// getPreviewChart().repaint();
|
285 |
auxLegend.setOutlineWidth(comboWidth.getInteger()); |
286 |
} |
287 |
|
288 |
}); |
289 |
} |
290 |
return comboWidth;
|
291 |
} |
292 |
|
293 |
private JCheckBox getShowAxis() { |
294 |
if (jShowAxis == null) { |
295 |
jShowAxis = new JCheckBox(); |
296 |
jShowAxis.setEnabled(false);
|
297 |
jShowAxis.setText(PluginServices.getText(this, "show_axis")); |
298 |
} |
299 |
return jShowAxis;
|
300 |
} |
301 |
|
302 |
private JCheckBox getJCheckBox() { |
303 |
if (jCheckBox == null) { |
304 |
jCheckBox = new JCheckBox(); |
305 |
jCheckBox.setText(PluginServices.getText(this, "Show")); |
306 |
jCheckBox.addChangeListener(new ChangeListener() { |
307 |
public void stateChanged(ChangeEvent e) { |
308 |
// getPreviewChart().setOutlineShow(jCheckBox.isSelected());
|
309 |
// getPreviewChart().repaint();
|
310 |
auxLegend.setOutlineShow(jCheckBox.isSelected()); |
311 |
} |
312 |
|
313 |
}); |
314 |
} |
315 |
return jCheckBox;
|
316 |
} |
317 |
|
318 |
private JPanel getSouthPanel() { |
319 |
if (southPanel == null) { |
320 |
southPanel = new JPanel(); |
321 |
southPanel.setLayout(new FlowLayout()); |
322 |
southPanel.setPreferredSize(new Dimension(170, 50)); |
323 |
southPanel.add(getSymbolPanel(), null);
|
324 |
southPanel.add(getNorthPanel(), null);
|
325 |
southPanel.add(getBSize(), null);
|
326 |
southPanel.add(getCkOnlySelection(), null);
|
327 |
} |
328 |
return southPanel;
|
329 |
} |
330 |
|
331 |
private JPanel getSymbolPanel() { |
332 |
if (symbolPanel == null) { |
333 |
lBackgroundSymbol = new JLabel(); |
334 |
lBackgroundSymbol.setText(PluginServices.getText(this,
|
335 |
"background_symbol"));
|
336 |
lBackgroundSymbol.setText(PluginServices.getText(this,
|
337 |
"show_axis"));
|
338 |
symbolPanel = new JPanel(); |
339 |
symbolPanel.setLayout(new FlowLayout()); |
340 |
symbolPanel.setPreferredSize(new Dimension(241, 40)); |
341 |
// symbolPanel.add(lBackgroundSymbol, null);
|
342 |
// symbolPanel.add(getBackgroundSymbol(), null);
|
343 |
symbolPanel.add(getShowAxis(), null);
|
344 |
|
345 |
} |
346 |
return symbolPanel;
|
347 |
} |
348 |
|
349 |
// private PreviewPieSymbol getPreviewChart() {
|
350 |
// if (previewPanel == null) {
|
351 |
// previewPanel = new PreviewPieSymbol();
|
352 |
// previewPanel.setLayout(new BorderLayout());
|
353 |
// previewPanel.setBorder(BorderFactory.createTitledBorder(null,
|
354 |
// PluginServices.getText(this, "preview_chart"),
|
355 |
// TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new
|
356 |
// Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
|
357 |
// previewPanel.setPreferredSize(new Dimension(150, 100));
|
358 |
// }
|
359 |
// return previewPanel;
|
360 |
// }
|
361 |
|
362 |
private JSymbolPreviewButton getBackgroundSymbol() {
|
363 |
if (bSymbolBackground == null) { |
364 |
bSymbolBackground = new JSymbolPreviewButton(shapeType);
|
365 |
bSymbolBackground.setPreferredSize(new Dimension(110, 20)); |
366 |
bSymbolBackground.addActionListener(new ActionListener() { |
367 |
public void actionPerformed(ActionEvent e) { |
368 |
// getPreviewChart().setBackgroundSymbol(bSymbolBackground.getSymbol());
|
369 |
// getPreviewChart().repaint();
|
370 |
} |
371 |
}); |
372 |
} |
373 |
return bSymbolBackground;
|
374 |
} |
375 |
|
376 |
private JButton getBSize() { |
377 |
if (bSize == null) { |
378 |
bSize = new JButton(); |
379 |
bSize.setText(PluginServices.getText(this, "size")); |
380 |
bSize.setPreferredSize(new Dimension(100, 30)); |
381 |
bSize.setMaximumSize(new Dimension(100, 30)); |
382 |
bSize.addActionListener(new ActionListener() { |
383 |
public void actionPerformed(ActionEvent e) { |
384 |
PluginServices.getMDIManager().addCentredWindow( |
385 |
new SizePanel(layer, auxLegend));
|
386 |
} |
387 |
|
388 |
}); |
389 |
} |
390 |
return bSize;
|
391 |
} |
392 |
|
393 |
/**
|
394 |
* This method initializes centerPanel
|
395 |
*
|
396 |
* @return javax.swing.JPanel
|
397 |
*/
|
398 |
private JPanel getCenterPanel() { |
399 |
if (centerPanel == null) { |
400 |
centerPanel = new JPanel(); |
401 |
centerPanel.setLayout(new BorderLayout()); |
402 |
centerPanel.setPreferredSize(new Dimension(350, 150)); |
403 |
centerPanel.add(getChartTypePanel(),BorderLayout.NORTH);
|
404 |
centerPanel.add(getJScrollPane(), BorderLayout.WEST);
|
405 |
centerPanel.add(getButtons(), BorderLayout.CENTER);
|
406 |
centerPanel.add(getFieldsPane(), java.awt.BorderLayout.EAST); |
407 |
} |
408 |
return centerPanel;
|
409 |
} |
410 |
|
411 |
|
412 |
private JPanel getFieldsPane() { |
413 |
if(fieldsPanel == null){ |
414 |
fieldsPanel = new JPanel(); |
415 |
fieldsPanel.setLayout(new BorderLayout()); |
416 |
fieldsPanel.add(getFieldsTable(),BorderLayout.NORTH);
|
417 |
JLabel label = new JLabel(); |
418 |
label.setPreferredSize(new Dimension(125,20)); |
419 |
label.setText(PluginServices.getText(this, "time_field")); |
420 |
fieldsPanel.add(label,BorderLayout.WEST);
|
421 |
timeField = new JComboBox(); |
422 |
timeField.setPreferredSize(new Dimension(75,20)); |
423 |
fieldsPanel.add(timeField,BorderLayout.CENTER);
|
424 |
} |
425 |
return fieldsPanel;
|
426 |
} |
427 |
|
428 |
|
429 |
private JPanel getPCentral() { |
430 |
if (pCentral == null) { |
431 |
pCentral = new JPanel(); |
432 |
pCentral.setLayout(new FlowLayout()); |
433 |
pCentral.setPreferredSize(new Dimension(50, 185)); |
434 |
pCentral.add(getRemoveAllButton(), null);
|
435 |
pCentral.add(getAddAllButton(), null);
|
436 |
pCentral.add(getRemoveButton(), null);
|
437 |
pCentral.add(getAddButton(), null);
|
438 |
} |
439 |
return pCentral;
|
440 |
} |
441 |
|
442 |
private JButton getAddButton() { |
443 |
if (addButton == null) { |
444 |
addButton = new JButton(); |
445 |
addButton.setText(">");
|
446 |
addButton.setPreferredSize(new Dimension(50, 40)); |
447 |
addButton.addActionListener(new java.awt.event.ActionListener() {
|
448 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
449 |
Object[] fields = getJFieldList().getSelectedValues(); |
450 |
Color[] colorScheme = colorCombo.getSelectedColors(); |
451 |
|
452 |
Color[] colors = new Color[colorScheme.length]; |
453 |
for (int i = 0; i < colorScheme.length; i++) { |
454 |
colors[i] = colorScheme[i]; |
455 |
} |
456 |
for (int i = 0; i < fields.length; i++) { |
457 |
getFieldsTable().addTableRecord( |
458 |
colorScheme[rand.nextInt(colorScheme.length)], |
459 |
(String) fields[i], (String) fields[i]); |
460 |
((DefaultListModel) getJFieldList().getModel())
|
461 |
.removeElement(fields[i]); |
462 |
} |
463 |
actualizePreviewSymbol(); |
464 |
} |
465 |
}); |
466 |
} |
467 |
return addButton;
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* This method initializes northPanel
|
472 |
*
|
473 |
* @return javax.swing.JPanel
|
474 |
*/
|
475 |
private JPanel getNorthPanel() { |
476 |
if (northPanel == null) { |
477 |
lColorSchema = new JLabel(); |
478 |
lColorSchema.setText(PluginServices.getText(this, "color_schema")); |
479 |
northPanel = new JPanel(); |
480 |
northPanel.setLayout(new FlowLayout()); |
481 |
northPanel.add(lColorSchema, null);
|
482 |
northPanel.add(getColorCombo()); |
483 |
} |
484 |
return northPanel;
|
485 |
} |
486 |
|
487 |
private JComboBoxColorScheme getColorCombo() {
|
488 |
if (colorCombo == null) { |
489 |
colorCombo = new JComboBoxColorScheme(false); |
490 |
} |
491 |
return colorCombo;
|
492 |
} |
493 |
|
494 |
/**
|
495 |
* This method initializes removeButton
|
496 |
*
|
497 |
* @return javax.swing.JButton
|
498 |
*/
|
499 |
private JButton getRemoveButton() { |
500 |
if (removeButton == null) { |
501 |
removeButton = new JButton(); |
502 |
removeButton.setPreferredSize(new Dimension(50, 40)); |
503 |
removeButton.setText("<");
|
504 |
removeButton.addActionListener(new java.awt.event.ActionListener() {
|
505 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
506 |
int[] index = getFieldsTable().getSelectedRows(); |
507 |
String[] fields = new String[index.length]; |
508 |
for (int i = 0; i < index.length; i++) { |
509 |
fields[i] = (String) getFieldsTable().getFieldValue(
|
510 |
index[i], 1);
|
511 |
} |
512 |
for (int i = 0; i < fields.length; i++) { |
513 |
((DefaultListModel) getJFieldList().getModel())
|
514 |
.addElement(fields[i]); |
515 |
} |
516 |
getFieldsTable().removeSelectedRows(); |
517 |
actualizePreviewSymbol(); |
518 |
|
519 |
fillDestinationFieldNames((String) destinationTable.getSelectedItem());
|
520 |
} |
521 |
}); |
522 |
} |
523 |
return removeButton;
|
524 |
} |
525 |
|
526 |
/**
|
527 |
* This method initializes addAllButton
|
528 |
*
|
529 |
* @return javax.swing.JButton
|
530 |
*/
|
531 |
private JButton getAddAllButton() { |
532 |
if (addAllButton == null) { |
533 |
addAllButton = new JButton(); |
534 |
addAllButton.setPreferredSize(new Dimension(50, 40)); |
535 |
addAllButton.setText(">>");
|
536 |
addAllButton.addActionListener(new java.awt.event.ActionListener() {
|
537 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
538 |
Object[] fields = ((DefaultListModel) getJFieldList() |
539 |
.getModel()).toArray(); |
540 |
|
541 |
Color[] colorScheme = colorCombo.getSelectedColors(); |
542 |
|
543 |
Color[] colors = new Color[colorScheme.length]; |
544 |
for (int i = 0; i < colorScheme.length; i++) { |
545 |
colors[i] = colorScheme[i]; |
546 |
} |
547 |
for (int i = 0; i < fields.length; i++) { |
548 |
getFieldsTable().addTableRecord( |
549 |
colorScheme[rand.nextInt(colorScheme.length)], |
550 |
(String) fields[i], (String) fields[i]); |
551 |
((DefaultListModel) getJFieldList().getModel())
|
552 |
.removeElement(fields[i]); |
553 |
} |
554 |
actualizePreviewSymbol(); |
555 |
} |
556 |
}); |
557 |
} |
558 |
return addAllButton;
|
559 |
} |
560 |
|
561 |
private void actualizePreviewSymbol() { |
562 |
int count = getFieldsTable().getRowCount();
|
563 |
String[] fieldsTable = new String[count]; |
564 |
for (int i = 0; i < count; i++) { |
565 |
fieldsTable[i] = (String) getFieldsTable().getFieldValue(i, 1); |
566 |
} |
567 |
String[] labelsTable = new String[count]; |
568 |
for (int i = 0; i < count; i++) { |
569 |
labelsTable[i] = (String) getFieldsTable().getFieldValue(i, 2); |
570 |
} |
571 |
Color[] colorsTable = new Color[count]; |
572 |
for (int i = 0; i < count; i++) { |
573 |
colorsTable[i] = ((JPanel) getFieldsTable().getFieldValue(i, 0)) |
574 |
.getBackground(); |
575 |
} |
576 |
// getPreviewChart().setSections(fieldsTable, colorsTable);
|
577 |
// getPreviewChart().repaint();
|
578 |
// auxLegend.setFieldNames(fieldsTable);
|
579 |
// auxLegend.setLabels(labelsTable);
|
580 |
// auxLegend.setColors(colorsTable);
|
581 |
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* This method initializes removeAllButton
|
586 |
*
|
587 |
* @return javax.swing.JButton
|
588 |
*/
|
589 |
private JButton getRemoveAllButton() { |
590 |
if (removeAllButton == null) { |
591 |
removeAllButton = new JButton(); |
592 |
removeAllButton.setPreferredSize(new Dimension(50, 40)); |
593 |
removeAllButton.setText("<<");
|
594 |
removeAllButton |
595 |
.addActionListener(new java.awt.event.ActionListener() {
|
596 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
597 |
getFieldsTable().removeAllItems(); |
598 |
actualizePreviewSymbol(); |
599 |
fillDestinationFieldNames((String) destinationTable.getSelectedItem());
|
600 |
} |
601 |
}); |
602 |
} |
603 |
return removeAllButton;
|
604 |
} |
605 |
|
606 |
private void fillFieldNames() { |
607 |
// FeatureStore rs;
|
608 |
// ((DefaultListModel) getJFieldList().getModel()).removeAllElements();
|
609 |
// try {
|
610 |
// rs = ((FLyrVect) layer).getFeatureStore();
|
611 |
// ArrayList<String> names = new ArrayList<String>();
|
612 |
// Iterator iterator = rs.getDefaultFeatureType().iterator();
|
613 |
// DefaultListModel cM = new DefaultListModel();
|
614 |
// while (iterator.hasNext()) {
|
615 |
// FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator
|
616 |
// .next();
|
617 |
// names.add(descriptor.getName());
|
618 |
// cM.addElement(descriptor.getName());
|
619 |
// }
|
620 |
//
|
621 |
// getJFieldList().setModel(cM);
|
622 |
//
|
623 |
// } catch (DataException e) {
|
624 |
// NotificationManager.addError(
|
625 |
// PluginServices.getText(this, "recovering_recordset"), e);
|
626 |
// }
|
627 |
//
|
628 |
fillOriginFieldNames(); |
629 |
} |
630 |
|
631 |
private JPanel getButtons() { |
632 |
if (buttons == null) { |
633 |
FlowLayout flowLayout = new FlowLayout(); |
634 |
flowLayout.setHgap(5);
|
635 |
flowLayout.setAlignment(FlowLayout.CENTER);
|
636 |
flowLayout.setVgap(1);
|
637 |
buttons = new JPanel(); |
638 |
buttons.setPreferredSize(new Dimension(60, 50)); |
639 |
buttons.setLayout(flowLayout); |
640 |
buttons.add(getPCentral(), null);
|
641 |
} |
642 |
return buttons;
|
643 |
} |
644 |
|
645 |
private FieldsTable getFieldsTable() {
|
646 |
if (fieldsTable == null) { |
647 |
fieldsTable = new FieldsTable();
|
648 |
fieldsTable.setPreferredSize(new Dimension(250, 175)); |
649 |
fieldsTable.addColorChange(new ColorChange() {
|
650 |
public void actionChange() { |
651 |
// actualizePreviewSymbol();
|
652 |
} |
653 |
|
654 |
}); |
655 |
} |
656 |
return fieldsTable;
|
657 |
} |
658 |
|
659 |
private JPanel getLinkedPanel() { |
660 |
if (jLinkedPane == null) { |
661 |
jLinkedPane = new JPanel(); |
662 |
// jLinkedPane.setBorder(BorderFactory.createTitledBorder(null,
|
663 |
// PluginServices.getText(this, "linked_table_options"),
|
664 |
// TitledBorder.DEFAULT_JUSTIFICATION,
|
665 |
// TitledBorder.DEFAULT_POSITION, new Font("Dialog",
|
666 |
// Font.BOLD, 12), new Color(51, 51, 51)));
|
667 |
jLinkedPane.setPreferredSize(new Dimension(350, 110)); |
668 |
|
669 |
jLinkedPane.add(getLinkedTablePanel(),BorderLayout.WEST);
|
670 |
jLinkedPane.add(getFieldToLinkPanel(),BorderLayout.EAST);
|
671 |
|
672 |
} |
673 |
return jLinkedPane;
|
674 |
} |
675 |
|
676 |
private Component getChartTypePanel() { |
677 |
if (jChartTypePane == null) { |
678 |
jChartTypePane = new JPanel(); |
679 |
jChartTypePane.setBorder(BorderFactory.createTitledBorder(null, |
680 |
PluginServices.getText(this, "choose_chart_type"), |
681 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
682 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
683 |
Font.BOLD, 12), new Color(51, 51, 51))); |
684 |
jChartTypePane.setPreferredSize(new Dimension(604, 50)); |
685 |
|
686 |
jChartTypePane.setLayout(new FlowLayout()); |
687 |
|
688 |
|
689 |
PieCb = new JRadioButton(); |
690 |
PieCb.addActionListener(new ActionListener() { |
691 |
public void actionPerformed(ActionEvent arg0) { |
692 |
getCk3D().setEnabled(!PieCb.isSelected()); |
693 |
getShowAxis().setEnabled(!PieCb.isSelected()); |
694 |
} |
695 |
}); |
696 |
PieCb.setText(PluginServices.getText(this, "pie_chart")); |
697 |
PieCb.setPreferredSize(new Dimension(200, 20)); |
698 |
PieCb.setSelected(true);
|
699 |
|
700 |
jChartTypePane.add(PieCb); |
701 |
|
702 |
|
703 |
BarsCb = new JRadioButton(); |
704 |
BarsCb.addActionListener(new ActionListener() { |
705 |
public void actionPerformed(ActionEvent arg0) { |
706 |
getCk3D().setEnabled(BarsCb.isSelected()); |
707 |
getShowAxis().setEnabled(BarsCb.isSelected()); |
708 |
} |
709 |
}); |
710 |
BarsCb.setText(PluginServices.getText(this, "bars_chart")); |
711 |
BarsCb.setPreferredSize(new Dimension(200, 20)); |
712 |
|
713 |
jChartTypePane.add(BarsCb); |
714 |
|
715 |
ButtonGroup group = new ButtonGroup(); |
716 |
group.add(PieCb); |
717 |
group.add(BarsCb); |
718 |
|
719 |
|
720 |
} |
721 |
return jChartTypePane;
|
722 |
} |
723 |
|
724 |
private void fillOriginFieldNames() { |
725 |
FeatureStore rs; |
726 |
((DefaultListModel) getJFieldList().getModel()).removeAllElements();
|
727 |
try {
|
728 |
rs = ((FLyrVect) layer).getFeatureStore(); |
729 |
|
730 |
originTable.setText(rs.getName()); |
731 |
|
732 |
ArrayList<String> names = new ArrayList<String>(); |
733 |
Iterator iterator = rs.getDefaultFeatureType().iterator();
|
734 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(); |
735 |
while (iterator.hasNext()) {
|
736 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator |
737 |
.next(); |
738 |
names.add(descriptor.getName()); |
739 |
cM.addElement(descriptor.getName()); |
740 |
} |
741 |
|
742 |
originField.setModel(cM); |
743 |
|
744 |
} catch (DataException e) {
|
745 |
NotificationManager.addError( |
746 |
PluginServices.getText(this, "recovering_recordset"), e); |
747 |
} |
748 |
|
749 |
} |
750 |
|
751 |
private JPanel getLinkedTablePanel() { |
752 |
if (jLinkedOriginPane == null) { |
753 |
jLinkedOriginPane = new JPanel(); |
754 |
jLinkedOriginPane.setBorder(BorderFactory.createTitledBorder(null, |
755 |
PluginServices.getText(this, "origin_linked_table"), |
756 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
757 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
758 |
Font.BOLD, 12), new Color(51, 51, 51))); |
759 |
jLinkedOriginPane.setPreferredSize(new Dimension(300, 100)); |
760 |
|
761 |
FLyrVect rs = ((FLyrVect) layer); |
762 |
|
763 |
JLabel lorigin = new JLabel(); |
764 |
lorigin.setText(PluginServices.getText(this, "table_origin")); |
765 |
lorigin.setPreferredSize(new Dimension(100, 15)); |
766 |
lorigin.setAlignmentY(0.0f);
|
767 |
|
768 |
originTable = new JTextField(); |
769 |
originTable.setEditable(false);
|
770 |
originTable.setEnabled(false);
|
771 |
originTable.setPreferredSize(new Dimension(170, 20)); |
772 |
|
773 |
jLinkedOriginPane.add(lorigin); |
774 |
jLinkedOriginPane.add(originTable); |
775 |
|
776 |
|
777 |
JLabel loriginField = new JLabel(); |
778 |
loriginField.setText(PluginServices.getText(this, "field_origin")); |
779 |
loriginField.setPreferredSize(new Dimension(100, 15)); |
780 |
loriginField.setAlignmentY(0.0f);
|
781 |
|
782 |
originField = new JComboBox(); |
783 |
originField.setEditable(false);
|
784 |
originField.setPreferredSize(new Dimension(170, 20)); |
785 |
|
786 |
jLinkedOriginPane.add(loriginField); |
787 |
jLinkedOriginPane.add(originField); |
788 |
|
789 |
originSelection = new JCheckBox(); |
790 |
originSelection.setText(PluginServices.getText(this, "only_selected")); |
791 |
|
792 |
jLinkedOriginPane.add(originSelection); |
793 |
} |
794 |
return jLinkedOriginPane;
|
795 |
} |
796 |
|
797 |
private void fillDestinationFieldNames(String tableName) { |
798 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
799 |
final Project project = appManager.getCurrentProject();
|
800 |
|
801 |
TableDocument selDoc = (TableDocument) project.getDocument(tableName, |
802 |
TableManager.TYPENAME); |
803 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
804 |
DefaultComboBoxModel model2 = new DefaultComboBoxModel(); |
805 |
DefaultListModel cM = new DefaultListModel(); |
806 |
if (selDoc != null) { |
807 |
try {
|
808 |
FeatureType featType = selDoc.getStore().getDefaultFeatureType(); |
809 |
FeatureAttributeDescriptor[] atts = featType.getAttributeDescriptors();
|
810 |
|
811 |
for(int i=0; i<atts.length; i++){ |
812 |
model.addElement(atts[i].getName()); |
813 |
|
814 |
if(atts[i].getDataType().isNumeric()){
|
815 |
cM.addElement(atts[i].getName()); |
816 |
model2.addElement(atts[i].getName()); |
817 |
} |
818 |
} |
819 |
|
820 |
getJFieldList().setModel(cM); |
821 |
destinationField.setModel(model); |
822 |
timeField.setModel(model2); |
823 |
timeField.insertItemAt("", 0); |
824 |
timeField.setSelectedIndex(0);
|
825 |
|
826 |
} catch (DataException e) {
|
827 |
// TODO Auto-generated catch block
|
828 |
e.printStackTrace(); |
829 |
} |
830 |
} |
831 |
} |
832 |
|
833 |
|
834 |
private void initializeTableDocuments(){ |
835 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
836 |
final Project project = appManager.getCurrentProject();
|
837 |
ProjectManager projectManager = appManager.getProjectManager(); |
838 |
|
839 |
List<Document> tableDocuments = project |
840 |
.getDocuments(TableManager.TYPENAME); |
841 |
TableDocument[] pts = tableDocuments
|
842 |
.toArray(new TableDocument[tableDocuments.size()]);
|
843 |
|
844 |
Properties extendedProps = new Properties(); |
845 |
//List<String> tableNames = new ArrayList<String>();
|
846 |
|
847 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
848 |
for (TableDocument t : pts) {
|
849 |
model.addElement(t.getName()); |
850 |
} |
851 |
destinationTable.setModel(model); |
852 |
|
853 |
if(model.getSize()>0){ |
854 |
fillDestinationFieldNames((String) model.getElementAt(0)); |
855 |
} |
856 |
} |
857 |
|
858 |
|
859 |
private JPanel getFieldToLinkPanel() { |
860 |
if (jLinkedDestinationPane == null) { |
861 |
jLinkedDestinationPane = new JPanel(); |
862 |
jLinkedDestinationPane.setBorder(BorderFactory.createTitledBorder(null, |
863 |
PluginServices.getText(this, "destination_linked_table"), |
864 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
865 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
866 |
Font.BOLD, 12), new Color(51, 51, 51))); |
867 |
jLinkedDestinationPane.setPreferredSize(new Dimension(300, 100)); |
868 |
|
869 |
jLinkedDestinationPane.setLayout(new FlowLayout()); |
870 |
|
871 |
FLyrVect rs = ((FLyrVect) layer); |
872 |
|
873 |
JLabel lorigin = new JLabel(); |
874 |
lorigin.setText(PluginServices.getText(this, "table_destination")); |
875 |
lorigin.setPreferredSize(new Dimension(100, 15)); |
876 |
lorigin.setAlignmentY(0.0f);
|
877 |
|
878 |
destinationTable = new JComboBox(); |
879 |
//destinationTable.setEnabled(false);
|
880 |
//destinationTable.setText(((FLyrVect) layer).getName());
|
881 |
destinationTable.setPreferredSize(new Dimension(170, 20)); |
882 |
destinationTable.addActionListener(new ActionListener() { |
883 |
public void actionPerformed(ActionEvent arg0) { |
884 |
String selected = (String) destinationTable.getSelectedItem(); |
885 |
if(selected!=""){ |
886 |
fillDestinationFieldNames(selected); |
887 |
destinationTable.setEnabled(true);
|
888 |
}else{
|
889 |
destinationTable.setModel(new DefaultComboBoxModel()); |
890 |
destinationTable.setEnabled(false);
|
891 |
} |
892 |
} |
893 |
}); |
894 |
|
895 |
jLinkedDestinationPane.add(lorigin, null);
|
896 |
jLinkedDestinationPane.add(destinationTable, null);
|
897 |
|
898 |
JLabel loriginField = new JLabel(); |
899 |
loriginField.setText(PluginServices.getText(this, "field_destination")); |
900 |
loriginField.setPreferredSize(new Dimension(100, 15)); |
901 |
loriginField.setAlignmentY(0.0f);
|
902 |
|
903 |
destinationField = new JComboBox(); |
904 |
|
905 |
destinationField.setEditable(false);
|
906 |
destinationField.setPreferredSize(new Dimension(170, 20)); |
907 |
|
908 |
jLinkedDestinationPane.add(loriginField, null);
|
909 |
jLinkedDestinationPane.add(destinationField, null);
|
910 |
|
911 |
destinationSelection = new JCheckBox(); |
912 |
destinationSelection.setText(PluginServices.getText(this, "only_selected")); |
913 |
|
914 |
jLinkedDestinationPane.add(destinationSelection, null);
|
915 |
} |
916 |
return jLinkedDestinationPane;
|
917 |
} |
918 |
|
919 |
private JScrollPane getJScrollPane() { |
920 |
if (jScrollPane == null) { |
921 |
jScrollPane = new JScrollPane(); |
922 |
jScrollPane.setBorder(BorderFactory.createTitledBorder(null, |
923 |
PluginServices.getText(this, "fields"), |
924 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
925 |
TitledBorder.DEFAULT_POSITION, new Font("Dialog", |
926 |
Font.BOLD, 12), new Color(51, 51, 51))); |
927 |
jScrollPane.setPreferredSize(new Dimension(150, 150)); |
928 |
jScrollPane.setViewportView(getJFieldList()); |
929 |
} |
930 |
return jScrollPane;
|
931 |
} |
932 |
|
933 |
/**
|
934 |
* This method initializes jFieldList
|
935 |
*
|
936 |
* @return javax.swing.JList
|
937 |
*/
|
938 |
private JList getJFieldList() { |
939 |
if (jFieldList == null) { |
940 |
DefaultListModel dlm = new DefaultListModel(); |
941 |
jFieldList = new JList(); |
942 |
jFieldList.setSize(new Dimension(150, 150)); |
943 |
jFieldList.setModel(dlm); |
944 |
} |
945 |
return jFieldList;
|
946 |
} |
947 |
|
948 |
|
949 |
public String getDescription() { |
950 |
return PluginServices.getText(this, "draw_bar_chart_for_each_feature"); |
951 |
} |
952 |
|
953 |
public ImageIcon getIcon() { |
954 |
return IconThemeHelper.getImageIcon("legend-pie-chart"); |
955 |
} |
956 |
|
957 |
/*
|
958 |
* (non-Javadoc)
|
959 |
*
|
960 |
* @see
|
961 |
* org.gvsig.app.project.documents.view.legend.gui.ILegendPanel#getLegend()
|
962 |
*/
|
963 |
public ILegend getLegend() {
|
964 |
if (auxLegend == null) { |
965 |
auxLegend = (IChartLegend) MapContextLocator.getMapContextManager() |
966 |
.createLegend(IChartLegend.LINKED_LEGEND_NAME); |
967 |
} |
968 |
//ISymbol backgroundSymbol = getBackgroundSymbol().getSymbol();
|
969 |
//auxLegend.setBackgroundSymbol(backgroundSymbol);
|
970 |
auxLegend.setOutlineShow(getJCheckBox().isSelected()); |
971 |
auxLegend.setOutlineColor(getColorButton().getColor()); |
972 |
auxLegend.setOutlineWidth(getComboWidth().getInteger()); |
973 |
auxLegend.setIs3D(getCk3D().isSelected()); |
974 |
|
975 |
int rowCount = getFieldsTable().getRowCount();
|
976 |
String[] fields = new String[rowCount]; |
977 |
String[] labels = new String[rowCount]; |
978 |
Color[] colors = new Color[rowCount]; |
979 |
for (int i = 0; i < fields.length; i++) { |
980 |
colors[i] = ((JPanel) getFieldsTable().getFieldValue(i, 0)) |
981 |
.getBackground(); |
982 |
fields[i] = (String) getFieldsTable().getFieldValue(i, 1); |
983 |
labels[i] = (String) getFieldsTable().getFieldValue(i, 2); |
984 |
} |
985 |
auxLegend.setClassifyingFieldNames(fields); |
986 |
auxLegend.setFields(fields); |
987 |
auxLegend.setLabels(labels); |
988 |
auxLegend.setColors(colors); |
989 |
|
990 |
if(auxLegend instanceof ILinkedChartLegend){ |
991 |
ILinkedChartLegend linkedLegend = (ILinkedChartLegend)auxLegend; |
992 |
linkedLegend.setLinkedField((String) destinationField.getSelectedItem());
|
993 |
linkedLegend.setGroupedField((String) timeField.getSelectedItem());
|
994 |
String[] linkField = {(String) originField.getSelectedItem()}; |
995 |
linkedLegend.setLinkedFieldName(linkField); |
996 |
linkedLegend.setLinkedFields(fields); |
997 |
linkedLegend.setLinkedTable((String)destinationTable.getSelectedItem());
|
998 |
linkedLegend.setOriginSelected(originSelection.isSelected()); |
999 |
linkedLegend.setLinkedSelected(originSelection.isSelected()); |
1000 |
linkedLegend.setTimeField((String)timeField.getSelectedItem());
|
1001 |
if(PieCb.isSelected()){
|
1002 |
linkedLegend.setLegendType("PieChart");
|
1003 |
} |
1004 |
else{
|
1005 |
linkedLegend.setLegendType("BarsChart");
|
1006 |
} |
1007 |
linkedLegend.setDataHash(linkedLegend.getLinkedData()); |
1008 |
|
1009 |
} |
1010 |
|
1011 |
if (auxLegend.getSizeOption() == IChartSymbol.SIZEFIELD) {
|
1012 |
int classifyingCount = fields.length + 2; |
1013 |
if (auxLegend.getFieldNormalize().equals("---")) { |
1014 |
classifyingCount = fields.length + 1;
|
1015 |
} |
1016 |
String[] classifyingFields = new String[classifyingCount]; |
1017 |
for (int i = 0; i < fields.length; i++) { |
1018 |
classifyingFields[i] = fields[i]; |
1019 |
} |
1020 |
if (!auxLegend.getFieldNormalize().equals("---")) { |
1021 |
classifyingFields[classifyingCount - 2] = auxLegend
|
1022 |
.getFieldNormalize(); |
1023 |
} |
1024 |
classifyingFields[classifyingCount - 1] = auxLegend.getFieldSize();
|
1025 |
|
1026 |
auxLegend.setClassifyingFieldNames(classifyingFields); |
1027 |
} else {
|
1028 |
if (fields != null && fields.length > 0) |
1029 |
auxLegend.setClassifyingFieldNames(fields); |
1030 |
} |
1031 |
// /////////////////////////////////////////////
|
1032 |
double min = Double.MAX_VALUE; |
1033 |
double max = Double.MIN_VALUE; |
1034 |
|
1035 |
if (auxLegend.getSizeOption() == IChartSymbol.SIZEFIELD) {
|
1036 |
try {
|
1037 |
FeatureStore fs = layer.getFeatureStore(); |
1038 |
FeatureType ft = fs.getDefaultFeatureType(); |
1039 |
FeatureAttributeDescriptor[] atts = ft
|
1040 |
.getAttributeDescriptors(); |
1041 |
ArrayList<String> auxNames = new ArrayList<String>(); |
1042 |
FeatureSet fset = fs.getFeatureSet(); |
1043 |
DisposableIterator it = fset.fastIterator(); |
1044 |
long rows = fs.getFeatureCount();
|
1045 |
int index = ft.getAttributeDescriptor(auxLegend.getFieldSize())
|
1046 |
.getIndex(); |
1047 |
while (it.hasNext()) {
|
1048 |
Feature f = (Feature) it.next(); |
1049 |
double dob = f.getDouble(index);
|
1050 |
if (dob < min)
|
1051 |
min = dob; |
1052 |
if (dob > max)
|
1053 |
max = dob; |
1054 |
} |
1055 |
it.dispose(); |
1056 |
auxLegend.setMinFeature(min); |
1057 |
auxLegend.setMaxFeature(max); |
1058 |
|
1059 |
} catch (DataException e) {
|
1060 |
// TODO Auto-generated catch block
|
1061 |
e.printStackTrace(); |
1062 |
} |
1063 |
|
1064 |
} else if (auxLegend.getSizeOption() == IChartSymbol.SIZESUM) { |
1065 |
try {
|
1066 |
|
1067 |
FeatureStore fs = layer.getFeatureStore(); |
1068 |
FeatureType ft = fs.getDefaultFeatureType(); |
1069 |
FeatureAttributeDescriptor[] atts = ft
|
1070 |
.getAttributeDescriptors(); |
1071 |
ArrayList<String> auxNames = new ArrayList<String>(); |
1072 |
FeatureSet fset = fs.getFeatureSet(); |
1073 |
DisposableIterator it = fset.fastIterator(); |
1074 |
long rows = fs.getFeatureCount();
|
1075 |
String[] names = auxLegend.getClassifyingFieldNames(); |
1076 |
int[] indexes = new int[names.length]; |
1077 |
for (int i = 0; i < names.length; i++) { |
1078 |
indexes[i] = ft.getAttributeDescriptor(names[i]).getIndex(); |
1079 |
} |
1080 |
|
1081 |
while (it.hasNext()) {
|
1082 |
Feature f = (Feature) it.next(); |
1083 |
double dob = 0; |
1084 |
for (int i = 0; i < indexes.length; i++) { |
1085 |
dob += f.getDouble(indexes[i]); |
1086 |
} |
1087 |
if (dob < min)
|
1088 |
min = dob; |
1089 |
if (dob > max)
|
1090 |
max = dob; |
1091 |
} |
1092 |
it.dispose(); |
1093 |
auxLegend.setMinFeature(min); |
1094 |
auxLegend.setMaxFeature(max); |
1095 |
|
1096 |
} catch (DataException e) {
|
1097 |
// TODO Auto-generated catch block
|
1098 |
e.printStackTrace(); |
1099 |
} |
1100 |
|
1101 |
} |
1102 |
// ////////////////////////////////////////////
|
1103 |
|
1104 |
auxLegend.useDefaultSymbol(true);
|
1105 |
|
1106 |
// TODO: DEVOLVER LA LEYENDA CORRECTA!!!
|
1107 |
// TODO: ESTO HAY QUE HACERLO BIEN. LA IDEA ES GENERAR CORRECTAMENTE
|
1108 |
// EL CHARTDATASET, PERO NO CON LOS REQUIREDFIELDS.
|
1109 |
// Ahora los campos son como las filas con las que trabajabamos
|
1110 |
// antes.
|
1111 |
|
1112 |
IChartSymbol symbol = (IChartSymbol) MapContextLocator |
1113 |
.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME); |
1114 |
|
1115 |
ChartManager cm = ChartLocator.getServiceManager().getChartManager(); |
1116 |
ChartProperties props; |
1117 |
try {
|
1118 |
props = cm.createProperties(getChartType()); |
1119 |
|
1120 |
|
1121 |
auxLegend.setColors(colors); |
1122 |
// auxLegend.setClassifyingFieldNames(fields);
|
1123 |
|
1124 |
props.setHasPlotOutline(auxLegend.isOutlineShow()); |
1125 |
props.setIsLegendVisible(false);
|
1126 |
props.setPlotBackgroundColor(auxLegend.getOutlineColor()); |
1127 |
props.setPlotBackgroundAlpha(0.5f);
|
1128 |
props.setChartName("");
|
1129 |
props.setChartDimension(auxLegend.is3D()); |
1130 |
|
1131 |
|
1132 |
if(getChartType().equals("BarsChart")){ |
1133 |
if(auxLegend.is3D()){
|
1134 |
props.setChartDimension(true);
|
1135 |
props.setChartRenderer("BarsChartRenderer3DBasic");
|
1136 |
}else{
|
1137 |
props.setChartDimension(false);
|
1138 |
props.setChartRenderer("BarsChartRendererBasic");
|
1139 |
} |
1140 |
props.setIsMandatoryChart(jShowAxis.isSelected()); |
1141 |
props.setIsXYPlotChart(false);
|
1142 |
} |
1143 |
|
1144 |
ChartService cs = cm.createChart(props); |
1145 |
cs.setIsAChartSymbol(true);
|
1146 |
|
1147 |
// Fijamos los colores dentro del ChartSymbol para hacerlo solo una vez
|
1148 |
if (cs.getRenderer() != null) { |
1149 |
if(getChartType().equals("PieChart")){ |
1150 |
for (int i=0; i < fields.length; i++) { |
1151 |
cs.getRenderer().setSeriesPaint(i, auxLegend.getColors()[i]); |
1152 |
} |
1153 |
}else{
|
1154 |
List<Color> colorsArray = new ArrayList<Color>(); |
1155 |
for (int i=0; i < fields.length; i++) { |
1156 |
cs.getRenderer().setSeriesPaint(i, auxLegend.getColors()[i]); |
1157 |
colorsArray.add(auxLegend.getColors()[i]); |
1158 |
} |
1159 |
cs.setCategoriesPaint(colorsArray); |
1160 |
} |
1161 |
} |
1162 |
|
1163 |
//auxLegend.setSize(260);
|
1164 |
// TODO: REVISAR QU? PASA CUANDO HAY SELECCION. EL SIMBOLO QUE DEVUELVE NO ES CORRECTO
|
1165 |
// symbol.setColor(Color.BLACK);
|
1166 |
symbol.setChart(cs); |
1167 |
//symbol.setSize(260);
|
1168 |
auxLegend.setDefaultSymbol(symbol); |
1169 |
try {
|
1170 |
if (auxLegend.getValues().length == 0) { |
1171 |
// Para evitar lo del error "No es posible aplicar una leyenda vac?a"
|
1172 |
auxLegend.addSymbol("-1asr12", symbol);
|
1173 |
} |
1174 |
} catch (Exception e) { |
1175 |
// TODO: ARREGLAR ESTO
|
1176 |
e.printStackTrace(); |
1177 |
} |
1178 |
|
1179 |
} catch (ServiceException e) {
|
1180 |
// TODO Auto-generated catch block
|
1181 |
e.printStackTrace(); |
1182 |
} |
1183 |
|
1184 |
// }
|
1185 |
this.theLegend = auxLegend;
|
1186 |
return theLegend;
|
1187 |
} |
1188 |
|
1189 |
|
1190 |
|
1191 |
private String getChartType() { |
1192 |
if(PieCb.isSelected())
|
1193 |
return "PieChart"; |
1194 |
if(BarsCb.isSelected())
|
1195 |
return "BarsChart"; |
1196 |
return "PieChart"; |
1197 |
} |
1198 |
|
1199 |
public Class getLegendClass() { |
1200 |
return LinkedChartLegend.class;
|
1201 |
} |
1202 |
|
1203 |
public JPanel getPanel() { |
1204 |
return this; |
1205 |
} |
1206 |
|
1207 |
public Class getParentClass() { |
1208 |
return MultipleAttributes.class;
|
1209 |
} |
1210 |
|
1211 |
public String getTitle() { |
1212 |
return PluginServices.getText(this, "linked_chart"); |
1213 |
} |
1214 |
|
1215 |
public boolean isSuitableFor(FLayer layer) { |
1216 |
return (layer instanceof FLyrVect); |
1217 |
} |
1218 |
|
1219 |
public void setData(FLayer layer, ILegend legend) { |
1220 |
this.layer = (FLyrVect) layer;
|
1221 |
try {
|
1222 |
shapeType = this.layer.getShapeType();
|
1223 |
} catch (ReadException e) {
|
1224 |
e.printStackTrace(); |
1225 |
} |
1226 |
//getBackgroundSymbol().setShapeType(shapeType);
|
1227 |
|
1228 |
fieldsTable = getFieldsTable(); |
1229 |
|
1230 |
fieldsTable.setSize(new Dimension(235, 129)); |
1231 |
fillFieldNames(); |
1232 |
|
1233 |
fieldsTable.removeAllItems(); |
1234 |
fillDestinationFieldNames((String)destinationTable.getSelectedItem());
|
1235 |
|
1236 |
if (legend instanceof IChartLegend) { |
1237 |
// TODO: PROVISIONAL. CREAMOS SIEMPRE LA LEYENDA PORQUE NO LA PODEMOS CLONAR TODAVIA.
|
1238 |
// auxLegend = (IChartLegend) legend.cloneLegend();
|
1239 |
auxLegend = (IChartLegend) legend; |
1240 |
|
1241 |
String[] fields = auxLegend.getClassifyingFieldNames(); |
1242 |
|
1243 |
if(auxLegend instanceof ILinkedChartLegend){ |
1244 |
ILinkedChartLegend leg = (ILinkedChartLegend) auxLegend; |
1245 |
|
1246 |
if(layer instanceof FLyrVect){ |
1247 |
this.layer = (FLyrVect) layer;
|
1248 |
fillOriginFieldNames(); |
1249 |
} |
1250 |
|
1251 |
destinationTable.setSelectedItem(leg.getLinkedTable()); |
1252 |
destinationField.setSelectedItem(leg.getLinkedField()); |
1253 |
destinationSelection.setSelected(leg.getLinkedSelected()); |
1254 |
|
1255 |
if(leg.getOriginFieldName().length>0){ |
1256 |
originField.setSelectedItem(leg.getOriginFieldName()[0]);
|
1257 |
} |
1258 |
originSelection.setSelected(leg.getOriginSelected()); |
1259 |
|
1260 |
fields = leg.getLinkedFields(); |
1261 |
|
1262 |
if(leg.getLegendType().equalsIgnoreCase("PieChart")){ |
1263 |
PieCb.setSelected(true);
|
1264 |
} |
1265 |
timeField.setSelectedItem(leg.getGroupedField()); |
1266 |
//timeField.setSelectedItem(leg.getTimeField());
|
1267 |
|
1268 |
} |
1269 |
ISymbol[] syms = auxLegend.getSymbols();
|
1270 |
if(syms.length>0){ |
1271 |
if(syms[0] instanceof IChartSymbol){ |
1272 |
IChartSymbol sb = (IChartSymbol)syms[0];
|
1273 |
if(sb.getChart().getChartType().equalsIgnoreCase("PieChart")){ |
1274 |
PieCb.setSelected(true);
|
1275 |
}else{
|
1276 |
BarsCb.setSelected(true);
|
1277 |
} |
1278 |
|
1279 |
} |
1280 |
} |
1281 |
|
1282 |
getJCheckBox().setSelected(auxLegend.isOutlineShow()); |
1283 |
// if (getColorButton().getGraphics()!=null)
|
1284 |
getColorButton().setColor(auxLegend.getOutlineColor()); |
1285 |
// getPreviewChart().setOutLineColor(auxLegend.getOutlineColor());
|
1286 |
// getPreviewChart().setOutlineWidth(auxLegend.getOutlineWidth());
|
1287 |
// getPreviewChart().setOutlineShow(auxLegend.isOutlineShow());
|
1288 |
getComboWidth().setInteger(auxLegend.getOutlineWidth()); |
1289 |
|
1290 |
getCk3D().setSelected(auxLegend.is3D()); |
1291 |
getCkOnlySelection().setSelected(auxLegend.isOnlySelection()); |
1292 |
|
1293 |
String[] labels = auxLegend.getFieldLabels(); |
1294 |
if(labels.length!= fields.length){
|
1295 |
String[] aux = new String[fields.length]; |
1296 |
for(int i=0; i<fields.length;i++){ |
1297 |
aux[i] = fields[i]; |
1298 |
} |
1299 |
labels = aux; |
1300 |
} |
1301 |
Color[] colors = auxLegend.getColors(); |
1302 |
if (colors != null) |
1303 |
getFieldsTable().fillTableFromSymbolList(colors, fields, labels); |
1304 |
// getPreviewChart().setSections(fields, colors);
|
1305 |
if (fields != null) { |
1306 |
for (int i = 0; i < fields.length; i++) { |
1307 |
((DefaultListModel) getJFieldList().getModel())
|
1308 |
.removeElement(fields[i]); |
1309 |
} |
1310 |
} |
1311 |
if(auxLegend instanceof ILinkedChartLegend){ |
1312 |
ILinkedChartLegend leg = (ILinkedChartLegend) auxLegend; |
1313 |
fillDestinationFieldNames(leg.getLinkedTable()); |
1314 |
} |
1315 |
|
1316 |
} else {
|
1317 |
auxLegend = (IChartLegend) MapContextLocator.getMapContextManager() |
1318 |
.createLegend(IChartLegend.LINKED_LEGEND_NAME); |
1319 |
|
1320 |
// ISymbol
|
1321 |
// backgroundSymbol=(ISymbol)SymbologyFactory.createSymbolFromXML(legend.getDefaultSymbol().getXMLEntity(),null);
|
1322 |
// auxLegend.setBackgroundSymbol(backgroundSymbol);
|
1323 |
} |
1324 |
getBackgroundSymbol().setSymbol(auxLegend.getBackgroundSymbol()); |
1325 |
|
1326 |
|
1327 |
// getPreviewChart().setBackgroundSymbol(auxLegend.getBackgroundSymbol());
|
1328 |
|
1329 |
} |
1330 |
|
1331 |
private boolean isNumericField(int fieldType) { |
1332 |
switch (fieldType) {
|
1333 |
case Types.BIGINT: |
1334 |
case Types.DECIMAL: |
1335 |
case Types.DOUBLE: |
1336 |
case Types.FLOAT: |
1337 |
case Types.INTEGER: |
1338 |
case Types.NUMERIC: |
1339 |
case Types.REAL: |
1340 |
case Types.SMALLINT: |
1341 |
case Types.TINYINT: |
1342 |
return true; |
1343 |
default:
|
1344 |
return false; |
1345 |
} |
1346 |
|
1347 |
} |
1348 |
|
1349 |
/**
|
1350 |
* This method initializes ckOnlySelection
|
1351 |
*
|
1352 |
* @return javax.swing.JCheckBox
|
1353 |
*/
|
1354 |
private JCheckBox getCkOnlySelection() { |
1355 |
if (ckOnlySelection == null) { |
1356 |
ckOnlySelection = new JCheckBox(); |
1357 |
ckOnlySelection.setText(PluginServices.getText(this,
|
1358 |
"only_selection"));
|
1359 |
ckOnlySelection |
1360 |
.addChangeListener(new javax.swing.event.ChangeListener() {
|
1361 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
1362 |
auxLegend.setOnlySelection(ckOnlySelection |
1363 |
.isSelected()); |
1364 |
} |
1365 |
}); |
1366 |
} |
1367 |
return ckOnlySelection;
|
1368 |
} |
1369 |
|
1370 |
} // @jve:decl-index=0:visual-constraint="10,10"
|