Revision 92
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/buildNumber.properties | ||
---|---|---|
1 |
#Fri Jul 03 20:34:35 CEST 2015 |
|
2 |
buildNumber=23 |
|
0 | 3 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
<dependencySets> |
|
26 |
<dependencySet> |
|
27 |
<useProjectArtifact>false</useProjectArtifact> |
|
28 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
29 |
<outputDirectory>lib</outputDirectory> |
|
30 |
<includes> |
|
31 |
<include>org.gvsig:org.gvsig.chart.lib.api</include> |
|
32 |
<include>org.gvsig:org.gvsig.chart.swing.api</include> |
|
33 |
<include>org.gvsig:org.gvsig.chart.lib.base</include> |
|
34 |
<include>org.gvsig:org.gvsig.chart.swing.base</include> |
|
35 |
<include>org.gvsig:org.gvsig.chart.lib.impl</include> |
|
36 |
<include>org.gvsig:org.gvsig.chart.swing.impl</include> |
|
37 |
</includes> |
|
38 |
</dependencySet> |
|
39 |
</dependencySets> |
|
40 |
|
|
41 |
</assembly> |
|
0 | 42 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/chart/mainplugin/ChartExtension.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.app.chart.mainplugin; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.awt.Graphics2D; |
|
26 |
import java.awt.Rectangle; |
|
27 |
import java.awt.image.BufferedImage; |
|
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
|
|
31 |
import javax.imageio.ImageIO; |
|
32 |
import javax.swing.ImageIcon; |
|
33 |
import javax.swing.JComponent; |
|
34 |
import javax.swing.JDialog; |
|
35 |
import javax.swing.JFileChooser; |
|
36 |
import javax.swing.JOptionPane; |
|
37 |
|
|
38 |
import org.gvsig.andami.IconThemeHelper; |
|
39 |
import org.gvsig.andami.PluginServices; |
|
40 |
import org.gvsig.andami.plugins.ExclusiveUIExtension; |
|
41 |
import org.gvsig.andami.plugins.Extension; |
|
42 |
import org.gvsig.andami.plugins.IExtension; |
|
43 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
44 |
import org.gvsig.app.project.documents.chart.ChartDocument; |
|
45 |
import org.gvsig.app.project.documents.chart.ChartDocumentManager; |
|
46 |
import org.gvsig.app.project.documents.chart.gui.DefaultChartDocumentPanel; |
|
47 |
import org.gvsig.app.project.documents.chart.gui.DefaultEditorGroupedChartIWindow; |
|
48 |
import org.gvsig.app.project.documents.chart.gui.EditorChartServiceJDialog; |
|
49 |
import org.gvsig.chart.ChartLocator; |
|
50 |
import org.gvsig.chart.ChartService; |
|
51 |
import org.gvsig.chart.lib.spi.ChartServiceManager; |
|
52 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
53 |
import org.gvsig.chart.swing.ChartSwingManager; |
|
54 |
import org.gvsig.chart.swing.editors.EditorChartServicePanel; |
|
55 |
import org.gvsig.chart.swing.spi.ChartSwingServiceManager; |
|
56 |
import org.gvsig.tools.library.LibraryException; |
|
57 |
import org.gvsig.tools.util.Caller; |
|
58 |
import org.gvsig.tools.util.impl.DefaultCaller; |
|
59 |
import org.jfree.ui.ExtensionFileFilter; |
|
60 |
import org.slf4j.Logger; |
|
61 |
import org.slf4j.LoggerFactory; |
|
62 |
|
|
63 |
/** |
|
64 |
* Andami extension to show Chart in the application. |
|
65 |
* |
|
66 |
* @author gvSIG Team |
|
67 |
* @version $Id$ |
|
68 |
*/ |
|
69 |
public class ChartExtension extends Extension implements ExclusiveUIExtension { |
|
70 |
static ImageIcon LOGO; |
|
71 |
|
|
72 |
private static final Logger logger = LoggerFactory |
|
73 |
.getLogger(ChartExtension.class); |
|
74 |
|
|
75 |
private static final String MY_VIEW_NAME = "Chart plugin"; |
|
76 |
|
|
77 |
private static final String TOOL_NAME = "Chart.infotool"; |
|
78 |
private static final String ACTION_CREATEPLOT = "chart-create-plot"; |
|
79 |
private static final String ACTION_EDITPLOT = "chart-edit-plot"; |
|
80 |
private static final String ACTION_EXPORTTOPDF = "chart-export-pdf"; |
|
81 |
private static final String ACTION_EXPORTTOPNG = "chart-export-png"; |
|
82 |
|
|
83 |
private ChartServiceManager manager; |
|
84 |
private ChartSwingServiceManager swingServiceManager; |
|
85 |
private ChartSwingManager swingManager; |
|
86 |
|
|
87 |
public void initialize() { |
|
88 |
registerIcons(); |
|
89 |
} |
|
90 |
|
|
91 |
public void postInitialize() { |
|
92 |
manager = ChartLocator.getServiceManager(); |
|
93 |
swingServiceManager = ChartSwingLocator.getSwingManager(); |
|
94 |
swingManager = swingServiceManager.getChartSwingManager(); |
|
95 |
|
|
96 |
// initializeDocumentActionsExtensionPoint(); |
|
97 |
try { |
|
98 |
registerIcons(); |
|
99 |
} |
|
100 |
catch (Exception e) { |
|
101 |
e.printStackTrace(); |
|
102 |
} |
|
103 |
|
|
104 |
ChartDocumentManager.register(); |
|
105 |
// registerContextMenuOptions(); |
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
Caller caller = new DefaultCaller(); |
|
110 |
/* |
|
111 |
* Add registry of persistent styles |
|
112 |
*/ |
|
113 |
caller.add( new ChartDocument.RegisterPersistence() ); |
|
114 |
|
|
115 |
/* |
|
116 |
* Do register of all |
|
117 |
*/ |
|
118 |
if( !caller.call() ) { |
|
119 |
throw new LibraryException(ChartExtension.class, caller.getExceptions()); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
/** |
|
125 |
* Execute the actions associated to this extension. |
|
126 |
*/ |
|
127 |
public void execute(String actionCommand) { |
|
128 |
if (ACTION_EDITPLOT.equalsIgnoreCase(actionCommand)) { |
|
129 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
|
130 |
if ((window instanceof DefaultChartDocumentPanel)) { |
|
131 |
// DefaultChartDocumentPanel chartPanel = (DefaultChartDocumentPanel) window; |
|
132 |
// EditorGroupedChartPanel editor = ChartSwingLocator.getSwingManager().getChartSwingManager().createEditorChartPanel( |
|
133 |
// (GroupedCharts)chartPanel.getChartPanel().getOverlayChart()); |
|
134 |
DefaultChartDocumentPanel chartPanel = (DefaultChartDocumentPanel) window; |
|
135 |
ChartDocument document = (ChartDocument)chartPanel.getDocument(); |
|
136 |
DefaultEditorGroupedChartIWindow windowPanel = |
|
137 |
new DefaultEditorGroupedChartIWindow(document); |
|
138 |
JDialog dlg = new JDialog(); |
|
139 |
// dlg.getContentPane().add(editor.getComponent()); |
|
140 |
windowPanel.setParentDialog(dlg); |
|
141 |
dlg.getContentPane().add(windowPanel); |
|
142 |
// dlg.pack(); |
|
143 |
dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
|
144 |
|
|
145 |
dlg.setPreferredSize(new Dimension(700, 600)); |
|
146 |
dlg.setModal(true); |
|
147 |
dlg.pack(); |
|
148 |
dlg.setSize(840, 650); |
|
149 |
dlg.setVisible(true); |
|
150 |
|
|
151 |
return; |
|
152 |
} |
|
153 |
} |
|
154 |
if (ACTION_CREATEPLOT.equalsIgnoreCase(actionCommand)) { |
|
155 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
|
156 |
if ((window instanceof DefaultChartDocumentPanel)) { |
|
157 |
DefaultChartDocumentPanel chartPanel = (DefaultChartDocumentPanel) window; |
|
158 |
ChartDocument document = (ChartDocument)chartPanel.getDocument(); |
|
159 |
DefaultEditorGroupedChartIWindow windowPanel = |
|
160 |
new DefaultEditorGroupedChartIWindow(document); |
|
161 |
|
|
162 |
EditorChartServicePanel editorChartServicePanel = swingManager.createNewChartPanel(windowPanel.getChartDocument().getChartService()); |
|
163 |
editorChartServicePanel.addObserver(windowPanel.getEditorPanel()); |
|
164 |
windowPanel.setEditorChartServicePanel( |
|
165 |
editorChartServicePanel |
|
166 |
); |
|
167 |
|
|
168 |
ChartService service = EditorChartServiceJDialog.showDialog( |
|
169 |
this.swingManager.getTranslation("Add_new_variable"), |
|
170 |
windowPanel.getEditorChartServicePanel()); |
|
171 |
|
|
172 |
if(service != null){ |
|
173 |
document.getChartService().addChartService(service); |
|
174 |
} |
|
175 |
|
|
176 |
windowPanel.setEditorChartServicePanel(null); |
|
177 |
// JDialog dlg = new JDialog(); |
|
178 |
// dlg.setTitle("Add variable to current Chart"); |
|
179 |
//// dlg.setContentPane(new ChartUsedFieldPanel(document)); |
|
180 |
// dlg.pack(); |
|
181 |
// dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
|
182 |
// |
|
183 |
// dlg.setVisible(true); |
|
184 |
|
|
185 |
return; |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
if (ACTION_EXPORTTOPDF.equalsIgnoreCase(actionCommand)) { |
|
190 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
|
191 |
if ((window instanceof DefaultChartDocumentPanel)) { |
|
192 |
DefaultChartDocumentPanel chartPanel = (DefaultChartDocumentPanel) window; |
|
193 |
ChartDocument document = (ChartDocument)chartPanel.getDocument(); |
|
194 |
JFileChooser chooser = new JFileChooser(); |
|
195 |
|
|
196 |
ExtensionFileFilter filter=new ExtensionFileFilter(this.swingManager.getTranslation("PDF_Image_Files"),".pdf"); |
|
197 |
chooser.addChoosableFileFilter(filter); |
|
198 |
|
|
199 |
chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); |
|
200 |
chooser.setDialogTitle(this.swingManager.getTranslation("SavePDF")); |
|
201 |
|
|
202 |
chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES ); |
|
203 |
// chooser.setAcceptAllFileFilterUsed(true); |
|
204 |
|
|
205 |
if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { |
|
206 |
|
|
207 |
// System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); |
|
208 |
// System.out.println("getSelectedFile() : " + chooser.getSelectedFile().getAbsolutePath()); |
|
209 |
// |
|
210 |
String filename = chooser.getSelectedFile().getAbsolutePath(); |
|
211 |
|
|
212 |
if (!filename.endsWith(".pdf")) { |
|
213 |
filename=filename + ".pdf"; |
|
214 |
} |
|
215 |
|
|
216 |
document.getChartService().exportAsPDF( |
|
217 |
filename, |
|
218 |
chartPanel.getWidth(), |
|
219 |
chartPanel.getHeight() |
|
220 |
); |
|
221 |
|
|
222 |
JOptionPane.showMessageDialog(null, this.swingManager.getTranslation("Document_exported")); |
|
223 |
} else { |
|
224 |
System.out.println("No Selection "); |
|
225 |
} |
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
return; |
|
230 |
} |
|
231 |
} |
|
232 |
|
|
233 |
if (ACTION_EXPORTTOPNG.equalsIgnoreCase(actionCommand)) { |
|
234 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
|
235 |
if ((window instanceof DefaultChartDocumentPanel)) { |
|
236 |
DefaultChartDocumentPanel chartPanel = (DefaultChartDocumentPanel) window; |
|
237 |
JFileChooser chooser = new JFileChooser(); |
|
238 |
|
|
239 |
ExtensionFileFilter filter=new ExtensionFileFilter(this.swingManager.getTranslation("PNG_Image_Files"),".png"); |
|
240 |
chooser.addChoosableFileFilter(filter); |
|
241 |
|
|
242 |
chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); |
|
243 |
chooser.setDialogTitle(this.swingManager.getTranslation("SavePNG")); |
|
244 |
|
|
245 |
chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES ); |
|
246 |
// chooser.setAcceptAllFileFilterUsed(true); |
|
247 |
|
|
248 |
if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { |
|
249 |
|
|
250 |
// System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); |
|
251 |
// System.out.println("getSelectedFile() : " + chooser.getSelectedFile().getAbsolutePath()); |
|
252 |
// |
|
253 |
String filename = chooser.getSelectedFile().getAbsolutePath(); |
|
254 |
|
|
255 |
if (!filename.endsWith(".png")) { |
|
256 |
filename=filename + ".png"; |
|
257 |
} |
|
258 |
|
|
259 |
BufferedImage bi = this.createImage(chartPanel, chartPanel.getBounds()); |
|
260 |
this.writeImage(bi, filename); |
|
261 |
|
|
262 |
JOptionPane.showMessageDialog(null, this.swingManager.getTranslation("Document_exported")); |
|
263 |
|
|
264 |
} else { |
|
265 |
System.out.println("No Selection "); |
|
266 |
} |
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
return; |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
public void writeImage(BufferedImage image, String fileName){ |
|
276 |
if (fileName == null) return; |
|
277 |
|
|
278 |
int offset = fileName.lastIndexOf( "." ); |
|
279 |
if (offset == -1){ |
|
280 |
return; |
|
281 |
} |
|
282 |
|
|
283 |
String type = fileName.substring(offset + 1); |
|
284 |
try { |
|
285 |
ImageIO.write(image, type, new File( fileName )); |
|
286 |
} catch (IOException e) { |
|
287 |
// TODO Auto-generated catch block |
|
288 |
e.printStackTrace(); |
|
289 |
} |
|
290 |
} |
|
291 |
|
|
292 |
private BufferedImage createImage(JComponent component, Rectangle region) |
|
293 |
{ |
|
294 |
// Make sure the component has a size and has been layed out. |
|
295 |
// (necessary check for components not added to a realized frame) |
|
296 |
|
|
297 |
if (! component.isDisplayable()) |
|
298 |
{ |
|
299 |
Dimension d = component.getSize(); |
|
300 |
|
|
301 |
if (d.width == 0 || d.height == 0) |
|
302 |
{ |
|
303 |
d = component.getPreferredSize(); |
|
304 |
component.setSize( d ); |
|
305 |
} |
|
306 |
|
|
307 |
// layoutComponent( component ); |
|
308 |
} |
|
309 |
|
|
310 |
BufferedImage image = new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB); |
|
311 |
Graphics2D g2d = image.createGraphics(); |
|
312 |
|
|
313 |
// Paint a background for non-opaque components, |
|
314 |
// otherwise the background will be black |
|
315 |
|
|
316 |
if (! component.isOpaque()) |
|
317 |
{ |
|
318 |
g2d.setColor( component.getBackground() ); |
|
319 |
g2d.fillRect(region.x, region.y, region.width, region.height); |
|
320 |
} |
|
321 |
|
|
322 |
g2d.translate(-region.x, -region.y); |
|
323 |
component.paint( g2d ); |
|
324 |
g2d.dispose(); |
|
325 |
return image; |
|
326 |
} |
|
327 |
|
|
328 |
|
|
329 |
/** |
|
330 |
* Check if tools of this extension are enabled. |
|
331 |
*/ |
|
332 |
public boolean isEnabled() { |
|
333 |
// |
|
334 |
// By default the tool is always enabled |
|
335 |
// |
|
336 |
return true; |
|
337 |
} |
|
338 |
|
|
339 |
/** |
|
340 |
* Check if tools of this extension are visible. |
|
341 |
*/ |
|
342 |
public boolean isVisible() { |
|
343 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
|
344 |
if (f == null) { |
|
345 |
return false; |
|
346 |
} |
|
347 |
|
|
348 |
if (f instanceof DefaultChartDocumentPanel) { |
|
349 |
return true; |
|
350 |
} |
|
351 |
return false; |
|
352 |
} |
|
353 |
|
|
354 |
/** |
|
355 |
* Check if an extension is enabled. |
|
356 |
*/ |
|
357 |
public boolean isEnabled(IExtension extension) { |
|
358 |
return extension.isEnabled(); |
|
359 |
} |
|
360 |
|
|
361 |
/** |
|
362 |
* Check if an extension is visible. |
|
363 |
*/ |
|
364 |
public boolean isVisible(IExtension extension) { |
|
365 |
return extension.isVisible(); |
|
366 |
} |
|
367 |
|
|
368 |
private void registerIcons() { |
|
369 |
IconThemeHelper.registerIcon("chart", "chart-create-plot", this.getClass()); |
|
370 |
IconThemeHelper.registerIcon("chart", "chart-edit-plot", this.getClass()); |
|
371 |
IconThemeHelper.registerIcon("chart", "chart-export-pdf", this.getClass()); |
|
372 |
IconThemeHelper.registerIcon("chart", "chart-export-png", this.getClass()); |
|
373 |
|
|
374 |
IconThemeHelper.registerIcon("document", "document-chart-unselect", ChartDocumentManager.class); |
|
375 |
IconThemeHelper.registerIcon("document", "document-chart-select", ChartDocumentManager.class); |
|
376 |
|
|
377 |
} |
|
378 |
|
|
379 |
} |
|
0 | 380 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/chart/mainplugin/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.landregistryviewer package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>LandRegistryViewer gvSIG extension</p> |
|
11 |
|
|
12 |
<p> |
|
13 |
Shows LandRegistryViewer into gvSIG. |
|
14 |
</p> |
|
15 |
|
|
16 |
</body> |
|
17 |
</html> |
|
0 | 18 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/ChartDocument.java | ||
---|---|---|
1 |
package org.gvsig.app.project.documents.chart; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
7 |
import org.gvsig.app.ApplicationLocator; |
|
8 |
import org.gvsig.app.ApplicationManager; |
|
9 |
import org.gvsig.app.project.Project; |
|
10 |
import org.gvsig.app.project.documents.AbstractDocument; |
|
11 |
import org.gvsig.app.project.documents.Document; |
|
12 |
import org.gvsig.app.project.documents.DocumentManager; |
|
13 |
import org.gvsig.app.project.documents.chart.events.ChartPropertiesChangeEvent; |
|
14 |
import org.gvsig.app.project.documents.chart.events.ChartPropertiesChangeListener; |
|
15 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
16 |
import org.gvsig.app.project.documents.table.TableManager; |
|
17 |
import org.gvsig.chart.ChartLocator; |
|
18 |
import org.gvsig.chart.ChartProperties; |
|
19 |
import org.gvsig.chart.ChartService; |
|
20 |
import org.gvsig.chart.GroupedCharts; |
|
21 |
import org.gvsig.chart.model.ChartDataSet; |
|
22 |
import org.gvsig.chart.model.variables.RequiredField; |
|
23 |
import org.gvsig.fmap.dal.exception.DataException; |
|
24 |
import org.gvsig.fmap.dal.feature.Feature; |
|
25 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
26 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
27 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
28 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
29 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
|
30 |
import org.gvsig.tools.ToolsLocator; |
|
31 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
32 |
import org.gvsig.tools.dynobject.DynStruct; |
|
33 |
import org.gvsig.tools.observer.Observable; |
|
34 |
import org.gvsig.tools.observer.Observer; |
|
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
36 |
import org.gvsig.tools.persistence.PersistentState; |
|
37 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
38 |
import org.gvsig.tools.util.Callable; |
|
39 |
|
|
40 |
public class ChartDocument extends AbstractDocument implements Document, |
|
41 |
Observer { |
|
42 |
/** |
|
43 |
* |
|
44 |
*/ |
|
45 |
private static final long serialVersionUID = 1421212389948622432L; |
|
46 |
|
|
47 |
private GroupedCharts overlayChart = null; |
|
48 |
private ChartDocumentManager documentManager; |
|
49 |
|
|
50 |
private FeatureStore store; |
|
51 |
private FeatureQuery query; |
|
52 |
|
|
53 |
// Create the listener list |
|
54 |
protected javax.swing.event.EventListenerList listenerList = new javax.swing.event.EventListenerList(); |
|
55 |
|
|
56 |
private boolean restored = false; |
|
57 |
|
|
58 |
/** |
|
59 |
* documentContext will have information about UsedFields and other |
|
60 |
* information that may be needed. UsedFields have information about the |
|
61 |
* table and fields from we will get information |
|
62 |
*/ |
|
63 |
|
|
64 |
// private ArrayList<String> categoryFields; |
|
65 |
|
|
66 |
// private String chartType; |
|
67 |
|
|
68 |
// public ArrayList<String> getCategoryFields() { |
|
69 |
// return categoryFields; |
|
70 |
// } |
|
71 |
// |
|
72 |
// public String getChartType() { |
|
73 |
// return chartType; |
|
74 |
// } |
|
75 |
|
|
76 |
// public ArrayList<String> getSeriesFields() { |
|
77 |
// return seriesFields; |
|
78 |
// } |
|
79 |
|
|
80 |
// private ArrayList<String> seriesFields; |
|
81 |
|
|
82 |
public ChartDocument() { |
|
83 |
this(new ChartDocumentManager()); |
|
84 |
this.restored = true; |
|
85 |
} |
|
86 |
|
|
87 |
public ChartDocument(DocumentManager factory) { |
|
88 |
super(factory); |
|
89 |
this.documentManager = (ChartDocumentManager) factory; |
|
90 |
this.store = null; |
|
91 |
this.query = null; |
|
92 |
|
|
93 |
this.overlayChart = ChartLocator.getServiceManager().getChartManager() |
|
94 |
.createGroupedCharts(); |
|
95 |
|
|
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
public ChartDocument(DocumentManager factory, FeatureStore store) { |
|
100 |
this(factory); |
|
101 |
setStore(store); |
|
102 |
} |
|
103 |
|
|
104 |
public FeatureStore getStore() { |
|
105 |
return store; |
|
106 |
} |
|
107 |
|
|
108 |
public void setStore(FeatureStore store) { |
|
109 |
if (this.store != null) { |
|
110 |
throw new UnsupportedOperationException( |
|
111 |
"can't set store. store already set."); |
|
112 |
} |
|
113 |
this.store = store; |
|
114 |
this.store.addObserver(this); |
|
115 |
this.query = null; // setQuery(store.createFeatureQuery()); |
|
116 |
} |
|
117 |
|
|
118 |
public void update(Observable observable, Object notification) { |
|
119 |
// if (this.store.equals(observable)) { |
|
120 |
if (observable instanceof GroupedCharts){ |
|
121 |
if(this.restored){ |
|
122 |
refreshGroupedChartsData(); |
|
123 |
this.overlayChart.deleteObserver(this); |
|
124 |
this.restored = false; |
|
125 |
} |
|
126 |
} |
|
127 |
if (observable instanceof FeatureSelection) { |
|
128 |
boolean bNeedUpdate = false; |
|
129 |
for (ChartService cs: overlayChart.getChartServices()) { |
|
130 |
if (cs.getChartProperties().getUseSelectedFeatures()) { |
|
131 |
bNeedUpdate = true; |
|
132 |
try { |
|
133 |
refreshChartServiceData(cs); |
|
134 |
} catch (DataException e) { |
|
135 |
// TODO Auto-generated catch block |
|
136 |
e.printStackTrace(); |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
if (bNeedUpdate) { |
|
141 |
|
|
142 |
fireChartPropertiesChangeEvent(null); |
|
143 |
} |
|
144 |
} |
|
145 |
if (notification instanceof FeatureStoreNotification) { |
|
146 |
FeatureStoreNotification event = (FeatureStoreNotification) notification; |
|
147 |
String type = event.getType(); |
|
148 |
// If the selection has changed, repaint the table to show the |
|
149 |
// new |
|
150 |
// selected rows |
|
151 |
if (FeatureStoreNotification.SELECTION_CHANGE.equals(type)) { |
|
152 |
// TODO: ENVIAR UN EVENTO QUE NO SEA NULL? |
|
153 |
fireChartPropertiesChangeEvent(null); |
|
154 |
} |
|
155 |
|
|
156 |
if (type.equals(FeatureStoreNotification.TRANSFORM_CHANGE) |
|
157 |
|| type.equals(FeatureStoreNotification.RESOURCE_CHANGED)) { |
|
158 |
this.query = null; |
|
159 |
} |
|
160 |
} |
|
161 |
// } |
|
162 |
|
|
163 |
} |
|
164 |
|
|
165 |
public void refreshGroupedChartsData() { |
|
166 |
List<ChartService> chartServices = this.overlayChart.getChartServices(); |
|
167 |
for (int i = 0; i < chartServices.size(); i++) { |
|
168 |
try { |
|
169 |
ChartService cs = chartServices.get(i); |
|
170 |
refreshChartServiceData(cs); |
|
171 |
} catch (DataException e) { |
|
172 |
// TODO Auto-generated catch block |
|
173 |
e.printStackTrace(); |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
public void loadFromState(PersistentState state) |
|
179 |
throws PersistenceException { |
|
180 |
super.loadFromState(state); |
|
181 |
// this.store = (FeatureStore) state.get("store"); |
|
182 |
// this.query = (FeatureQuery) state.get("query"); |
|
183 |
try { |
|
184 |
setChartService((GroupedCharts)state.get("GroupedCharts")); |
|
185 |
} catch (Exception e) { |
|
186 |
e.printStackTrace(); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
public void refreshChartServiceData(ChartService cs) throws DataException{ |
|
191 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
|
192 |
Project project = appManager.getCurrentProject(); |
|
193 |
|
|
194 |
ChartProperties cp = cs.getChartProperties(); |
|
195 |
|
|
196 |
FeatureSet fs; |
|
197 |
String tableName = cs.getChartProperties().getChartTableName(); |
|
198 |
if(tableName != null){ |
|
199 |
TableDocument table = (TableDocument) project.getDocument( |
|
200 |
tableName, TableManager.TYPENAME); |
|
201 |
|
|
202 |
if (table == null) { |
|
203 |
throw new RuntimeException("No se encuentra la tabla " |
|
204 |
+ tableName); |
|
205 |
} |
|
206 |
ChartDataSet dataSet = cs.getChartDataSet(); |
|
207 |
FeatureSelection fsel = table.getStore().getFeatureSelection(); |
|
208 |
fs = table.getStore().getFeatureSet(); |
|
209 |
|
|
210 |
DisposableIterator it = null; |
|
211 |
|
|
212 |
if (cp.getUseSelectedFeatures()) { |
|
213 |
it = fsel.fastIterator(); |
|
214 |
} |
|
215 |
else { |
|
216 |
it = fs.fastIterator(); |
|
217 |
} |
|
218 |
|
|
219 |
int[] fieldIDs = new int[cp.getRequiredFields().size()]; |
|
220 |
ArrayList[] data = new ArrayList[cp.getRequiredFields().size()]; |
|
221 |
|
|
222 |
// Buscamos los ID de los campos que vamos a usar. |
|
223 |
for (int j = 0; j < cp.getRequiredFields().size(); j++) { |
|
224 |
RequiredField rq = cp.getRequiredFields().get(j); |
|
225 |
|
|
226 |
if (rq.isOptional()) { |
|
227 |
if (fs.getDefaultFeatureType() |
|
228 |
.getAttributeDescriptor(rq.getValue()) == null) |
|
229 |
fieldIDs[j] = -1; |
|
230 |
else{ |
|
231 |
fieldIDs[j] = fs.getDefaultFeatureType() |
|
232 |
.getAttributeDescriptor(rq.getValue()).getIndex(); |
|
233 |
} |
|
234 |
} |
|
235 |
else { |
|
236 |
fieldIDs[j] = fs.getDefaultFeatureType() |
|
237 |
.getAttributeDescriptor(rq.getValue()).getIndex(); |
|
238 |
} |
|
239 |
|
|
240 |
ArrayList<Object> aux = new ArrayList<Object>(); |
|
241 |
data[j] = aux; |
|
242 |
} |
|
243 |
|
|
244 |
// if onlyRecordsSelected is set, we should iterate by selected features only |
|
245 |
while (it.hasNext()) { |
|
246 |
Feature f = (Feature) it.next(); |
|
247 |
for (int j = 0; j < fieldIDs.length; j++) { |
|
248 |
if (fieldIDs[j] != -1) |
|
249 |
data[j].add(f.get(fieldIDs[j])); |
|
250 |
} |
|
251 |
} |
|
252 |
for (int j = 0; j < fieldIDs.length; j++) { |
|
253 |
RequiredField rq = cp.getRequiredFields().get(j); |
|
254 |
if (fieldIDs[j] != -1) |
|
255 |
dataSet.addData(rq.getName(), |
|
256 |
data[j]); |
|
257 |
} |
|
258 |
it.dispose(); |
|
259 |
cs.setChartDataSet(dataSet); |
|
260 |
cs.update(); |
|
261 |
cs.loadSavedChartLegendItems(); |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
266 |
super.saveToState(state); |
|
267 |
state.set("GroupedCharts", this.getChartService()); |
|
268 |
} |
|
269 |
|
|
270 |
public static class RegisterPersistence implements Callable { |
|
271 |
|
|
272 |
public Object call() throws Exception { |
|
273 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
274 |
if (manager.getDefinition("ChartDocumentPersistence") == null) { |
|
275 |
DynStruct definition = manager |
|
276 |
.addDefinition( |
|
277 |
ChartDocument.class, |
|
278 |
"ChartDocumentPersistence", |
|
279 |
"ChartDocumentPersistence" |
|
280 |
+ " Persistence definition (FIXME check keys type)", |
|
281 |
null, null); |
|
282 |
|
|
283 |
// // Extend the Classified Vector Legend base definition |
|
284 |
definition.extend(manager.getDefinition("AbstractDocument")); |
|
285 |
|
|
286 |
// Values |
|
287 |
definition.addDynFieldObject("GroupedCharts").setClassOfValue(GroupedCharts.class); |
|
288 |
|
|
289 |
} |
|
290 |
return Boolean.TRUE; |
|
291 |
} |
|
292 |
|
|
293 |
} |
|
294 |
|
|
295 |
public IWindow getMainWindow() { |
|
296 |
return this.getFactory().getMainWindow(this); |
|
297 |
} |
|
298 |
|
|
299 |
public void setChartService(GroupedCharts chartService) { |
|
300 |
this.overlayChart = chartService; |
|
301 |
|
|
302 |
// repasamos las tablas y nos ponemos como escucha |
|
303 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
|
304 |
final Project project = appManager.getCurrentProject(); |
|
305 |
|
|
306 |
List<Document> tableDocuments = project |
|
307 |
.getDocuments(TableManager.TYPENAME); |
|
308 |
TableDocument[] pts = tableDocuments |
|
309 |
.toArray(new TableDocument[tableDocuments.size()]); |
|
310 |
|
|
311 |
for (TableDocument t : pts) { |
|
312 |
try { |
|
313 |
FeatureSelection featSelection = t.getFeatureStoreModel() |
|
314 |
.getFeatureStore().getFeatureSelection(); |
|
315 |
|
|
316 |
featSelection.deleteObserver(this); |
|
317 |
|
|
318 |
for (ChartService cs : chartService.getChartServices()) { |
|
319 |
if (cs.getChartProperties().getChartTableName() |
|
320 |
.equals(t.getName())) { |
|
321 |
featSelection.addObserver(this); |
|
322 |
} |
|
323 |
} |
|
324 |
} catch (DataException e) { |
|
325 |
e.printStackTrace(); |
|
326 |
} |
|
327 |
|
|
328 |
} |
|
329 |
|
|
330 |
fireChartPropertiesChangeEvent(null); |
|
331 |
|
|
332 |
if(this.restored){ |
|
333 |
this.overlayChart.addObserver(this); |
|
334 |
} |
|
335 |
} |
|
336 |
|
|
337 |
public GroupedCharts getChartService() { |
|
338 |
return overlayChart; |
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* Manejador de eventos cuando hay un cambio en ChartProperties |
|
343 |
*/ |
|
344 |
|
|
345 |
public void addChartPropertiesChangeEventListener( |
|
346 |
ChartPropertiesChangeListener listener) { |
|
347 |
listenerList.add(ChartPropertiesChangeListener.class, listener); |
|
348 |
} |
|
349 |
|
|
350 |
public void removeChartPropertiesChangeEventListener( |
|
351 |
ChartPropertiesChangeListener listener) { |
|
352 |
listenerList.remove(ChartPropertiesChangeListener.class, listener); |
|
353 |
} |
|
354 |
|
|
355 |
void fireChartPropertiesChangeEvent(ChartPropertiesChangeEvent evt) { |
|
356 |
Object[] listeners = listenerList.getListenerList(); |
|
357 |
// Each listener occupies two elements - the first is the listener class |
|
358 |
// and the second is the listener instance |
|
359 |
for (int i = 0; i < listeners.length; i += 2) { |
|
360 |
if (listeners[i] == ChartPropertiesChangeListener.class) { |
|
361 |
((ChartPropertiesChangeListener) listeners[i + 1]) |
|
362 |
.chartPropertiesChange(evt); |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
|
|
367 |
public ChartDocumentManager getDocumentManager() { |
|
368 |
return documentManager; |
|
369 |
} |
|
370 |
|
|
371 |
} |
|
0 | 372 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/events/ChartPropertiesChangeEvent.java | ||
---|---|---|
1 |
package org.gvsig.app.project.documents.chart.events; |
|
2 |
|
|
3 |
import java.util.EventObject; |
|
4 |
|
|
5 |
public class ChartPropertiesChangeEvent extends EventObject { |
|
6 |
/** |
|
7 |
* |
|
8 |
*/ |
|
9 |
private static final long serialVersionUID = -1974434668957358782L; |
|
10 |
|
|
11 |
public ChartPropertiesChangeEvent(Object source) { |
|
12 |
super(source); |
|
13 |
} |
|
14 |
} |
|
0 | 15 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/events/ChartPropertiesChangeListener.java | ||
---|---|---|
1 |
package org.gvsig.app.project.documents.chart.events; |
|
2 |
|
|
3 |
import java.util.EventListener; |
|
4 |
|
|
5 |
public interface ChartPropertiesChangeListener extends EventListener { |
|
6 |
public void chartPropertiesChange(ChartPropertiesChangeEvent evt); |
|
7 |
} |
|
0 | 8 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/gui/EditorChartServiceJDialog.java | ||
---|---|---|
1 |
package org.gvsig.app.project.documents.chart.gui; |
|
2 |
|
|
3 |
import org.gvsig.chart.ChartService; |
|
4 |
import org.gvsig.chart.swing.editors.EditorChartServicePanel; |
|
5 |
import org.gvsig.chart.swing.editors.panels.EditorChartPropertiesPanel; |
|
6 |
|
|
7 |
public class EditorChartServiceJDialog { |
|
8 |
|
|
9 |
public static ChartService showDialog(String title, EditorChartServicePanel editorPanel) { |
|
10 |
|
|
11 |
DefaultEditorChartServiceJDialog dlg = new DefaultEditorChartServiceJDialog(title, true, editorPanel); |
|
12 |
if(dlg.getMainPanel().isCancelled()) { |
|
13 |
dlg.setVisible(false); |
|
14 |
return null; |
|
15 |
} |
|
16 |
return dlg.getChartService(); |
|
17 |
} |
|
18 |
|
|
19 |
public static ChartService showDialog(String title, EditorChartPropertiesPanel editorPanel) { |
|
20 |
|
|
21 |
DefaultEditorChartPropertiesJDialog dlg = new DefaultEditorChartPropertiesJDialog(title, true, editorPanel); |
|
22 |
if(dlg.getMainPanel().isCancelled()) { |
|
23 |
dlg.setVisible(false); |
|
24 |
return null; |
|
25 |
} |
|
26 |
return dlg.getChartService(); |
|
27 |
} |
|
28 |
} |
|
0 | 29 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/gui/DefaultEditorChartPropertiesJDialog.java | ||
---|---|---|
1 |
package org.gvsig.app.project.documents.chart.gui; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
import java.awt.Font; |
|
5 |
import java.awt.event.ComponentEvent; |
|
6 |
import java.awt.event.ComponentListener; |
|
7 |
|
|
8 |
import javax.swing.JDialog; |
|
9 |
|
|
10 |
import org.gvsig.app.gui.utils.FontChooser; |
|
11 |
import org.gvsig.chart.ChartService; |
|
12 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
13 |
import org.gvsig.chart.swing.ChartSwingManager; |
|
14 |
import org.gvsig.chart.swing.editors.panels.EditorChartPropertiesPanel; |
|
15 |
import org.gvsig.chart.swing.editors.panels.format.chartarea.ChartServiceFormatLegendPanel; |
|
16 |
import org.gvsig.chart.swing.editors.panels.format.chartarea.ChartServiceFormatTitlePanel; |
|
17 |
import org.gvsig.tools.observer.Observable; |
|
18 |
import org.gvsig.tools.observer.Observer; |
|
19 |
|
|
20 |
/** |
|
21 |
* A dialog for choosing a font from the available system fonts. |
|
22 |
* |
|
23 |
* @author Jos? Bad?a |
|
24 |
*/ |
|
25 |
public class DefaultEditorChartPropertiesJDialog extends JDialog implements Observer{ |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
*/ |
|
30 |
private static final long serialVersionUID = 822457766380562414L; |
|
31 |
|
|
32 |
private EditorChartPropertiesPanel panel; |
|
33 |
|
|
34 |
private ChartSwingManager swingManager; |
|
35 |
|
|
36 |
/** |
|
37 |
* Standard constructor - builds a font chooser dialog owned by another dialog. |
|
38 |
* |
|
39 |
* @param owner the dialog that 'owns' this dialog. |
|
40 |
* @param title the title for the dialog. |
|
41 |
* @param modal a boolean that indicates whether or not the dialog is modal. |
|
42 |
* @param font the initial font displayed. |
|
43 |
*/ |
|
44 |
public DefaultEditorChartPropertiesJDialog(String title, boolean modal, EditorChartPropertiesPanel panel) { |
|
45 |
super(); |
|
46 |
this.panel = panel; |
|
47 |
this.panel.addObserver(this); |
|
48 |
swingManager = ChartSwingLocator.getSwingManager().getChartSwingManager(); |
|
49 |
setTitle(title); |
|
50 |
setContentPane(panel.getComponent()); |
|
51 |
panel.getComponent().addComponentListener(new ComponentListener() { |
|
52 |
|
|
53 |
public void componentShown(ComponentEvent arg0) { |
|
54 |
// TODO Auto-generated method stub |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
public void componentResized(ComponentEvent arg0) { |
|
59 |
// TODO Auto-generated method stub |
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
public void componentMoved(ComponentEvent arg0) { |
|
64 |
// TODO Auto-generated method stub |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
public void componentHidden(ComponentEvent arg0) { |
|
69 |
DefaultEditorChartPropertiesJDialog.this.dispose(); |
|
70 |
} |
|
71 |
}); |
|
72 |
getContentPane().setVisible(true); |
|
73 |
setPreferredSize(new Dimension(850,500)); |
|
74 |
setModal(true); |
|
75 |
|
|
76 |
pack(); |
|
77 |
setSize(700, 500); |
|
78 |
setVisible(true); |
|
79 |
} |
|
80 |
|
|
81 |
|
|
82 |
public ChartService getChartService(){ |
|
83 |
return panel.getChartService(); |
|
84 |
} |
|
85 |
|
|
86 |
|
|
87 |
public EditorChartPropertiesPanel getMainPanel() { |
|
88 |
return this.panel; |
|
89 |
} |
|
90 |
|
|
91 |
|
|
92 |
public void update(Observable observable, Object notification) { |
|
93 |
if(observable instanceof EditorChartPropertiesPanel){ |
|
94 |
|
|
95 |
if(observable instanceof ChartServiceFormatTitlePanel){ |
|
96 |
ChartServiceFormatTitlePanel titlePanel = (ChartServiceFormatTitlePanel)observable; |
|
97 |
Font newFont = null; |
|
98 |
newFont = FontChooser.showDialog(this.swingManager.getTranslation("Pick_Color"), titlePanel.getTitleFont()); |
|
99 |
if (newFont == null) { |
|
100 |
return; |
|
101 |
} |
|
102 |
titlePanel.setTitleFont(newFont); |
|
103 |
} |
|
104 |
if(observable instanceof ChartServiceFormatLegendPanel){ |
|
105 |
ChartServiceFormatLegendPanel titlePanel = (ChartServiceFormatLegendPanel)observable; |
|
106 |
Font newFont = null; |
|
107 |
newFont = FontChooser.showDialog(this.swingManager.getTranslation("Pick_Color"), titlePanel.getLegendTitleFont()); |
|
108 |
if (newFont == null) { |
|
109 |
return; |
|
110 |
} |
|
111 |
titlePanel.setLegendTitleFont(newFont); |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
} |
|
0 | 117 |
org.gvsig.chart/tags/org.gvsig.chart-1.0.8/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/gui/DefaultEditorGroupedChartIWindow.java | ||
---|---|---|
1 |
package org.gvsig.app.project.documents.chart.gui; |
|
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.beans.PropertyChangeEvent; |
|
9 |
import java.beans.PropertyChangeListener; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
import java.util.Properties; |
|
15 |
|
|
16 |
import javax.swing.JButton; |
|
17 |
import javax.swing.JDialog; |
|
18 |
import javax.swing.JOptionPane; |
|
19 |
import javax.swing.JPanel; |
|
20 |
|
|
21 |
import org.gvsig.andami.PluginServices; |
|
22 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
23 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
24 |
import org.gvsig.app.ApplicationLocator; |
|
25 |
import org.gvsig.app.ApplicationManager; |
|
26 |
import org.gvsig.app.project.Project; |
|
27 |
import org.gvsig.app.project.ProjectManager; |
|
28 |
import org.gvsig.app.project.documents.Document; |
|
29 |
import org.gvsig.app.project.documents.chart.ChartDocument; |
|
30 |
import org.gvsig.app.project.documents.table.TableDocument; |
|
31 |
import org.gvsig.app.project.documents.table.TableManager; |
|
32 |
import org.gvsig.chart.ChartProperties; |
|
33 |
import org.gvsig.chart.ChartService; |
|
34 |
import org.gvsig.chart.GroupedCharts; |
|
35 |
import org.gvsig.chart.model.ChartDataSet; |
|
36 |
import org.gvsig.chart.model.variables.RequiredField; |
|
37 |
import org.gvsig.chart.swing.ChartSwingLocator; |
|
38 |
import org.gvsig.chart.swing.ChartSwingManager; |
|
39 |
import org.gvsig.chart.swing.editors.EditorChartServicePanel; |
|
40 |
import org.gvsig.chart.swing.editors.EditorGroupedChartPanel; |
|
41 |
import org.gvsig.chart.swing.editors.panels.ChartServiceDataPanel; |
|
42 |
import org.gvsig.chart.swing.editors.panels.EditorChartPropertiesPanel; |
|
43 |
import org.gvsig.fmap.dal.exception.DataException; |
|
44 |
import org.gvsig.fmap.dal.feature.Feature; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
46 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
48 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
49 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
50 |
import org.gvsig.tools.observer.Observable; |
|
51 |
import org.gvsig.tools.observer.Observer; |
|
52 |
|
|
53 |
public class DefaultEditorGroupedChartIWindow extends JPanel implements IWindow, Observer { |
|
54 |
|
|
55 |
/** |
|
56 |
* |
|
57 |
*/ |
|
58 |
private static final long serialVersionUID = -412071853707015402L; |
|
59 |
private static final long ROW_LIMIT = 750; |
|
60 |
private static final long ROW_ALERT_LIMIT = 200; |
|
61 |
private EditorGroupedChartPanel editorPanel; |
|
62 |
private GroupedCharts charts; |
|
63 |
private EditorChartServicePanel editorChartServicePanel = null; |
|
64 |
private ChartSwingManager swingManager; |
|
65 |
private ChartDocument document; |
|
66 |
private boolean isFirstTime = true; |
|
67 |
private boolean allowOnlySelectedRows = false; |
|
68 |
private JDialog dialogParent; |
|
69 |
private HashMap<String, TableDocument> tableDocs; |
|
70 |
|
|
71 |
|
|
72 |
public DefaultEditorGroupedChartIWindow(ChartDocument doc) { |
|
73 |
this.document = doc; |
|
74 |
charts = doc.getChartService().copy(); |
|
75 |
|
|
76 |
swingManager = ChartSwingLocator.getSwingManager().getChartSwingManager(); |
|
77 |
|
|
78 |
editorPanel = ChartSwingLocator.getSwingManager().getChartSwingManager().createEditorChartPanel(charts); |
|
79 |
editorPanel.addObserver(this); |
|
80 |
|
|
81 |
GridBagLayout gridBagLayout = new GridBagLayout(); |
|
82 |
/*gridBagLayout.columnWidths = new int[]{0, 0, 655, 0, 0, 0}; |
|
83 |
/*gridBagLayout.rowHeights = new int[]{0, 0, 0}; |
|
84 |
gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; |
|
85 |
gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};*/ |
|
86 |
setLayout(gridBagLayout); |
|
87 |
|
|
88 |
JButton acceptButton = new JButton(this.swingManager.getTranslation("accept")); |
|
89 |
acceptButton.addActionListener(new ActionListener() { |
|
90 |
|
|
91 |
public void actionPerformed(ActionEvent arg0) { |
|
92 |
updateDocument(); |
|
93 |
closeMainWindow(); |
|
94 |
|
|
95 |
} |
|
96 |
}); |
|
97 |
acceptButton.setSize(100, acceptButton.getHeight()); |
|
98 |
|
|
99 |
GridBagConstraints gbc_panel = new GridBagConstraints(); |
|
100 |
gbc_panel.gridwidth = 5; |
|
101 |
gbc_panel.insets = new Insets(5, 5, 5, 5); |
|
102 |
gbc_panel.gridx = 0; |
|
103 |
gbc_panel.gridy = 0; |
|
104 |
gbc_panel.fill = GridBagConstraints.BOTH; |
|
105 |
gbc_panel.weightx = 1.0; |
|
106 |
gbc_panel.weighty = 1.0; |
|
107 |
add(editorPanel.getComponent(), gbc_panel); |
|
108 |
|
|
109 |
JButton cancelButton = new JButton(this.swingManager.getTranslation("Cancel")); |
|
110 |
cancelButton.addActionListener(new ActionListener() { |
|
111 |
public void actionPerformed(ActionEvent arg0) { |
|
112 |
closeMainWindow(); |
|
113 |
} |
|
114 |
}); |
|
115 |
|
|
116 |
|
|
117 |
GridBagConstraints gbc_btnNewButton_2 = new GridBagConstraints(); |
|
118 |
gbc_btnNewButton_2.anchor = GridBagConstraints.EAST; |
|
119 |
gbc_btnNewButton_2.insets = new Insets(5, 5, 5, 5); |
|
120 |
gbc_btnNewButton_2.gridx = 4; |
|
121 |
gbc_btnNewButton_2.gridy = 1; |
|
122 |
|
|
123 |
add(acceptButton, gbc_btnNewButton_2); |
|
124 |
|
|
125 |
cancelButton.setSize(100, cancelButton.getHeight()); |
|
126 |
GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints(); |
|
127 |
gbc_btnNewButton_1.anchor = GridBagConstraints.EAST; |
|
128 |
gbc_btnNewButton_1.insets = new Insets(5, 5, 5, 75); |
|
129 |
gbc_panel.fill = GridBagConstraints.BOTH; |
|
130 |
gbc_panel.weightx = 1.0; |
|
131 |
gbc_panel.weighty = 0.0; |
|
132 |
gbc_btnNewButton_1.gridx = 4; |
|
133 |
gbc_btnNewButton_1.gridy = 1; |
|
134 |
add(cancelButton, gbc_btnNewButton_1); |
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
} |
|
139 |
|
|
140 |
protected void closeMainWindow() { |
|
141 |
if(this.dialogParent!=null){ |
|
142 |
this.dialogParent.dispose(); |
|
143 |
}else{ |
|
144 |
PluginServices.getMDIManager().closeWindow(this); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
public void setParentDialog(JDialog parent){ |
|
149 |
this.dialogParent = parent; |
|
150 |
} |
|
151 |
|
|
152 |
public EditorChartServicePanel getEditorChartServicePanel(){ |
|
153 |
return this.editorChartServicePanel; |
|
154 |
} |
|
155 |
|
|
156 |
public TableDocument getDocument(String name){ |
|
157 |
if(tableDocs != null && !tableDocs.isEmpty()){ |
|
158 |
return tableDocs.get(name); |
|
159 |
} |
|
160 |
return null; |
|
161 |
} |
|
162 |
|
|
163 |
public WindowInfo getWindowInfo() { |
|
164 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG |
|
165 |
| WindowInfo.RESIZABLE); |
|
166 |
m_viewinfo |
|
167 |
.setTitle(PluginServices.getText(this, this.swingManager.getTranslation("propiedades_grafico"))); |
|
168 |
m_viewinfo.setWidth(830); |
|
169 |
m_viewinfo.setHeight(545); |
|
170 |
return m_viewinfo; |
|
171 |
} |
|
172 |
|
|
173 |
public Object getWindowProfile() { |
|
174 |
return WindowInfo.PROPERTIES_PROFILE; |
|
175 |
} |
|
176 |
|
|
177 |
public EditorGroupedChartPanel getEditorPanel() { |
|
178 |
return editorPanel; |
|
179 |
} |
|
180 |
|
|
181 |
private void initializeDataSource(ChartServiceDataPanel panel) { |
|
182 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
|
183 |
final Project project = appManager.getCurrentProject(); |
|
184 |
ProjectManager projectManager = appManager.getProjectManager(); |
|
185 |
|
|
186 |
List<Document> tableDocuments = project |
|
187 |
.getDocuments(TableManager.TYPENAME); |
|
188 |
TableDocument[] pts = tableDocuments |
|
189 |
.toArray(new TableDocument[tableDocuments.size()]); |
|
190 |
|
|
191 |
Properties extendedProps = new Properties(); |
|
192 |
tableDocs = new HashMap<String, TableDocument>(); |
|
193 |
List<String> tableNames = new ArrayList<String>(); |
|
194 |
|
|
195 |
for (TableDocument t : pts) { |
|
196 |
tableDocs.put(t.getName(), t); |
|
197 |
tableNames.add(t.getName()); |
|
198 |
} |
|
199 |
|
|
200 |
//props.setDataTableModel(tableNames); |
|
201 |
panel.setTableNameModel(tableNames); |
|
202 |
|
|
203 |
if(tableNames.size() > 0){ |
|
204 |
String tableName = panel.getPreviousChartProperties().getChartTableName(); |
|
205 |
if(tableName != null && tableName != ""){ |
|
206 |
panel.setSelectedTableName(tableName); |
|
207 |
setFieldsForTable(panel, tableName); |
|
208 |
}else{ |
|
209 |
panel.setSelectedTableName(tableNames.get(0)); |
|
210 |
setFieldsForTable(panel, tableNames.get(0)); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
panel.fillTableData(); |
|
215 |
|
|
216 |
} |
|
217 |
|
|
218 |
private boolean isActivatedPanel(ChartServiceDataPanel panel, long total, long selected){ |
|
219 |
if(total>ROW_LIMIT && (selected>ROW_LIMIT || selected ==0)){ |
|
220 |
editorChartServicePanel.setDisableChartCreation(false); |
|
221 |
return false; |
|
222 |
} |
|
223 |
return true; |
|
224 |
} |
|
225 |
|
|
226 |
private void getAlertMessages(ChartServiceDataPanel panel, String tableName){ |
|
227 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
|
228 |
final Project project = appManager.getCurrentProject(); |
|
229 |
|
|
230 |
TableDocument selDoc = (TableDocument) project.getDocument(tableName, |
|
231 |
TableManager.TYPENAME); |
|
232 |
if (selDoc != null) { |
|
233 |
try { |
|
234 |
long total = selDoc.getStore().getFeatureCount(); |
|
235 |
long selected = selDoc.getStore().getFeatureSelection().getSize(); |
|
236 |
this.allowOnlySelectedRows=false; |
|
237 |
editorChartServicePanel.setDisableChartCreation(true); |
|
238 |
String text=""; |
|
239 |
int messageType = JOptionPane.PLAIN_MESSAGE; |
|
240 |
if(total>ROW_LIMIT && (selected>ROW_LIMIT || selected == 0)){ |
|
241 |
// alert |
|
242 |
text += this.swingManager.getTranslation("chart_data_limit_exceeded"); |
|
243 |
text += "\n"; |
|
244 |
text += this.swingManager.getTranslation("chart_data_more_info"); |
|
245 |
text += "\n"; |
|
246 |
messageType = JOptionPane.ERROR_MESSAGE; |
|
247 |
this.allowOnlySelectedRows=true; |
|
248 |
editorChartServicePanel.setDisableChartCreation(false); |
|
249 |
} |
|
250 |
if(total>ROW_LIMIT && selected<ROW_LIMIT && selected>ROW_ALERT_LIMIT){ |
|
251 |
if(!panel.getOnlySelectedRows()){ |
|
252 |
// alert for that |
|
253 |
text += this.swingManager.getTranslation("chart_data_using_selected_rows"); |
|
254 |
text += "\n"; |
|
255 |
text += this.swingManager.getTranslation("chart_data_more_info"); |
|
256 |
text += "\n"; |
|
257 |
} |
|
258 |
this.allowOnlySelectedRows=true; |
|
259 |
// alert for too time |
|
260 |
text += this.swingManager.getTranslation("chart_data_operation_seconds"); |
|
261 |
text += "\n"; |
|
262 |
messageType = JOptionPane.WARNING_MESSAGE; |
|
263 |
} |
|
264 |
if(total>ROW_LIMIT && selected<=ROW_ALERT_LIMIT && selected > 0){ |
|
265 |
if(!panel.getOnlySelectedRows()){ |
|
266 |
// alert for that |
|
267 |
text += this.swingManager.getTranslation("chart_data_using_selected_rows"); |
|
268 |
text += "\n"; |
|
269 |
text += this.swingManager.getTranslation("chart_data_more_info"); |
|
270 |
text += "\n"; |
|
271 |
messageType = JOptionPane.WARNING_MESSAGE; |
|
272 |
} |
|
273 |
this.allowOnlySelectedRows=true; |
|
274 |
} |
|
275 |
if(total>ROW_ALERT_LIMIT && total<=ROW_LIMIT && (selected == 0 || selected > ROW_ALERT_LIMIT)){ |
|
276 |
// alert for too time |
|
277 |
text += this.swingManager.getTranslation("chart_data_operation_seconds"); |
|
278 |
text += "\n"; |
|
279 |
messageType = JOptionPane.INFORMATION_MESSAGE; |
|
280 |
} |
|
281 |
if(selected == 0 && panel.getOnlySelectedRows()){ |
|
282 |
text += this.swingManager.getTranslation("chart_data_no_rows_selected"); |
|
283 |
messageType = JOptionPane.WARNING_MESSAGE; |
|
284 |
} |
|
285 |
|
|
286 |
panel.setOnlySelectedRows(this.allowOnlySelectedRows); |
|
287 |
|
|
288 |
if(!text.equals("") && !isFirstTime){ |
|
289 |
JOptionPane.showConfirmDialog(this, text, |
|
290 |
"Chart data limit exceeded", |
|
291 |
JOptionPane.DEFAULT_OPTION, |
|
292 |
messageType); |
|
293 |
} |
|
294 |
} catch (DataException e) { |
|
295 |
// TODO Auto-generated catch block |
|
296 |
e.printStackTrace(); |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
private void setFieldsForTable(ChartServiceDataPanel panel, String tableName) { |
|
302 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
|
303 |
final Project project = appManager.getCurrentProject(); |
|
304 |
|
|
305 |
TableDocument selDoc = (TableDocument) project.getDocument(tableName, |
|
306 |
TableManager.TYPENAME); |
|
307 |
if (selDoc != null) { |
|
308 |
// We get the fields of this table and put them to lstFields |
|
309 |
try { |
|
310 |
long total_rows = selDoc.getStore().getFeatureCount(); |
|
311 |
long selected_rows = selDoc.getStore().getFeatureSelection().getSize(); |
|
312 |
|
|
313 |
boolean activated = isActivatedPanel(panel, total_rows, selected_rows); |
|
314 |
|
|
315 |
FeatureType featType = selDoc.getStore() |
|
316 |
.getDefaultFeatureType(); |
|
317 |
FeatureAttributeDescriptor[] atts = featType |
|
318 |
.getAttributeDescriptors(); |
|
319 |
List<String> newFields = new ArrayList<String>(); |
|
320 |
List<RequiredField> rFields = null; |
|
321 |
if(panel.getPreviousChartProperties().getChartType().equals(panel.getChartProperties().getChartType())){ |
|
322 |
rFields = panel.getPreviousChartProperties().getRequiredFields(); |
|
323 |
} |
|
324 |
else{ |
|
325 |
rFields = panel.getChartProperties().getRequiredFields(); |
|
326 |
} |
|
327 |
int j=0; |
|
328 |
for (RequiredField rf : rFields) { |
|
329 |
if (rf.isOptional()) |
|
330 |
newFields.add(""); |
|
331 |
|
|
332 |
for (int i = 0; i < atts.length; i++) { |
|
333 |
if(rf.isNumeric()){ |
|
334 |
if (atts[i].getDataType().isNumeric()) { |
|
335 |
newFields.add(atts[i].getName()); |
|
336 |
} |
|
337 |
}else{ |
|
338 |
newFields.add(atts[i].getName()); |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
panel.setRequiredFieldModel(rFields, rf, newFields, activated); |
|
343 |
|
|
344 |
// Seleccionamos el valor previo |
|
345 |
if(rf.getValue()!=null){ |
|
346 |
panel.setSelectedRequiredField(rFields, rf, rf.getValue(), activated); |
|
347 |
} |
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
newFields = new ArrayList<String>(); |
|
352 |
j++; |
|
353 |
} |
|
354 |
// Properties props = ((ChartPanel) panelProps).getExtendedData(); |
|
355 |
// props.put("fieldsCombo", newFields); |
|
356 |
// ((ChartPanel) panelProps).setExtendedData(props); |
|
357 |
} catch (DataException e) { |
|
358 |
// TODO Auto-generated catch block |
|
359 |
e.printStackTrace(); |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
|
|
364 |
public void update(Observable observable, Object notification) { |
|
365 |
if(observable instanceof EditorGroupedChartPanel){ |
|
366 |
EditorGroupedChartPanel editorPanel = (EditorGroupedChartPanel)observable; |
|
367 |
if(notification instanceof GroupedCharts){ |
|
368 |
EditorChartPropertiesPanel editorPropertiesPanel = ChartSwingLocator.getSwingManager().getChartSwingManager().createEditorChartPropertiesPanel( |
|
369 |
(ChartService)editorPanel.getGroupedChart(), |
|
370 |
editorPanel.getGroupedChart()); |
|
371 |
ChartService service = EditorChartServiceJDialog.showDialog( |
|
372 |
this.swingManager.getTranslation("General_options"), |
|
373 |
editorPropertiesPanel |
|
374 |
); |
|
375 |
if(service != null){ |
|
376 |
editorPanel.refreshInformation(); |
|
377 |
} |
|
378 |
} |
|
379 |
if(notification == null){ |
|
380 |
ChartSwingManager swingManager = ChartSwingLocator.getSwingManager().getChartSwingManager(); |
|
381 |
editorChartServicePanel = swingManager.createNewChartPanel(this.charts); |
|
382 |
editorChartServicePanel.addObserver(getEditorPanel()); |
|
383 |
ChartService service = EditorChartServiceJDialog.showDialog( |
|
384 |
this.swingManager.getTranslation("Add_new_variable"), |
|
385 |
editorChartServicePanel); |
|
386 |
if(service != null){ |
|
387 |
getEditorPanel().getGroupedChart().addChartService(service); |
|
388 |
getEditorPanel().notifyObservers(getEditorPanel().getGroupedChart(), service); |
|
389 |
int services = getEditorPanel().getGroupedChart().getChartServices().size(); |
|
390 |
if(services > 1){ |
|
391 |
for(int x=services; x>1; x--){ |
|
392 |
ChartService prev_service = getEditorPanel().getGroupedChart().getChartServices().get(x-2); |
|
393 |
service = getEditorPanel().getGroupedChart().getChartServices().get(x-1); |
|
394 |
getEditorPanel().getGroupedChart().updateChartService(x-2, service); |
|
395 |
getEditorPanel().getGroupedChart().updateChartService(x-1, prev_service); |
|
396 |
} |
|
397 |
getEditorPanel().getGroupedChart().refreshCharts(); |
|
398 |
getEditorPanel().getGroupedChart().redrawCharts(); |
|
399 |
getEditorPanel().getGroupedChart().notifyChange( |
|
400 |
getEditorPanel().getGroupedChart()); |
|
401 |
|
|
402 |
} |
|
403 |
} |
|
404 |
editorChartServicePanel = null; |
|
405 |
} |
|
406 |
if(!(notification instanceof GroupedCharts) && |
|
407 |
notification instanceof ChartService){ |
|
408 |
int index = getEditorPanel().getGroupedChart().getChartServices().indexOf((ChartService)notification); |
|
409 |
createNewChartVariable(index); |
|
410 |
} |
|
411 |
getEditorPanel().getGroupedChart().refreshCharts(); |
|
412 |
} |
|
413 |
if(observable instanceof ChartServiceDataPanel){ |
|
414 |
if(notification != null && notification instanceof String){ |
|
415 |
setFieldsForTable(((ChartServiceDataPanel)observable), (String) notification); |
|
416 |
getAlertMessages(((ChartServiceDataPanel)observable), (String) notification); |
|
417 |
isFirstTime=false; |
|
418 |
} |
|
419 |
if(notification != null && notification instanceof ChartService){ |
|
420 |
try { |
|
421 |
if(editorChartServicePanel != null){ |
Also available in: Unified diff