Revision 379
org.gvsig.chart/tags/org.gvsig.chart-1.0.64/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.64/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.64/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.64/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.64/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.64/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.64/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.64/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.64/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.64/org.gvsig.chart.main/src/main/java/org/gvsig/chart/main/panels/ChartUsedFieldPropertiesPanel.java | ||
---|---|---|
1 |
package org.gvsig.chart.main.panels; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.GridBagConstraints; |
|
6 |
import java.awt.GridBagLayout; |
|
7 |
import java.awt.Insets; |
|
8 |
import java.awt.event.ActionEvent; |
|
9 |
import java.awt.event.ActionListener; |
|
10 |
import java.util.HashMap; |
|
11 |
import java.util.List; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import javax.swing.DefaultListModel; |
|
15 |
import javax.swing.JButton; |
|
16 |
import javax.swing.JLabel; |
|
17 |
import javax.swing.JList; |
|
18 |
import javax.swing.JPanel; |
|
19 |
import javax.swing.JTextField; |
|
20 |
import javax.swing.JTextPane; |
|
21 |
import javax.swing.ListSelectionModel; |
|
22 |
import javax.swing.event.ListSelectionEvent; |
|
23 |
import javax.swing.event.ListSelectionListener; |
|
24 |
|
|
25 |
import org.gvsig.andami.PluginServices; |
|
26 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
27 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
28 |
import org.gvsig.chart.ChartLocator; |
|
29 |
import org.gvsig.chart.ChartProperties; |
|
30 |
import org.gvsig.chart.ChartService; |
|
31 |
import org.gvsig.chart.lib.spi.ChartServiceManager; |
|
32 |
import org.gvsig.chart.main.DefaultDataPropertiesPanel; |
|
33 |
import org.gvsig.chart.main.MainContext; |
|
34 |
import org.gvsig.chart.main.utils.ChartCellRenderer; |
|
35 |
import org.gvsig.chart.main.utils.ChartEntry; |
|
36 |
import org.gvsig.chart.main.utils.ChartJDialog; |
|
37 |
import org.gvsig.chart.main.utils.ChartJPanel; |
|
38 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
39 |
import org.gvsig.chart.swing.spi.ChartPanel; |
|
40 |
import org.gvsig.chart.swing.spi.ChartSwingServiceManager; |
|
41 |
import org.gvsig.tools.service.ServiceException; |
|
42 |
|
|
43 |
public class ChartUsedFieldPropertiesPanel extends ChartJPanel implements IWindow, ActionListener, ListSelectionListener{ |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
*/ |
|
48 |
private static final long serialVersionUID = -301224990996378683L; |
|
49 |
|
|
50 |
private static final int SUBPANEL_WIDTH = 400; |
|
51 |
private static final int SUBPANEL_HEIGHT = 210; |
|
52 |
|
|
53 |
private JButton accept; |
|
54 |
private JButton cancel; |
|
55 |
|
|
56 |
private String selectedChartType = null; |
|
57 |
private ChartPanel currentSubtypePanel = null; |
|
58 |
|
|
59 |
private JPanel panel_chartType = null; |
|
60 |
private JPanel panelSubtype = null; |
|
61 |
private Map<String, JPanel> cardPanel = new HashMap<String, JPanel>(); |
|
62 |
private JList list = null; |
|
63 |
private DefaultListModel listModel; |
|
64 |
private JLabel chartTypesLabel; |
|
65 |
private JLabel chartOptionsLabel; |
|
66 |
|
|
67 |
private ChartServiceManager serviceManager; |
|
68 |
|
|
69 |
private ChartSwingServiceManager swingManager; |
|
70 |
private JLabel lblName; |
|
71 |
private JTextField nameTextField; |
|
72 |
private JTextField unitsTextField; |
|
73 |
private JLabel lblUnits; |
|
74 |
private JLabel lblDescription; |
|
75 |
private JTextPane descriptionTextField; |
|
76 |
|
|
77 |
private MainContext mainContext; |
|
78 |
|
|
79 |
private ChartJDialog chartJDialog; |
|
80 |
|
|
81 |
private ChartProperties chartProperties; |
|
82 |
private ChartProperties previousChartProperties; |
|
83 |
|
|
84 |
/** |
|
85 |
* @wbp.parser.constructor |
|
86 |
*/ |
|
87 |
public ChartUsedFieldPropertiesPanel(MainContext mainContext) { |
|
88 |
serviceManager = ChartLocator.getServiceManager(); |
|
89 |
swingManager = ChartSwingLocator.getSwingManager(); |
|
90 |
|
|
91 |
this.mainContext = mainContext; |
|
92 |
// this.usedField = usedField; |
|
93 |
// this.chartUsedFieldPanel = chartUsedFieldPanel; |
|
94 |
|
|
95 |
createMainPanel(); |
|
96 |
createButtonPanelEvents(); |
|
97 |
} |
|
98 |
|
|
99 |
public ChartUsedFieldPropertiesPanel(MainContext mainContext, ChartProperties props) { |
|
100 |
this(mainContext); |
|
101 |
chartProperties = props; |
|
102 |
previousChartProperties = props; |
|
103 |
this.completeForm(); |
|
104 |
} |
|
105 |
|
|
106 |
public void completeForm(){ |
|
107 |
|
|
108 |
// Rellenamos todos los campos |
|
109 |
nameTextField.setText(chartProperties.getChartName()); |
|
110 |
|
|
111 |
// Seleccionamos el tipo de gr?fica |
|
112 |
for(int i=0;i<listModel.getSize();i++){ |
|
113 |
ChartEntry entry = (ChartEntry) listModel.get(i); |
|
114 |
if(entry.getChartType()==chartProperties.getChartType()){ |
|
115 |
list.setSelectedIndex(i); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
// Rellenamos el panel caracter?stico de cada tipo de gr?fica |
|
120 |
ChartPanel panel = (ChartPanel) cardPanel.get((String)chartProperties.getChartType()); |
|
121 |
panel.setChartProperties(chartProperties); |
|
122 |
|
|
123 |
// TODO ??Refrescar el panel?? |
|
124 |
} |
|
125 |
|
|
126 |
public ChartProperties getPreviousChartProperties(){ |
|
127 |
return previousChartProperties; |
|
128 |
} |
|
129 |
|
|
130 |
private void createMainPanel(){ |
|
131 |
GridBagLayout gridBagLayout = new GridBagLayout(); |
|
132 |
gridBagLayout.columnWidths = new int[]{303, 0, 0, 88, 0}; |
|
133 |
|
|
134 |
setLayout(gridBagLayout); |
|
135 |
|
|
136 |
GridBagConstraints gbc_panel_chartType = new GridBagConstraints(); |
|
137 |
gbc_panel_chartType.gridheight = 2; |
|
138 |
gbc_panel_chartType.insets = new Insets(0, 0, 5, 0); |
|
139 |
gbc_panel_chartType.gridy = 0; |
|
140 |
gbc_panel_chartType.gridwidth = 5; |
|
141 |
gbc_panel_chartType.gridx = 0; |
|
142 |
add(getTypePanel(), gbc_panel_chartType); |
|
143 |
|
|
144 |
accept = new JButton("Next >"); |
|
145 |
GridBagConstraints gbc_accept = new GridBagConstraints(); |
|
146 |
gbc_accept.insets = new Insets(0, 0, 0, 5); |
|
147 |
gbc_accept.gridx = 3; |
|
148 |
gbc_accept.gridy = 2; |
|
149 |
add(accept, gbc_accept); |
|
150 |
|
|
151 |
cancel = new JButton("Cancel"); |
|
152 |
GridBagConstraints gbc_cancel = new GridBagConstraints(); |
|
153 |
gbc_cancel.gridx = 4; |
|
154 |
gbc_cancel.gridy = 2; |
|
155 |
add(cancel, gbc_cancel); |
|
156 |
|
|
157 |
} |
|
158 |
|
|
159 |
private JPanel getTypePanel(){ |
|
160 |
if (panel_chartType==null){ |
|
161 |
panel_chartType = new JPanel(); |
|
162 |
|
|
163 |
GridBagLayout gbl_panel_chartType = new GridBagLayout(); |
|
164 |
gbl_panel_chartType.columnWidths = new int[]{150, 0, 210, 0, 0, 203, 0}; |
|
165 |
gbl_panel_chartType.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 208, 0, 0}; |
|
166 |
gbl_panel_chartType.columnWeights = new double[]{1.0, 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; |
|
167 |
gbl_panel_chartType.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; |
|
168 |
panel_chartType.setLayout(gbl_panel_chartType); |
|
169 |
|
|
170 |
lblName = new JLabel("Name"); |
|
171 |
GridBagConstraints gbc_lblName = new GridBagConstraints(); |
|
172 |
gbc_lblName.anchor = GridBagConstraints.WEST; |
|
173 |
gbc_lblName.insets = new Insets(0, 0, 5, 5); |
|
174 |
gbc_lblName.gridx = 0; |
|
175 |
gbc_lblName.gridy = 0; |
|
176 |
panel_chartType.add(lblName, gbc_lblName); |
|
177 |
|
|
178 |
nameTextField = new JTextField(); |
|
179 |
GridBagConstraints gbc_nameTextField = new GridBagConstraints(); |
|
180 |
gbc_nameTextField.gridwidth = 4; |
|
181 |
gbc_nameTextField.insets = new Insets(0, 0, 5, 0); |
|
182 |
gbc_nameTextField.fill = GridBagConstraints.HORIZONTAL; |
|
183 |
gbc_nameTextField.gridx = 2; |
|
184 |
gbc_nameTextField.gridy = 0; |
|
185 |
panel_chartType.add(nameTextField, gbc_nameTextField); |
|
186 |
nameTextField.setColumns(10); |
|
187 |
|
|
188 |
lblUnits = new JLabel("Units"); |
|
189 |
GridBagConstraints gbc_lblUnits = new GridBagConstraints(); |
|
190 |
gbc_lblUnits.anchor = GridBagConstraints.WEST; |
|
191 |
gbc_lblUnits.insets = new Insets(0, 0, 5, 5); |
|
192 |
gbc_lblUnits.gridx = 0; |
|
193 |
gbc_lblUnits.gridy = 1; |
|
194 |
panel_chartType.add(lblUnits, gbc_lblUnits); |
|
195 |
|
|
196 |
unitsTextField = new JTextField(); |
|
197 |
GridBagConstraints gbc_unitsTextField = new GridBagConstraints(); |
|
198 |
gbc_unitsTextField.gridwidth = 4; |
|
199 |
gbc_unitsTextField.insets = new Insets(0, 0, 5, 0); |
|
200 |
gbc_unitsTextField.fill = GridBagConstraints.HORIZONTAL; |
|
201 |
gbc_unitsTextField.gridx = 2; |
|
202 |
gbc_unitsTextField.gridy = 1; |
|
203 |
panel_chartType.add(unitsTextField, gbc_unitsTextField); |
|
204 |
unitsTextField.setColumns(10); |
|
205 |
|
|
206 |
lblDescription = new JLabel("Description"); |
|
207 |
GridBagConstraints gbc_lblDescription = new GridBagConstraints(); |
|
208 |
gbc_lblDescription.anchor = GridBagConstraints.WEST; |
|
209 |
gbc_lblDescription.insets = new Insets(0, 0, 5, 5); |
|
210 |
gbc_lblDescription.gridx = 0; |
|
211 |
gbc_lblDescription.gridy = 2; |
|
212 |
panel_chartType.add(lblDescription, gbc_lblDescription); |
|
213 |
|
|
214 |
descriptionTextField = new JTextPane(); |
|
215 |
GridBagConstraints gbc_descriptionTextField = new GridBagConstraints(); |
|
216 |
gbc_descriptionTextField.gridheight = 3; |
|
217 |
gbc_descriptionTextField.gridwidth = 4; |
|
218 |
gbc_descriptionTextField.insets = new Insets(0, 0, 5, 0); |
|
219 |
gbc_descriptionTextField.fill = GridBagConstraints.BOTH; |
|
220 |
gbc_descriptionTextField.gridx = 2; |
|
221 |
gbc_descriptionTextField.gridy = 2; |
|
222 |
panel_chartType.add(descriptionTextField, gbc_descriptionTextField); |
|
223 |
|
|
224 |
chartTypesLabel = new JLabel("Chart renderer types"); |
|
225 |
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints(); |
|
226 |
gbc_lblNewLabel_2.anchor = GridBagConstraints.WEST; |
|
227 |
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5); |
|
228 |
gbc_lblNewLabel_2.gridx = 0; |
|
229 |
gbc_lblNewLabel_2.gridy = 5; |
|
230 |
panel_chartType.add(chartTypesLabel, gbc_lblNewLabel_2); |
|
231 |
|
|
232 |
chartOptionsLabel= new JLabel("Drawing options"); |
|
233 |
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints(); |
|
234 |
gbc_lblNewLabel_3.anchor = GridBagConstraints.WEST; |
|
235 |
gbc_lblNewLabel_3.gridwidth = 4; |
|
236 |
gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 0); |
|
237 |
gbc_lblNewLabel_3.gridx = 2; |
|
238 |
gbc_lblNewLabel_3.gridy = 5; |
|
239 |
panel_chartType.add(chartOptionsLabel, gbc_lblNewLabel_3); |
|
240 |
|
|
241 |
list = new JList(); |
|
242 |
GridBagConstraints gbc_list = new GridBagConstraints(); |
|
243 |
gbc_list.insets = new Insets(0, 0, 5, 5); |
|
244 |
gbc_list.fill = GridBagConstraints.BOTH; |
|
245 |
gbc_list.gridx = 0; |
|
246 |
gbc_list.gridy = 6; |
|
247 |
panel_chartType.add(list, gbc_list); |
|
248 |
|
|
249 |
panelSubtype = new JPanel(); |
|
250 |
GridBagConstraints gbc_panelSubtype = new GridBagConstraints(); |
|
251 |
gbc_panelSubtype.insets = new Insets(0, 0, 5, 0); |
|
252 |
gbc_panelSubtype.gridwidth = 4; |
|
253 |
gbc_panelSubtype.fill = GridBagConstraints.BOTH; |
|
254 |
gbc_panelSubtype.gridx = 2; |
|
255 |
gbc_panelSubtype.gridy = 6; |
|
256 |
panelSubtype.setAutoscrolls(true); |
|
257 |
Dimension dimension = new Dimension(SUBPANEL_WIDTH, SUBPANEL_HEIGHT); |
|
258 |
panelSubtype.setMaximumSize(dimension); |
|
259 |
panelSubtype.setMinimumSize(dimension); |
|
260 |
panel_chartType.add(panelSubtype, gbc_panelSubtype); |
|
261 |
} |
|
262 |
return panel_chartType; |
|
263 |
|
|
264 |
} |
|
265 |
|
|
266 |
public WindowInfo getWindowInfo() { |
|
267 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
|
268 |
m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_variable")); |
|
269 |
m_viewinfo.setWidth(575); |
|
270 |
m_viewinfo.setHeight(500); |
|
271 |
return m_viewinfo; |
|
272 |
} |
|
273 |
|
|
274 |
public Object getWindowProfile() { |
|
275 |
return WindowInfo.PROPERTIES_PROFILE; |
|
276 |
} |
|
277 |
|
|
278 |
// public Object getWindowModel() { |
|
279 |
// return chartDocument; |
|
280 |
// } |
|
281 |
|
|
282 |
public String getSelectedChartType(){ |
|
283 |
return selectedChartType; |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* Crea el panel de la ChartPropertiesPanel usando un dise?o de Abeille |
|
288 |
*/ |
|
289 |
private void createButtonPanelEvents(){ |
|
290 |
cardPanel.put("empty", new JPanel()); |
|
291 |
|
|
292 |
accept.addActionListener(new ActionListener() { |
|
293 |
public void actionPerformed(ActionEvent e) { |
|
294 |
acceptForm(); |
|
295 |
} |
|
296 |
}); |
|
297 |
cancel.addActionListener(new ActionListener() { |
|
298 |
public void actionPerformed(ActionEvent arg0) { |
|
299 |
cancelForm(); |
|
300 |
} |
|
301 |
}); |
Also available in: Unified diff