Revision 465
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/Main.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.chart.main; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.Color; |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
import java.beans.PropertyChangeEvent; |
|
30 |
import java.beans.PropertyChangeListener; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Properties; |
|
33 |
|
|
34 |
import javax.swing.AbstractAction; |
|
35 |
import javax.swing.Action; |
|
36 |
import javax.swing.JButton; |
|
37 |
import javax.swing.JComboBox; |
|
38 |
import javax.swing.JDialog; |
|
39 |
import javax.swing.JFrame; |
|
40 |
import javax.swing.JMenu; |
|
41 |
import javax.swing.JMenuBar; |
|
42 |
import javax.swing.JMenuItem; |
|
43 |
import javax.swing.JPanel; |
|
44 |
import javax.swing.JToolBar; |
|
45 |
import javax.swing.WindowConstants; |
|
46 |
|
|
47 |
import org.gvsig.chart.ChartLocator; |
|
48 |
import org.gvsig.chart.ChartProperties; |
|
49 |
import org.gvsig.chart.ChartService; |
|
50 |
import org.gvsig.chart.axis.ValueAxis; |
|
51 |
import org.gvsig.chart.base.bars.BarsChartProperties; |
|
52 |
import org.gvsig.chart.base.overlay.OverlayChartProperties; |
|
53 |
import org.gvsig.chart.base.pie.PieChartProperties; |
|
54 |
import org.gvsig.chart.lib.spi.ChartServiceManager; |
|
55 |
import org.gvsig.chart.main.panels.ChartPropertiesPanel; |
|
56 |
import org.gvsig.chart.main.panels.ChooseWindow; |
|
57 |
import org.gvsig.chart.model.DefaultChartDataSet; |
|
58 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
59 |
import org.gvsig.chart.swing.ChartSwingPanel; |
|
60 |
import org.gvsig.chart.swing.ChartWindowManager; |
|
61 |
import org.gvsig.chart.swing.spi.ChartPanel; |
|
62 |
import org.gvsig.chart.swing.spi.ChartSwingServiceManager; |
|
63 |
import org.gvsig.fmap.dal.DALLocator; |
|
64 |
import org.gvsig.fmap.dal.DataManager; |
|
65 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
66 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
67 |
import org.gvsig.fmap.mapcontrol.MapControlCreationException; |
|
68 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
|
69 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
70 |
import org.gvsig.tools.locator.LocatorException; |
|
71 |
import org.gvsig.tools.service.ServiceException; |
|
72 |
import org.slf4j.Logger; |
|
73 |
import org.slf4j.LoggerFactory; |
|
74 |
|
|
75 |
/** |
|
76 |
* Main executable class for testing the Chart library. |
|
77 |
* |
|
78 |
* @author gvSIG Team |
|
79 |
* @version $Id$ |
|
80 |
*/ |
|
81 |
public class Main { |
|
82 |
|
|
83 |
private static final Logger LOG = LoggerFactory.getLogger(Main.class); |
|
84 |
|
|
85 |
private static final String SHOWINFO_TOOL_NAME = "Chart.infotool"; |
|
86 |
|
|
87 |
private ChartServiceManager serviceManager; |
|
88 |
|
|
89 |
private MapControlManager mapControlManager; |
|
90 |
|
|
91 |
private MapControl mapControl; |
|
92 |
|
|
93 |
private ChartSwingServiceManager swingManager; |
|
94 |
|
|
95 |
private DataManager dataManager; |
|
96 |
|
|
97 |
private ChooseWindow choosePanel; |
|
98 |
|
|
99 |
private JComboBox keys; |
|
100 |
private JComboBox cols; |
|
101 |
private JComboBox rows; |
|
102 |
|
|
103 |
private Action xyPlotChart; |
|
104 |
private Action barChart; |
|
105 |
private Action pieChart; |
|
106 |
private Action makeChart; |
|
107 |
private Action makeOverlayedChart; |
|
108 |
private Action preferences; |
|
109 |
private Action exit; |
|
110 |
|
|
111 |
public String[] fields = { "compa?ia", "num_empleados", "facturaci?n", |
|
112 |
"facturaci?n2", "facturaci?n3", "facturaci?n4" }; |
|
113 |
|
|
114 |
private MainContext mainContext; |
|
115 |
|
|
116 |
private ChartPropertiesPanel propertiesPanel; |
|
117 |
|
|
118 |
public static void main(String args[]) throws MapControlCreationException, |
|
119 |
LocatorException, LoadLayerException { |
|
120 |
new DefaultLibrariesInitializer().fullInitialize(true); |
|
121 |
|
|
122 |
Main main = new Main(); |
|
123 |
main.show(); |
|
124 |
} |
|
125 |
|
|
126 |
public ChartServiceManager getServiceManager() { |
|
127 |
return serviceManager; |
|
128 |
} |
|
129 |
|
|
130 |
@SuppressWarnings("serial") |
|
131 |
public void show() throws MapControlCreationException, LocatorException, LoadLayerException { |
|
132 |
// LOG.info("Providers: " + DALLocator.getDataManager().getStoreProviders().toString()); |
|
133 |
|
|
134 |
serviceManager = ChartLocator.getServiceManager(); |
|
135 |
swingManager = ChartSwingLocator.getSwingManager(); |
|
136 |
dataManager = DALLocator.getDataManager(); |
|
137 |
|
|
138 |
mainContext = new MainContext(this); |
|
139 |
|
|
140 |
xyPlotChart = new AbstractAction("Get a XYPlotChart") { |
|
141 |
|
|
142 |
public void actionPerformed(ActionEvent e) { |
|
143 |
showXYPlotChart(serviceManager, createDataSet(fields[0], fields[2], fields[1])); |
|
144 |
} |
|
145 |
}; |
|
146 |
|
|
147 |
barChart = new AbstractAction("Get a BarChart") { |
|
148 |
|
|
149 |
public void actionPerformed(ActionEvent e) { |
|
150 |
showBarChart(serviceManager, createDataSet(fields[0], fields[2], fields[1])); |
|
151 |
} |
|
152 |
}; |
|
153 |
|
|
154 |
pieChart = new AbstractAction("Get a PieChart") { |
|
155 |
|
|
156 |
public void actionPerformed(ActionEvent e) { |
|
157 |
showPieChart(serviceManager, createDataSet(fields[0], fields[2], fields[1])); |
|
158 |
} |
|
159 |
}; |
|
160 |
|
|
161 |
makeChart = new AbstractAction("Make your chart") { |
|
162 |
|
|
163 |
public void actionPerformed(ActionEvent e) { |
|
164 |
chooseWindow(); |
|
165 |
} |
|
166 |
}; |
|
167 |
|
|
168 |
makeOverlayedChart = new AbstractAction("Make your overlayed chart") { |
|
169 |
|
|
170 |
public void actionPerformed(ActionEvent e) { |
|
171 |
makeOverlayedWindow(); |
|
172 |
} |
|
173 |
}; |
|
174 |
|
|
175 |
preferences = new AbstractAction("Chart preferences") { |
|
176 |
|
|
177 |
public void actionPerformed(ActionEvent e) { |
|
178 |
showExporttoPreferences(); |
|
179 |
} |
|
180 |
|
|
181 |
}; |
|
182 |
|
|
183 |
exit = new AbstractAction("Exit") { |
|
184 |
|
|
185 |
public void actionPerformed(ActionEvent e) { |
|
186 |
System.exit(0); |
|
187 |
} |
|
188 |
}; |
|
189 |
|
|
190 |
JFrame frame = new JFrame("Chart example app"); |
|
191 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
192 |
|
|
193 |
// Create the menu bar. |
|
194 |
JMenuBar menuBar = new JMenuBar(); |
|
195 |
|
|
196 |
// Build the menu. |
|
197 |
JMenu menuFile = new JMenu("File"); |
|
198 |
menuFile.add(new JMenuItem(xyPlotChart)); |
|
199 |
menuFile.add(new JMenuItem(barChart)); |
|
200 |
menuFile.add(new JMenuItem(pieChart)); |
|
201 |
// menuFile.add(new JMenuItem(makeChart)); |
|
202 |
menuFile.add(new JMenuItem(makeOverlayedChart)); |
|
203 |
menuFile.add(new JMenuItem(preferences)); |
|
204 |
menuFile.add(new JMenuItem(exit)); |
|
205 |
|
|
206 |
menuBar.add(menuFile); |
|
207 |
|
|
208 |
JToolBar toolBar = new JToolBar(); |
|
209 |
|
|
210 |
AbstractAction pieChartProps = new AbstractAction("Test PieChart Props panel") { |
|
211 |
|
|
212 |
public void actionPerformed(ActionEvent e) { |
|
213 |
try { |
|
214 |
PieChartProperties props = new PieChartProperties(); |
|
215 |
// OverlayChartProperties props = new OverlayChartProperties(); |
|
216 |
// ChartSwingPanel panelProps = swingManager.getChartSwingManager().createPanel(pieProps); |
|
217 |
// final JPanel panelProps = (JPanel) swingManager.getSwingServices().get(props.getChartType() + "Panel"); |
|
218 |
// Properties extendedProps = new Properties(); |
|
219 |
// ArrayList<String> tableNames = new ArrayList(); |
|
220 |
// tableNames.add("tabla1"); |
|
221 |
// tableNames.add("tabla2"); |
|
222 |
// extendedProps.put("tables", tableNames); |
|
223 |
DefaultDataPropertiesPanel panelProps = new DefaultDataPropertiesPanel(props,null); |
|
224 |
|
|
225 |
JDialog dlg = new JDialog(); |
|
226 |
dlg.getContentPane().add(panelProps); |
|
227 |
dlg.getContentPane().setPreferredSize(new Dimension(800, 400)); |
|
228 |
dlg.setSize(new Dimension(800, 400)); |
|
229 |
dlg.setVisible(true); |
|
230 |
|
|
231 |
} catch (Exception e1) { |
|
232 |
// TODO Auto-generated catch block |
|
233 |
e1.printStackTrace(); |
|
234 |
} |
|
235 |
} |
|
236 |
}; |
|
237 |
|
|
238 |
toolBar.add(new JButton(pieChartProps)); |
|
239 |
toolBar.add(new JButton(xyPlotChart)); |
|
240 |
toolBar.add(new JButton(barChart)); |
|
241 |
toolBar.add(new JButton(pieChart)); |
|
242 |
//toolBar.add(new JButton(makeChart)); |
|
243 |
toolBar.add(new JButton(makeOverlayedChart)); |
|
244 |
toolBar.add(new JButton(exit)); |
|
245 |
|
|
246 |
frame.setPreferredSize(new Dimension(800, 100)); |
|
247 |
frame.setJMenuBar(menuBar); |
|
248 |
frame.add(toolBar, BorderLayout.PAGE_START); |
|
249 |
|
|
250 |
// Display the window. |
|
251 |
frame.pack(); |
|
252 |
frame.setVisible(true); |
|
253 |
|
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
private void makeOverlayedWindow() { |
|
258 |
JFrame frame = new JFrame("Create a Chart"); |
|
259 |
propertiesPanel = new ChartPropertiesPanel(mainContext); |
|
260 |
|
|
261 |
frame.add(propertiesPanel, BorderLayout.CENTER); |
|
262 |
frame.setSize(1020, 680); |
|
263 |
frame.setVisible(true); |
|
264 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
265 |
} |
|
266 |
|
|
267 |
private void chooseWindow() { |
|
268 |
JFrame frame = new JFrame("Create a Chart"); |
|
269 |
choosePanel = new ChooseWindow(); |
|
270 |
|
|
271 |
JButton create = new JButton("create"); |
|
272 |
create.addActionListener(new ActionListener() { |
|
273 |
|
|
274 |
public void actionPerformed(ActionEvent arg0) { |
|
275 |
createCustomChart(); |
|
276 |
} |
|
277 |
}); |
|
278 |
frame.add(choosePanel, BorderLayout.CENTER); |
|
279 |
frame.add(create, BorderLayout.SOUTH); |
|
280 |
frame.setSize(400, 400); |
|
281 |
frame.setVisible(true); |
|
282 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
283 |
} |
|
284 |
|
|
285 |
public void createCustomChart() { |
|
286 |
|
|
287 |
DefaultChartDataSet dataset = createDataSet(choosePanel |
|
288 |
.getKeysComboBox().getSelectedItem().toString(), choosePanel |
|
289 |
.getRowsComboBox().getSelectedItem().toString(), choosePanel |
|
290 |
.getColsComboBox().getSelectedItem().toString()); |
|
291 |
|
|
292 |
if (choosePanel.getXyPlotChart().isSelected()) { |
|
293 |
showXYPlotChart(serviceManager, dataset); |
|
294 |
} |
|
295 |
if (choosePanel.getBarsChart().isSelected()) { |
|
296 |
showBarChart(serviceManager, dataset); |
|
297 |
} |
|
298 |
if (choosePanel.getPieChart().isSelected()) { |
|
299 |
showPieChart(serviceManager, dataset); |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
private void showExporttoPreferences() { |
|
304 |
// ChartSwingPreferencesComponent preferences = |
|
305 |
// ChartSwingProviderLocator.getManager() |
|
306 |
// .createExporttoSwingProvidersPreferences(); |
|
307 |
// |
|
308 |
// JFrame preferencesFrame = new JFrame("Export to preferences"); |
|
309 |
// preferencesFrame.add(preferences.asJComponent()); |
|
310 |
// |
|
311 |
// preferencesFrame.pack(); |
|
312 |
// preferencesFrame.setVisible(true); |
|
313 |
} |
|
314 |
|
|
315 |
public DefaultChartDataSet createDataSet(String keys, String rows, |
|
316 |
String cols) { |
|
317 |
DefaultChartDataSet dataSet = new DefaultChartDataSet(); |
|
318 |
Object[] key = { "McPato2", "BurgerRey2", "McPato2", "BurgerRey2", |
|
319 |
"BurgerRey2", "McPato2", "McPato2", "BurgerRey2", "McPato2", |
|
320 |
"BurgerRey2" }; |
|
321 |
Object[] y = { 1000, "500", 2000, 1000, 3000, 1500, 4000, 2000, 5000, |
|
322 |
"2500" }; |
|
323 |
Object[] y2 = { 500, "250", 1000, 500, 1500, 750, 2000, 1000, 2500, |
|
324 |
"1250" }; |
|
325 |
Object[] y3 = { 250, "125", 500, 250, 750, 375, 1000, 500, 1250, "625" }; |
|
326 |
Object[] y4 = { 100, "50", 200, 100, 300, 150, 400, 200, 500, "250" }; |
|
327 |
Object[] x = { 5, 5, 4, 4, "cat3", "xS3", 6, 6, 1, 1 }; |
|
328 |
|
|
329 |
ArrayList<Object> auxX = new ArrayList<Object>(); |
|
330 |
ArrayList<Object> auxY = new ArrayList<Object>(); |
|
331 |
ArrayList<Object> auxY2 = new ArrayList<Object>(); |
|
332 |
ArrayList<Object> auxY3 = new ArrayList<Object>(); |
|
333 |
ArrayList<Object> auxY4 = new ArrayList<Object>(); |
|
334 |
ArrayList<Object> auxKey = new ArrayList<Object>(); |
|
335 |
for (int i = 0; i < y.length; i++) { |
|
336 |
auxKey.add(key[i]); |
|
337 |
auxX.add(x[i]); |
|
338 |
auxY.add(y[i]); |
|
339 |
auxY2.add(y2[i]); |
|
340 |
auxY3.add(y3[i]); |
|
341 |
auxY4.add(y4[i]); |
|
342 |
} |
|
343 |
|
|
344 |
dataSet.setKeyField(keys); |
|
345 |
dataSet.setColumnField(cols); |
|
346 |
dataSet.setRowField(rows); |
|
347 |
|
|
348 |
dataSet.addData(fields[0], auxKey.iterator()); |
|
349 |
dataSet.addData(fields[1], auxX.iterator()); |
|
350 |
dataSet.addData(fields[2], auxY.iterator()); |
|
351 |
dataSet.addData(fields[3], auxY2.iterator()); |
|
352 |
dataSet.addData(fields[4], auxY3.iterator()); |
|
353 |
dataSet.addData(fields[5], auxY4.iterator()); |
|
354 |
|
|
355 |
return dataSet; |
|
356 |
} |
|
357 |
|
|
358 |
public void showXYPlotChart(ChartServiceManager manager, |
|
359 |
DefaultChartDataSet dataset) { |
|
360 |
|
|
361 |
try { |
|
362 |
ChartProperties props = swingManager.getChartSwingManager() |
|
363 |
.getServiceManager().getChartManager() |
|
364 |
.createProperties("XYPlotChart"); // PieChart //XYPlotChart |
|
365 |
ChartProperties props2 = swingManager.getChartSwingManager() |
|
366 |
.getServiceManager().getChartManager() |
|
367 |
.createProperties("XYPlotChart"); |
|
368 |
ChartProperties props_overlay = swingManager.getChartSwingManager() |
|
369 |
.getServiceManager().getChartManager() |
|
370 |
.createProperties("OverlayChart"); |
|
371 |
|
|
372 |
ChartService service_overlay = serviceManager.getChartManager() |
|
373 |
.createChart(props_overlay); |
|
374 |
ChartService service = serviceManager.getChartManager() |
|
375 |
.createChart(props); |
|
376 |
ChartService service2 = serviceManager.getChartManager() |
|
377 |
.createChart(props2); |
|
378 |
|
|
379 |
service.setChartDataSet(dataset); |
|
380 |
|
|
381 |
DefaultChartDataSet dataSet2 = new DefaultChartDataSet(); |
|
382 |
String[] key2 = { "McPato2", "BurgerRey2", "McPato2", "McPato2", |
|
383 |
"BurgerRey2" }; |
|
384 |
double[] y2 = { 1000, 2300, 3000, 4000, 5000 }; |
|
385 |
int[] x2 = { 8, 2, 5, 1, 3 }; |
|
386 |
|
|
387 |
ArrayList<Integer> auxX2 = new ArrayList<Integer>(); |
|
388 |
ArrayList<Double> auxY2 = new ArrayList<Double>(); |
|
389 |
for (int i = 0; i < key2.length; i++) { |
|
390 |
auxX2.add(x2[i]); |
|
391 |
auxY2.add(y2[i]); |
|
392 |
} |
|
393 |
dataSet2.addData(fields[0], key2); |
|
394 |
dataSet2.addData(fields[1], auxX2.iterator()); |
|
395 |
dataSet2.addData(fields[2], auxY2.iterator()); |
|
396 |
service2.setChartDataSet(dataset); |
|
397 |
|
|
398 |
// JFreeChart aux = (JFreeChart) service.getInnerChart(); |
|
399 |
// JFreeChart aux2 = (JFreeChart) service2.getInnerChart(); |
|
400 |
// service.getInnerChart().getXYPlot().getDomainAxis().setAutoRange(false); |
|
401 |
if (service.getDomainAxis() instanceof ValueAxis) { |
|
402 |
ValueAxis axis = (ValueAxis) service.getDomainAxis(); |
|
403 |
axis.setRange(0, 8); |
|
404 |
} |
|
405 |
|
|
406 |
// service.getInnerChart().getXYPlot().getDomainAxis().setLowerBound(0); |
|
407 |
// service.getInnerChart().getXYPlot().getDomainAxis().setUpperBound(8); |
|
408 |
// aux2.getXYPlot().getDomainAxis().setRange(0, 8); |
|
409 |
// aux2.getXYPlot().getRenderer().setSeriesPaint(0, Color.green); |
|
410 |
service2.getRenderer().setSeriesPaint(0, Color.green); |
|
411 |
|
|
412 |
ArrayList<ChartService> charts = new ArrayList<ChartService>(); |
|
413 |
charts.add(service); |
|
414 |
// charts.add(service2); |
|
415 |
|
|
416 |
((OverlayChartProperties) props_overlay).setCharts(charts); |
|
417 |
|
|
418 |
ChartSwingPanel panel = swingManager.getChartSwingManager() |
|
419 |
.createPanel(props_overlay); |
|
420 |
panel.setChartService(service_overlay); |
|
421 |
// ChartSwingDashboard panel = |
|
422 |
// swingManager.getChartSwingManager().createPanelDashboard(props); |
|
423 |
// ChartSwingTimeNavigator panel = |
|
424 |
// swingManager.getChartSwingManager().createPanelTimeNavigator(props); |
|
425 |
|
|
426 |
panel.setPreferredSize(new Dimension(800, 400)); |
|
427 |
swingManager |
|
428 |
.getChartSwingManager() |
|
429 |
.getWindowManager() |
|
430 |
.showWindow(panel, "Chart window", |
|
431 |
ChartWindowManager.MODE_WINDOW); |
|
432 |
} catch (Exception e) { |
|
433 |
LOG.error("Error showing a ChartPanel", e); |
|
434 |
} |
|
435 |
|
|
436 |
} |
|
437 |
|
|
438 |
public void showBarChart(ChartServiceManager manager, |
|
439 |
DefaultChartDataSet dataset) { |
|
440 |
|
|
441 |
try { |
|
442 |
ChartProperties props_bars2 = swingManager.getChartSwingManager() |
|
443 |
.getServiceManager().getChartManager() |
|
444 |
.createProperties("BarsChart"); |
|
445 |
ChartProperties props_bars = swingManager.getChartSwingManager() |
|
446 |
.getServiceManager().getChartManager() |
|
447 |
.createProperties("BarsChart"); |
|
448 |
ChartProperties props_overlay = swingManager.getChartSwingManager() |
|
449 |
.getServiceManager().getChartManager() |
|
450 |
.createProperties("OverlayChart"); |
|
451 |
|
|
452 |
ChartService service_overlay = serviceManager.getChartManager() |
|
453 |
.createChart(props_overlay); |
|
454 |
ChartService service_bars2 = serviceManager.getChartManager() |
|
455 |
.createChart(props_bars2); |
|
456 |
ChartService service_bars = serviceManager.getChartManager() |
|
457 |
.createChart(props_bars); |
|
458 |
|
|
459 |
((BarsChartProperties) props_bars).setXLabel("x"); |
|
460 |
((BarsChartProperties) props_bars).setYLabel("y"); |
|
461 |
((BarsChartProperties) props_bars2).setXLabel("x"); |
|
462 |
((BarsChartProperties) props_bars2).setYLabel("y"); |
|
463 |
|
|
464 |
((BarsChartProperties) props_bars2).setRendererType("BarRenderer"); |
|
465 |
|
|
466 |
service_bars.setChartDataSet(dataset); |
|
467 |
service_bars2.setChartDataSet(dataset); |
|
468 |
|
|
469 |
// JFreeChart bars_chart = (JFreeChart)service_bars.getInnerChart(); |
|
470 |
// BarRenderer renderer = new BarRenderer(); |
|
471 |
// bars_chart.getCategoryPlot().setRenderer(renderer); |
|
472 |
|
|
473 |
// JFreeChart bars_chart2 = |
|
474 |
// (JFreeChart)service_bars2.getInnerChart(); |
|
475 |
// |
|
476 |
// LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); |
|
477 |
// bars_chart2.getCategoryPlot().setRenderer(renderer2); |
|
478 |
|
|
479 |
ArrayList<ChartService> charts = new ArrayList<ChartService>(); |
|
480 |
charts.add(service_bars); |
|
481 |
charts.add(service_bars2); |
|
482 |
|
|
483 |
((OverlayChartProperties) props_overlay).setCharts(charts); |
|
484 |
|
|
485 |
ChartSwingPanel panel = swingManager.getChartSwingManager() |
|
486 |
.createPanel(props_overlay); |
|
487 |
panel.setChartService(service_overlay); |
|
488 |
// ChartSwingDashboard panel = |
|
489 |
// swingManager.getChartSwingManager().createPanelDashboard(props); |
|
490 |
// ChartSwingTimeNavigator panel = |
|
491 |
// swingManager.getChartSwingManager().createPanelTimeNavigator(props); |
|
492 |
|
|
493 |
panel.setPreferredSize(new Dimension(800, 400)); |
|
494 |
swingManager |
|
495 |
.getChartSwingManager() |
|
496 |
.getWindowManager() |
|
497 |
.showWindow(panel, "Chart window", |
|
498 |
ChartWindowManager.MODE_WINDOW); |
|
499 |
} catch (Exception e) { |
|
500 |
LOG.error("Error showing a ChartPanel", e); |
|
501 |
} |
|
502 |
|
|
503 |
} |
|
504 |
|
|
505 |
public void showPieChart(ChartServiceManager manager, |
|
506 |
DefaultChartDataSet dataset) { |
|
507 |
|
|
508 |
try { |
|
509 |
ChartProperties props_bars = swingManager.getChartSwingManager() |
|
510 |
.getServiceManager().getChartManager() |
|
511 |
.createProperties("PieChart"); |
|
512 |
ChartProperties props_overlay = swingManager.getChartSwingManager() |
|
513 |
.getServiceManager().getChartManager() |
|
514 |
.createProperties("OverlayChart"); |
|
515 |
|
|
516 |
ChartService service_overlay = serviceManager.getChartManager() |
|
517 |
.createChart(props_overlay); |
|
518 |
ChartService service_bars = serviceManager.getChartManager() |
|
519 |
.createChart(props_bars); |
|
520 |
|
|
521 |
service_bars.setChartDataSet(dataset); |
|
522 |
|
|
523 |
// JFreeChart bars_chart = (JFreeChart)service_bars.getInnerChart(); |
|
524 |
// PieRenderer renderer = new BarRenderer(); |
|
525 |
|
|
526 |
ArrayList<ChartService> charts = new ArrayList<ChartService>(); |
|
527 |
charts.add(service_bars); |
|
528 |
|
|
529 |
((OverlayChartProperties) props_overlay).setCharts(charts); |
|
530 |
|
|
531 |
ChartSwingPanel panel = swingManager.getChartSwingManager() |
|
532 |
.createPanel(props_overlay); |
|
533 |
panel.setChartService(service_overlay); |
|
534 |
// ChartSwingDashboard panel = |
|
535 |
// swingManager.getChartSwingManager().createPanelDashboard(props); |
|
536 |
// ChartSwingTimeNavigator panel = |
|
537 |
// swingManager.getChartSwingManager().createPanelTimeNavigator(props); |
|
538 |
|
|
539 |
panel.setPreferredSize(new Dimension(800, 400)); |
|
540 |
swingManager |
|
541 |
.getChartSwingManager() |
|
542 |
.getWindowManager() |
|
543 |
.showWindow(panel, "Chart window", |
|
544 |
ChartWindowManager.MODE_WINDOW); |
|
545 |
} catch (Exception e) { |
|
546 |
LOG.error("Error showing a ChartPanel", e); |
|
547 |
} |
|
548 |
|
|
549 |
} |
|
550 |
|
|
551 |
public MainContext getMainContext() { |
|
552 |
return mainContext; |
|
553 |
} |
|
554 |
|
|
555 |
} |
|
0 | 556 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/MainContext.java | ||
---|---|---|
1 |
package org.gvsig.chart.main; |
|
2 |
|
|
3 |
import org.gvsig.chart.ChartProperties; |
|
4 |
import org.gvsig.chart.model.DefaultChartDataSet; |
|
5 |
import org.gvsig.chart.model.variables.ObservableUsedChartServices; |
|
6 |
import org.gvsig.tools.observer.Observable; |
|
7 |
import org.gvsig.tools.observer.Observer; |
|
8 |
|
|
9 |
public class MainContext implements Observable{ |
|
10 |
|
|
11 |
private ObservableUsedChartServices<ChartProperties> chartProperties; |
|
12 |
private Main mainDocument; |
|
13 |
private DefaultChartDataSet dataset; |
|
14 |
|
|
15 |
public MainContext(Main main) { |
|
16 |
chartProperties = new ObservableUsedChartServices<ChartProperties>(null); |
|
17 |
mainDocument=main; |
|
18 |
dataset = mainDocument.createDataSet(mainDocument.fields[0],mainDocument.fields[1],mainDocument.fields[2]); |
|
19 |
} |
|
20 |
|
|
21 |
public void addObserver(Observer o) { |
|
22 |
// TODO Auto-generated method stub |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
public void deleteObserver(Observer o) { |
|
27 |
// TODO Auto-generated method stub |
|
28 |
|
|
29 |
} |
|
30 |
|
|
31 |
public void deleteObservers() { |
|
32 |
// TODO Auto-generated method stub |
|
33 |
|
|
34 |
} |
|
35 |
|
|
36 |
public ObservableUsedChartServices<ChartProperties> getChartProperties() { |
|
37 |
return chartProperties; |
|
38 |
} |
|
39 |
|
|
40 |
public Main getMainDocument() { |
|
41 |
return mainDocument; |
|
42 |
} |
|
43 |
|
|
44 |
// public void setDataset(DefaultChartDataSet dataset) { |
|
45 |
// this.dataset = dataset; |
|
46 |
// } |
|
47 |
|
|
48 |
public DefaultChartDataSet getDataset() { |
|
49 |
return dataset; |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
} |
|
0 | 54 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/DefaultDataPropertiesPanel.java | ||
---|---|---|
1 |
package org.gvsig.chart.main; |
|
2 |
|
|
3 |
import java.awt.GridBagConstraints; |
|
4 |
import java.awt.GridBagLayout; |
|
5 |
import java.awt.Insets; |
|
6 |
import java.awt.event.ActionEvent; |
|
7 |
import java.awt.event.ActionListener; |
|
8 |
import java.util.ArrayList; |
|
9 |
|
|
10 |
import javax.swing.JButton; |
|
11 |
import javax.swing.JComboBox; |
|
12 |
import javax.swing.JLabel; |
|
13 |
import javax.swing.SwingConstants; |
|
14 |
|
|
15 |
import org.gvsig.chart.ChartLocator; |
|
16 |
import org.gvsig.chart.ChartProperties; |
|
17 |
import org.gvsig.chart.lib.spi.ChartServiceManager; |
|
18 |
import org.gvsig.chart.main.panels.ChartUsedFieldPropertiesPanel; |
|
19 |
import org.gvsig.chart.main.utils.ChartJPanel; |
|
20 |
import org.gvsig.chart.model.variables.ObservableUsedChartServices; |
|
21 |
import org.gvsig.chart.model.variables.RequiredField; |
|
22 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
23 |
import org.gvsig.chart.swing.spi.ChartSwingServiceManager; |
|
24 |
|
|
25 |
public class DefaultDataPropertiesPanel extends ChartJPanel{ |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
*/ |
|
30 |
private static final long serialVersionUID = 3973104135478200344L; |
|
31 |
|
|
32 |
private ArrayList<JComboBox> cbos = new ArrayList<JComboBox>(); |
|
33 |
private JButton backButton; |
|
34 |
private JButton FinishButton; |
|
35 |
private JButton cancelButton; |
|
36 |
|
|
37 |
private ChartUsedFieldPropertiesPanel previousPanel; |
|
38 |
private ChartServiceManager serviceManager; |
|
39 |
private ChartSwingServiceManager swingManager; |
|
40 |
|
|
41 |
public DefaultDataPropertiesPanel(ChartProperties props, ChartUsedFieldPropertiesPanel chartUsedFieldPropertiesPanel) { |
|
42 |
|
|
43 |
this.previousPanel = chartUsedFieldPropertiesPanel; |
|
44 |
|
|
45 |
serviceManager = ChartLocator.getServiceManager(); |
|
46 |
swingManager = ChartSwingLocator.getSwingManager(); |
|
47 |
|
|
48 |
GridBagLayout gridBagLayout = new GridBagLayout(); |
|
49 |
setLayout(gridBagLayout); |
|
50 |
|
|
51 |
JLabel lblChartDataDefinition = new JLabel("Chart Data Definition"); |
|
52 |
GridBagConstraints gbc_lblChartDataDefinition = new GridBagConstraints(); |
|
53 |
gbc_lblChartDataDefinition.gridwidth = 4; |
|
54 |
gbc_lblChartDataDefinition.anchor = GridBagConstraints.WEST; |
|
55 |
gbc_lblChartDataDefinition.insets = new Insets(0, 0, 5, 0); |
|
56 |
gbc_lblChartDataDefinition.gridx = 0; |
|
57 |
gbc_lblChartDataDefinition.gridy = 0; |
|
58 |
add(lblChartDataDefinition, gbc_lblChartDataDefinition); |
|
59 |
|
|
60 |
// JLabel lblNewLabel = new JLabel("Tabla"); |
|
61 |
// add(lblNewLabel); |
|
62 |
// JComboBox cboTable = new JComboBox(); |
|
63 |
// add(cboTable); |
|
64 |
|
|
65 |
int i = 0; |
|
66 |
for (i = 0; i < props.getRequiredFields().size(); i++) { |
|
67 |
// RequiredField f = props.getRequiredFields().get(i); |
|
68 |
// JLabel lbl = new JLabel(f.getDescription()); |
|
69 |
// add(lbl); |
|
70 |
// JComboBox cbo = new JComboBox(); |
|
71 |
// cbo.setName("cbo" + f.getName()); |
|
72 |
// cbos.add(cbo); |
|
73 |
// add(cbo); |
|
74 |
|
|
75 |
RequiredField f = props.getRequiredFields().get(i); |
|
76 |
JLabel lblNewLabel = new JLabel(f.getDescription()); |
|
77 |
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); |
|
78 |
gbc_lblNewLabel.fill = GridBagConstraints.BOTH; |
|
79 |
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5); |
|
80 |
gbc_lblNewLabel.gridx = 0; |
|
81 |
gbc_lblNewLabel.gridy = 1+i; |
|
82 |
add(lblNewLabel, gbc_lblNewLabel); |
|
83 |
JComboBox cboTable = new JComboBox(); |
|
84 |
GridBagConstraints gbc_cboTable = new GridBagConstraints(); |
|
85 |
gbc_cboTable.gridwidth = 3; |
|
86 |
gbc_cboTable.insets = new Insets(0, 0, 5, 0); |
|
87 |
gbc_cboTable.fill = GridBagConstraints.BOTH; |
|
88 |
gbc_cboTable.gridx = 1; |
|
89 |
gbc_cboTable.gridy = 1+i; |
|
90 |
add(cboTable, gbc_cboTable); |
|
91 |
|
|
92 |
cbos.add(cboTable); |
|
93 |
} |
|
94 |
|
|
95 |
backButton = new JButton("< Back"); |
|
96 |
backButton.setHorizontalAlignment(SwingConstants.LEFT); |
|
97 |
GridBagConstraints gbc_backButton = new GridBagConstraints(); |
|
98 |
gbc_backButton.anchor = GridBagConstraints.EAST; |
|
99 |
gbc_backButton.insets = new Insets(0, 0, 0, 5); |
|
100 |
gbc_backButton.gridx = 1; |
|
101 |
gbc_backButton.gridy = 3+i; |
|
102 |
add(backButton, gbc_backButton); |
|
103 |
|
|
104 |
FinishButton = new JButton("Finish"); |
|
105 |
GridBagConstraints gbc_FinishButton = new GridBagConstraints(); |
|
106 |
gbc_FinishButton.insets = new Insets(0, 0, 0, 5); |
|
107 |
gbc_FinishButton.gridx = 2; |
|
108 |
gbc_FinishButton.gridy = 3+i; |
|
109 |
add(FinishButton, gbc_FinishButton); |
|
110 |
|
|
111 |
cancelButton = new JButton("Cancel"); |
|
112 |
GridBagConstraints gbc_cancelButton = new GridBagConstraints(); |
|
113 |
gbc_cancelButton.gridx = 3; |
|
114 |
gbc_cancelButton.gridy = 3+i; |
|
115 |
add(cancelButton, gbc_cancelButton); |
|
116 |
|
|
117 |
createButtons(); |
|
118 |
} |
|
119 |
|
|
120 |
private void createButtons(){ |
|
121 |
backButton.addActionListener(new ActionListener() { |
|
122 |
public void actionPerformed(ActionEvent e) { |
|
123 |
backForm(); |
|
124 |
} |
|
125 |
}); |
|
126 |
|
|
127 |
cancelButton.addActionListener(new ActionListener() { |
|
128 |
public void actionPerformed(ActionEvent e) { |
|
129 |
cancelForm(); |
|
130 |
} |
|
131 |
}); |
|
132 |
|
|
133 |
FinishButton.addActionListener(new ActionListener() { |
|
134 |
public void actionPerformed(ActionEvent e) { |
|
135 |
finishForm(); |
|
136 |
} |
|
137 |
}); |
|
138 |
} |
|
139 |
|
|
140 |
private void cancelForm() { |
|
141 |
this.setVisible(false); |
|
142 |
this.getParentWindow().setVisible(false); |
|
143 |
} |
|
144 |
|
|
145 |
private void finishForm() { |
|
146 |
this.setVisible(false); |
|
147 |
this.getParentWindow().setVisible(false); |
|
148 |
|
|
149 |
if(validateValues()){ |
|
150 |
this.getParametersToChartProperties(); |
|
151 |
|
|
152 |
ObservableUsedChartServices<ChartProperties> properties = this.getPreviousPanel().getMainContext().getChartProperties(); |
|
153 |
if(this.getPreviousPanel().getPreviousChartProperties()!=null){ |
|
154 |
int index = properties.indexOf(this.getPreviousPanel().getPreviousChartProperties()); |
|
155 |
if(index != -1){ |
|
156 |
properties.set(index, this.getPreviousPanel().getChartProperties()); |
|
157 |
} |
|
158 |
}else{ |
|
159 |
properties.add(this.getPreviousPanel().getChartProperties()); |
|
160 |
} |
|
161 |
|
|
162 |
// // TODO Provisional |
|
163 |
// try { |
|
164 |
// ChartProperties props_overlay = serviceManager.getChartManager() |
|
165 |
// .createProperties("OverlayChart"); |
|
166 |
// |
|
167 |
// ChartService service_overlay = serviceManager.getChartManager() |
|
168 |
// .createChart(props_overlay); |
|
169 |
// |
|
170 |
// ChartService service_chart = serviceManager.getChartManager() |
|
171 |
// .createChart(this.chartProperties); |
|
172 |
// |
|
173 |
// service_chart.setChartDataSet(((AbstractChart) service_chart).createDataSet()); |
|
174 |
// |
|
175 |
// ArrayList<ChartService> charts = new ArrayList<ChartService>(); |
|
176 |
// charts.add(service_chart); |
|
177 |
// |
|
178 |
// ((OverlayChartProperties) props_overlay).setCharts(charts); |
|
179 |
// |
|
180 |
// ChartSwingPanel panel = swingManager.getChartSwingManager() |
|
181 |
// .createPanel(props_overlay); |
|
182 |
// panel.setChartService(service_overlay); |
|
183 |
// |
|
184 |
// panel.setPreferredSize(new Dimension(800, 400)); |
|
185 |
// swingManager |
|
186 |
// .getChartSwingManager() |
|
187 |
// .getWindowManager() |
|
188 |
// .showWindow(panel, "Chart window", |
|
189 |
// ChartWindowManager.MODE_WINDOW); |
|
190 |
// |
|
191 |
// } catch (ServiceException e) { |
|
192 |
// // TODO Auto-generated catch block |
|
193 |
// e.printStackTrace(); |
|
194 |
// } |
|
195 |
}else{ |
|
196 |
|
|
197 |
} |
|
198 |
|
|
199 |
|
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Check if the values have the correct format |
|
204 |
* @return boolean |
|
205 |
*/ |
|
206 |
private boolean validateValues() { |
|
207 |
// TODO Auto-generated method stub |
|
208 |
return true; |
|
209 |
} |
|
210 |
|
|
211 |
// Rellena el ChartProperties con el contenido de los 2 paneles |
|
212 |
private void getParametersToChartProperties() { |
|
213 |
this.getPreviousPanel().getChartProperties(); |
|
214 |
this.getChartProperties(); |
|
215 |
} |
|
216 |
|
|
217 |
private void backForm() { |
|
218 |
this.setVisible(false); |
|
219 |
this.getParentWindow().setVisible(false); |
|
220 |
|
|
221 |
this.getPreviousPanel().setVisible(true); |
|
222 |
this.getPreviousPanel().getParentWindow().setVisible(true); |
|
223 |
|
|
224 |
} |
|
225 |
|
|
226 |
public void getChartProperties(){ |
|
227 |
ChartProperties chartProperties = this.getPreviousPanel().getChartProperties(); |
|
228 |
for (int i = 0; i < chartProperties.getRequiredFields().size(); i++) { |
|
229 |
RequiredField f = chartProperties.getRequiredFields().get(i); |
|
230 |
JComboBox cbo = cbos.get(i); |
|
231 |
f.setValue(cbo.getSelectedItem().toString()); |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
public ChartUsedFieldPropertiesPanel getPreviousPanel() { |
|
236 |
return previousPanel; |
|
237 |
} |
|
238 |
} |
|
0 | 239 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/package.html | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
4 |
<head> |
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|
6 |
<title>org.gvsig.construc package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>Construc library testing and demo application.</p> |
|
11 |
|
|
12 |
</body> |
|
13 |
</html> |
|
0 | 14 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/utils/ChartEntry.java | ||
---|---|---|
1 |
package org.gvsig.chart.main.utils; |
|
2 |
|
|
3 |
import javax.swing.ImageIcon; |
|
4 |
|
|
5 |
import org.gvsig.andami.PluginServices; |
|
6 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
7 |
import org.gvsig.chart.swing.spi.panels.ChartServiceTypePanel; |
|
8 |
import org.gvsig.fmap.IconThemeHelper; |
|
9 |
|
|
10 |
/** |
|
11 |
* Clase que define una entrada de la lista de Charts registrados. |
|
12 |
* Contiene el identificador, el nombre, icono y la preview. |
|
13 |
*/ |
|
14 |
public class ChartEntry { |
|
15 |
private final String id; |
|
16 |
private final String title; |
|
17 |
private ImageIcon icon; |
|
18 |
private ImageIcon image; |
|
19 |
|
|
20 |
public ChartEntry(String id, String title) { |
|
21 |
this.id = id; |
|
22 |
this.title = title; |
|
23 |
} |
|
24 |
|
|
25 |
public String getChartType() { |
|
26 |
return id; |
|
27 |
} |
|
28 |
|
|
29 |
public String getChartPanelType() { |
|
30 |
return id + "Panel"; |
|
31 |
} |
|
32 |
|
|
33 |
public String getTitle() { |
|
34 |
return title; |
|
35 |
} |
|
36 |
|
|
37 |
public ImageIcon getIcon() { |
|
38 |
if (icon == null) { |
|
39 |
ChartServiceTypePanel panel = ChartSwingLocator.getSwingManager().getSwingServices().get(this.getChartPanelType()); |
|
40 |
if(panel!=null) |
|
41 |
icon = panel.getChartIcon(); |
|
42 |
} |
|
43 |
if (icon==null) |
|
44 |
icon = IconThemeHelper.getImageIcon("no-chart-icon"); |
|
45 |
return icon; |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
public String toString() { |
|
50 |
return title; |
|
51 |
} |
|
52 |
|
|
53 |
public ImageIcon getExampleImage() { |
|
54 |
if (image == null) { |
|
55 |
ChartServiceTypePanel panel = ChartSwingLocator.getSwingManager().getSwingServices().get(this.getChartPanelType()); |
|
56 |
if(panel!=null) |
|
57 |
image = panel.getChartExample(); |
|
58 |
} |
|
59 |
if (image==null) |
|
60 |
image = IconThemeHelper.getImageIcon("no-chart-example"); |
|
61 |
return image; |
|
62 |
} |
|
63 |
} |
|
0 | 64 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/utils/ChartCellRenderer.java | ||
---|---|---|
1 |
package org.gvsig.chart.main.utils; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Component; |
|
5 |
|
|
6 |
import javax.swing.JLabel; |
|
7 |
import javax.swing.JList; |
|
8 |
import javax.swing.JPanel; |
|
9 |
import javax.swing.JTable; |
|
10 |
import javax.swing.ListCellRenderer; |
|
11 |
import javax.swing.table.TableCellRenderer; |
|
12 |
|
|
13 |
|
|
14 |
public class ChartCellRenderer extends JLabel implements ListCellRenderer, TableCellRenderer { |
|
15 |
/** |
|
16 |
* |
|
17 |
*/ |
|
18 |
private static final long serialVersionUID = 1493992436327160367L; |
|
19 |
private final Color HIGHLIGHT_COLOR = new Color(195, 212, 232); |
|
20 |
private JPanel parentPanel; |
|
21 |
|
|
22 |
public ChartCellRenderer(JPanel parentPanel) { |
|
23 |
setOpaque(true); |
|
24 |
setIconTextGap(12); |
|
25 |
this.parentPanel = parentPanel; |
|
26 |
} |
|
27 |
|
|
28 |
public Component getListCellRendererComponent(JList list, Object value, |
|
29 |
int index, boolean isSelected, boolean cellHasFocus) { |
|
30 |
ChartEntry entry = (ChartEntry) value; |
|
31 |
setText(entry.getTitle()); |
|
32 |
setIcon(entry.getIcon()); |
|
33 |
if (isSelected) { |
|
34 |
setBackground(HIGHLIGHT_COLOR); |
|
35 |
setForeground(Color.black); |
|
36 |
} else { |
|
37 |
setBackground(Color.white); |
|
38 |
setForeground(Color.black); |
|
39 |
} |
|
40 |
return this; |
|
41 |
} |
|
42 |
|
|
43 |
public JPanel getParentPanel() { |
|
44 |
return parentPanel; |
|
45 |
} |
|
46 |
|
|
47 |
public Component getTableCellRendererComponent(JTable table, Object value, |
|
48 |
boolean isSelected, boolean arg3, int arg4, int arg5) { |
|
49 |
if(value==null) |
|
50 |
return null; |
|
51 |
ChartEntry entry = (ChartEntry) value; |
|
52 |
setText(entry.getTitle()); |
|
53 |
setIcon(entry.getIcon()); |
|
54 |
if (isSelected) { |
|
55 |
setBackground(HIGHLIGHT_COLOR); |
|
56 |
setForeground(Color.black); |
|
57 |
} else { |
|
58 |
setBackground(Color.white); |
|
59 |
setForeground(Color.black); |
|
60 |
} |
|
61 |
return this; |
|
62 |
} |
|
63 |
} |
|
0 | 64 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/utils/ChartJDialog.java | ||
---|---|---|
1 |
package org.gvsig.chart.main.utils; |
|
2 |
|
|
3 |
import java.awt.event.ComponentEvent; |
|
4 |
import java.awt.event.ComponentListener; |
|
5 |
|
|
6 |
import javax.swing.JDialog; |
|
7 |
import javax.swing.JPanel; |
|
8 |
|
|
9 |
public class ChartJDialog extends JDialog implements ComponentListener{ |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
*/ |
|
14 |
private static final long serialVersionUID = -1850855026936065122L; |
|
15 |
|
|
16 |
private ChartJPanel panel; |
|
17 |
|
|
18 |
public ChartJDialog(ChartJPanel panel){ |
|
19 |
this.panel = panel; |
|
20 |
this.panel.setParentWindow(this); |
|
21 |
panel.addComponentListener(this); |
|
22 |
getContentPane().add(panel); |
|
23 |
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
|
24 |
setModal(true); |
|
25 |
|
|
26 |
pack(); |
|
27 |
setVisible(true); |
|
28 |
} |
|
29 |
|
|
30 |
public void componentHidden(ComponentEvent e) { |
|
31 |
this.dispose(); |
|
32 |
} |
|
33 |
|
|
34 |
public void componentMoved(ComponentEvent e) { |
|
35 |
// TODO Auto-generated method stub |
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
public void componentResized(ComponentEvent e) { |
|
40 |
// TODO Auto-generated method stub |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
public void componentShown(ComponentEvent e) { |
|
45 |
// TODO Auto-generated method stub |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
public JPanel getContentPanel() { |
|
50 |
return panel; |
|
51 |
} |
|
52 |
|
|
53 |
} |
|
0 | 54 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/utils/ChartJPanel.java | ||
---|---|---|
1 |
package org.gvsig.chart.main.utils; |
|
2 |
|
|
3 |
import javax.swing.JPanel; |
|
4 |
|
|
5 |
public class ChartJPanel extends JPanel{ |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = 1L; |
|
11 |
private ChartJDialog chartParentWindow; |
|
12 |
|
|
13 |
public void setParentWindow(ChartJDialog jDialog){ |
|
14 |
this.chartParentWindow = jDialog; |
|
15 |
} |
|
16 |
|
|
17 |
public ChartJDialog getParentWindow(){ |
|
18 |
return chartParentWindow; |
|
19 |
} |
|
20 |
} |
|
0 | 21 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/utils/CheckBoxRenderer.java | ||
---|---|---|
1 |
package org.gvsig.chart.main.utils; |
|
2 |
|
|
3 |
import java.awt.Component; |
|
4 |
|
|
5 |
import javax.swing.JCheckBox; |
|
6 |
import javax.swing.JLabel; |
|
7 |
import javax.swing.JTable; |
|
8 |
import javax.swing.table.TableCellRenderer; |
|
9 |
|
|
10 |
public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer { |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
*/ |
|
15 |
private static final long serialVersionUID = 3586418802127664068L; |
|
16 |
|
|
17 |
public CheckBoxRenderer() { |
|
18 |
setHorizontalAlignment(JLabel.CENTER); |
|
19 |
} |
|
20 |
|
|
21 |
public Component getTableCellRendererComponent(JTable table, Object value, |
|
22 |
boolean isSelected, boolean hasFocus, int row, int column) { |
|
23 |
if (isSelected) { |
|
24 |
setForeground(table.getSelectionForeground()); |
|
25 |
//super.setBackground(table.getSelectionBackground()); |
|
26 |
setBackground(table.getSelectionBackground()); |
|
27 |
} else { |
|
28 |
setForeground(table.getForeground()); |
|
29 |
setBackground(table.getBackground()); |
|
30 |
} |
|
31 |
setSelected((value != null && ((Boolean) value).booleanValue())); |
|
32 |
return this; |
|
33 |
} |
|
34 |
} |
|
35 |
|
|
0 | 36 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.81/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/panels/ChartPropertiesPanel.java | ||
---|---|---|
1 |
package org.gvsig.chart.main.panels; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
import java.awt.GridBagConstraints; |
|
5 |
import java.awt.GridBagLayout; |
|
6 |
import java.awt.Insets; |
|
7 |
import java.awt.event.ActionEvent; |
|
8 |
import java.awt.event.ActionListener; |
|
9 |
import java.awt.event.MouseEvent; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.Iterator; |
|
12 |
import java.util.List; |
|
13 |
|
|
14 |
import javax.swing.DefaultListModel; |
|
15 |
import javax.swing.ImageIcon; |
|
16 |
import javax.swing.JButton; |
|
17 |
import javax.swing.JLabel; |
|
18 |
import javax.swing.JList; |
|
19 |
import javax.swing.JPanel; |
|
20 |
import javax.swing.JScrollPane; |
|
21 |
import javax.swing.JTable; |
|
22 |
import javax.swing.ListSelectionModel; |
|
23 |
import javax.swing.event.ListSelectionEvent; |
|
24 |
import javax.swing.event.ListSelectionListener; |
|
25 |
import javax.swing.table.DefaultTableModel; |
|
26 |
|
|
27 |
import org.gvsig.andami.PluginServices; |
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
29 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
30 |
import org.gvsig.chart.ChartLocator; |
|
31 |
import org.gvsig.chart.ChartProperties; |
|
32 |
import org.gvsig.chart.ChartService; |
|
33 |
import org.gvsig.chart.base.overlay.OverlayChartProperties; |
|
34 |
import org.gvsig.chart.lib.spi.ChartServiceManager; |
|
35 |
import org.gvsig.chart.main.MainContext; |
|
36 |
import org.gvsig.chart.main.utils.ChartCellRenderer; |
|
37 |
import org.gvsig.chart.main.utils.ChartEntry; |
|
38 |
import org.gvsig.chart.main.utils.ChartJDialog; |
|
39 |
import org.gvsig.chart.main.utils.CheckBoxRenderer; |
|
40 |
import org.gvsig.chart.model.DefaultChartDataSet; |
|
41 |
import org.gvsig.chart.model.variables.ObservableUsedChartServices; |
|
42 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
43 |
import org.gvsig.chart.swing.ChartSwingPanel; |
|
44 |
import org.gvsig.chart.swing.ChartWindowManager; |
|
45 |
import org.gvsig.chart.swing.spi.ChartSwingServiceManager; |
|
46 |
import org.gvsig.fmap.IconThemeHelper; |
|
47 |
import org.gvsig.tools.service.ServiceException; |
|
48 |
import javax.swing.border.LineBorder; |
|
49 |
import java.awt.Color; |
|
50 |
|
|
51 |
public class ChartPropertiesPanel extends JPanel implements IWindow, ActionListener, ListSelectionListener{ |
|
52 |
|
|
53 |
/** |
|
54 |
* |
|
55 |
*/ |
|
56 |
private static final long serialVersionUID = -301224990996378683L; |
|
57 |
private MainContext chartDocument; |
|
58 |
private JButton accept; |
|
59 |
private JButton cancel; |
|
60 |
|
|
61 |
private String selectedChartType = null; |
|
62 |
|
|
63 |
private JPanel panel_chartType = null; |
|
64 |
|
|
65 |
private JLabel previewImageLabel = new JLabel(); |
|
66 |
private JLabel chartOptionsLabel; |
|
67 |
|
|
68 |
private DefaultListModel listModel; |
|
69 |
|
|
70 |
private JButton addButton; |
|
71 |
private JTable table; |
|
72 |
private DefaultTableModel tableModel; |
|
73 |
private JButton editButton; |
|
74 |
private JButton deleteButton; |
|
75 |
|
|
76 |
private ChartPropertiesPanelObserver<ChartProperties> chartPropertiesObserver; |
|
77 |
private JList list; |
|
78 |
private ChartSwingServiceManager swingManager; |
|
79 |
private ChartServiceManager serviceManager; |
|
80 |
private JButton upButton; |
|
81 |
private JButton downButton; |
|
82 |
private JLabel lblChartPreview; |
|
83 |
private JPanel previewPanel; |
|
84 |
|
|
85 |
public ChartPropertiesPanel(MainContext doc) { |
|
86 |
serviceManager = ChartLocator.getServiceManager(); |
|
87 |
swingManager = ChartSwingLocator.getSwingManager(); |
|
88 |
|
|
89 |
chartDocument = doc; |
|
90 |
listModel = getCharts(); |
|
91 |
|
|
92 |
chartPropertiesObserver = new ChartPropertiesPanelObserver<ChartProperties>(this); |
|
93 |
doc.getChartProperties().registerObserver(chartPropertiesObserver); |
|
94 |
|
|
95 |
createMainPanel(); |
|
96 |
createButtonPanelEvents(); |
|
97 |
|
|
98 |
initializeChartList(); |
|
99 |
initialize(); |
|
100 |
} |
|
101 |
|
|
102 |
private void createMainPanel(){ |
|
103 |
GridBagLayout gridBagLayout = new GridBagLayout(); |
|
104 |
gridBagLayout.columnWidths = new int[]{303, 0, 0, 445, 102}; |
|
105 |
|
|
106 |
setLayout(gridBagLayout); |
|
107 |
|
|
108 |
lblChartPreview = new JLabel("Chart preview"); |
|
109 |
GridBagConstraints gbc_lblChartPreview = new GridBagConstraints(); |
|
110 |
gbc_lblChartPreview.gridwidth = 4; |
|
111 |
gbc_lblChartPreview.anchor = GridBagConstraints.WEST; |
|
112 |
gbc_lblChartPreview.insets = new Insets(0, 0, 5, 5); |
|
113 |
gbc_lblChartPreview.gridx = 0; |
|
114 |
gbc_lblChartPreview.gridy = 0; |
|
115 |
add(lblChartPreview, gbc_lblChartPreview); |
|
116 |
|
|
117 |
GridBagConstraints gbc_panel_chartType = new GridBagConstraints(); |
|
118 |
gbc_panel_chartType.gridheight = 2; |
|
119 |
gbc_panel_chartType.insets = new Insets(0, 0, 5, 0); |
|
120 |
gbc_panel_chartType.gridy = 1; |
|
121 |
gbc_panel_chartType.gridwidth = 5; |
|
122 |
gbc_panel_chartType.gridx = 0; |
|
123 |
add(getTypePanel(), gbc_panel_chartType); |
|
124 |
|
|
125 |
accept = new JButton("accept"); |
|
126 |
GridBagConstraints gbc_accept = new GridBagConstraints(); |
|
127 |
gbc_accept.anchor = GridBagConstraints.EAST; |
|
128 |
gbc_accept.insets = new Insets(0, 0, 0, 5); |
|
129 |
gbc_accept.gridx = 3; |
|
130 |
gbc_accept.gridy = 4; |
|
131 |
add(accept, gbc_accept); |
|
132 |
|
|
133 |
cancel = new JButton("Cancel"); |
|
134 |
GridBagConstraints gbc_cancel = new GridBagConstraints(); |
|
135 |
gbc_cancel.anchor = GridBagConstraints.WEST; |
|
136 |
gbc_cancel.gridx = 4; |
|
137 |
gbc_cancel.gridy = 4; |
|
138 |
add(cancel, gbc_cancel); |
|
139 |
|
|
140 |
} |
|
141 |
|
|
142 |
private JPanel getTypePanel(){ |
|
143 |
if (panel_chartType==null){ |
|
144 |
panel_chartType = new JPanel(); |
|
145 |
|
|
146 |
GridBagLayout gbl_panel_chartType = new GridBagLayout(); |
|
147 |
gbl_panel_chartType.columnWidths = new int[]{540, 0, 0, 210, 198, 56, 0}; |
|
148 |
gbl_panel_chartType.rowHeights = new int[]{0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
|
149 |
gbl_panel_chartType.columnWeights = new double[]{1.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE}; |
|
150 |
gbl_panel_chartType.rowWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; |
|
151 |
panel_chartType.setLayout(gbl_panel_chartType); |
|
152 |
|
|
153 |
previewPanel = new JPanel(); |
|
154 |
previewPanel.setBackground(Color.WHITE); |
|
155 |
previewPanel.setBorder(new LineBorder(new Color(0, 0, 0))); |
|
156 |
GridBagConstraints gbc_previewPanel = new GridBagConstraints(); |
|
157 |
gbc_previewPanel.gridheight = 2; |
|
158 |
gbc_previewPanel.gridwidth = 6; |
|
159 |
gbc_previewPanel.insets = new Insets(0, 0, 5, 5); |
|
160 |
gbc_previewPanel.fill = GridBagConstraints.BOTH; |
|
161 |
gbc_previewPanel.gridx = 0; |
|
162 |
gbc_previewPanel.gridy = 0; |
|
163 |
panel_chartType.add(previewPanel, gbc_previewPanel); |
|
164 |
|
|
165 |
|
|
166 |
chartOptionsLabel= new JLabel("Chart variables"); |
|
167 |
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints(); |
|
168 |
gbc_lblNewLabel_3.anchor = GridBagConstraints.WEST; |
|
169 |
gbc_lblNewLabel_3.gridwidth = 4; |
|
170 |
gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5); |
|
171 |
gbc_lblNewLabel_3.gridx = 0; |
|
172 |
gbc_lblNewLabel_3.gridy = 3; |
|
173 |
panel_chartType.add(chartOptionsLabel, gbc_lblNewLabel_3); |
|
174 |
|
|
175 |
table = new JTable(){ |
|
176 |
/** |
|
177 |
* |
|
178 |
*/ |
|
179 |
private static final long serialVersionUID = -352323096347454258L; |
|
180 |
|
|
181 |
public boolean isCellEditable(int rowIndex, int colIndex) { |
|
182 |
if(colIndex==0) |
|
183 |
return true; |
|
184 |
return false; //Disallow the editing of any cell |
|
185 |
} |
|
186 |
|
|
187 |
public String getToolTipText(MouseEvent e) { |
|
188 |
String tip = null; |
|
189 |
List<ChartProperties> usedFields = getDocument().getChartProperties(); |
|
190 |
|
|
191 |
java.awt.Point p = e.getPoint(); |
|
192 |
int rowIndex = rowAtPoint(p); |
|
193 |
int colIndex = columnAtPoint(p); |
|
194 |
int realColumnIndex = convertColumnIndexToModel(colIndex); |
|
195 |
|
|
196 |
if (realColumnIndex == 0) { //Sport column |
|
197 |
tip = usedFields.get(rowIndex).getChartName(); |
|
198 |
} |
|
199 |
return tip; |
|
200 |
} |
|
201 |
}; |
|
202 |
|
|
203 |
GridBagConstraints gbc_table = new GridBagConstraints(); |
|
204 |
gbc_table.gridheight = 6; |
|
205 |
gbc_table.gridwidth = 5; |
|
206 |
gbc_table.insets = new Insets(0, 0, 0, 5); |
|
207 |
gbc_table.fill = GridBagConstraints.BOTH; |
|
208 |
gbc_table.gridx = 0; |
|
209 |
gbc_table.gridy = 4; |
|
210 |
//panel_chartType.add(table, gbc_table); |
|
211 |
JScrollPane scrollPane = new JScrollPane(table); |
|
212 |
panel_chartType.add(scrollPane, gbc_table); |
|
213 |
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
214 |
|
|
215 |
upButton = new JButton(""); |
|
216 |
upButton.setIcon(new ImageIcon(ChartPropertiesPanel.class.getResource("/icons/arrow_up.png"))); |
|
217 |
GridBagConstraints gbc_upButton = new GridBagConstraints(); |
|
218 |
gbc_upButton.insets = new Insets(0, 0, 5, 0); |
|
219 |
gbc_upButton.gridx = 5; |
|
220 |
gbc_upButton.gridy = 4; |
|
221 |
panel_chartType.add(upButton, gbc_upButton); |
|
222 |
|
|
223 |
downButton = new JButton(""); |
|
224 |
downButton.setIcon(new ImageIcon(ChartPropertiesPanel.class.getResource("/icons/arrow_down.png"))); |
|
225 |
GridBagConstraints gbc_downButton = new GridBagConstraints(); |
|
226 |
gbc_downButton.insets = new Insets(0, 0, 5, 0); |
|
227 |
gbc_downButton.gridx = 5; |
|
228 |
gbc_downButton.gridy = 5; |
|
229 |
panel_chartType.add(downButton, gbc_downButton); |
|
230 |
|
|
231 |
|
|
232 |
addButton = new JButton(""); |
|
233 |
addButton.setIcon(new ImageIcon(ChartPropertiesPanel.class.getResource("/icons/add.png"))); |
|
234 |
GridBagConstraints gbc_addButton = new GridBagConstraints(); |
|
235 |
gbc_addButton.insets = new Insets(0, 0, 5, 0); |
|
236 |
gbc_addButton.gridx = 5; |
|
237 |
gbc_addButton.gridy = 7; |
|
238 |
panel_chartType.add(addButton, gbc_addButton); |
|
239 |
|
|
240 |
editButton = new JButton(""); |
|
241 |
editButton.setIcon(new ImageIcon(ChartPropertiesPanel.class.getResource("/icons/edit.png"))); |
|
242 |
GridBagConstraints gbc_editButton = new GridBagConstraints(); |
|
243 |
gbc_editButton.insets = new Insets(0, 0, 5, 0); |
|
244 |
gbc_editButton.gridx = 5; |
|
245 |
gbc_editButton.gridy = 8; |
|
246 |
panel_chartType.add(editButton, gbc_editButton); |
|
247 |
|
|
248 |
deleteButton = new JButton(""); |
|
249 |
deleteButton.setIcon(new ImageIcon(ChartPropertiesPanel.class.getResource("/icons/delete.png"))); |
|
250 |
GridBagConstraints gbc_deleteButton = new GridBagConstraints(); |
|
251 |
gbc_deleteButton.anchor = GridBagConstraints.NORTH; |
|
252 |
gbc_deleteButton.gridx = 5; |
|
253 |
gbc_deleteButton.gridy = 9; |
|
254 |
panel_chartType.add(deleteButton, gbc_deleteButton); |
|
255 |
} |
|
256 |
return panel_chartType; |
|
257 |
|
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* |
|
262 |
* Inicializa los elementos para el manejo de los Chart |
|
263 |
*/ |
|
264 |
private void initialize() { |
|
265 |
String[] colName = {"Visible", "Variable (units)", "Chart Type", "Render type" }; |
|
266 |
|
|
267 |
tableModel = (DefaultTableModel) table.getModel(); |
|
268 |
tableModel.setColumnIdentifiers(colName); |
|
269 |
|
|
270 |
fillTableData(); |
|
271 |
table.getColumnModel().getColumn(0).setPreferredWidth(45); |
|
272 |
table.getColumnModel().getColumn(2).setPreferredWidth(150); |
|
273 |
table.getColumnModel().getColumn(3).setPreferredWidth(150); |
|
274 |
|
|
275 |
|
|
276 |
table.getColumnModel().getColumn(0).setCellRenderer(new CheckBoxRenderer()); |
|
277 |
table.getColumnModel().getColumn(2).setCellRenderer(new ChartCellRenderer(this)); |
|
278 |
|
|
279 |
|
|
280 |
} |
|
281 |
|
|
282 |
public void fillTableData(){ |
|
283 |
List<ChartProperties> chartProperties = getDocument().getChartProperties(); |
|
284 |
removeTable(); |
|
285 |
for (int i = 0; i < chartProperties.size(); i++) { |
|
286 |
Object[] data = new Object[4]; |
|
287 |
data[0] = true; |
|
288 |
data[1] = chartProperties.get(i).getChartTitle(); |
|
289 |
data[2] = getChartCellType(chartProperties.get(i).getChartType()); |
|
290 |
data[3] = chartProperties.get(i).getChartRenderer(); |
|
291 |
|
|
292 |
((DefaultTableModel) tableModel).addRow(data); |
|
293 |
} |
|
294 |
// tableModel.fireTableDataChanged(); |
|
295 |
table.revalidate(); |
|
296 |
table.repaint(); |
|
297 |
} |
|
298 |
|
|
299 |
private ChartEntry getChartCellType(String type){ |
|
300 |
for(int i=0;i<listModel.getSize(); i++){ |
|
301 |
ChartEntry entry = (ChartEntry)listModel.get(i); |
Also available in: Unified diff