Revision 765

View differences:

org.gvsig.chart/tags/org.gvsig.chart-1.0.140/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.140/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.chart">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.140/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.140/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.140/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/ChartDocumentManager.java
1
package org.gvsig.app.project.documents.chart;
2

  
3
import java.util.HashMap;
4

  
5
import javax.swing.ImageIcon;
6
import javax.swing.JPanel;
7

  
8
import org.gvsig.fmap.dal.feature.FeatureStore;
9
import org.gvsig.andami.PluginServices;
10
import org.gvsig.andami.ui.mdiManager.IWindow;
11
import org.gvsig.app.project.ProjectManager;
12
import org.gvsig.app.project.documents.AbstractDocument;
13
import org.gvsig.app.project.documents.AbstractDocumentManager;
14
import org.gvsig.app.project.documents.Document;
15
import org.gvsig.app.project.documents.DocumentManager;
16
import org.gvsig.app.project.documents.chart.gui.DefaultChartDocumentPanel;
17
import org.gvsig.app.project.documents.chart.gui.DefaultEditorGroupedChartIWindow;
18
import org.gvsig.app.project.documents.gui.IDocumentWindow;
19
import org.gvsig.app.project.documents.gui.WindowLayout;
20
import org.gvsig.fmap.IconThemeHelper;
21
import org.gvsig.fmap.dal.feature.FeatureQuery;
22
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel;
23
import org.gvsig.tools.ToolsLocator;
24
import org.gvsig.tools.dynobject.DynObjectManager;
25
import org.gvsig.tools.dynobject.DynStruct;
26
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
27
import org.gvsig.tools.persistence.PersistenceManager;
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

  
31
public class ChartDocumentManager extends AbstractDocumentManager implements DocumentManager{
32

  
33
	final static private Logger logger = LoggerFactory.getLogger(ChartDocumentManager.class);
34

  
35
	public static final String PERSISTENCE_CHART_DOCUMENT_DEFINITION_NAME = "ChartDocumentManager";
36
    public static String TYPENAME = "project.document.chart";
37
    
38
    private DynStruct persistenceDefinition = null;
39
    
40
    private HashMap<Document, JPanel> documents = new HashMap<Document, JPanel>();
41
    
42
    private DefaultEditorGroupedChartIWindow propertiesPanel;
43
    
44
	private static final String CHART_WIZARD_EXTENSION_POINT = "ChartWizardExtensionPoint";
45
	private static final String CHART_WIZARD_NAME = "ChartWizard";
46
	private static ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
47
	
48
	public DynStruct getDefinition(String className) {
49
		if( this.persistenceDefinition.getName().equalsIgnoreCase(className)) {
50
            return this.persistenceDefinition;
51
        }
52
        if( this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) {
53
            return this.persistenceDefinition;
54
        }
55
        if( this.getDocumentClass().getName().equals(className) ) {
56
            return this.persistenceDefinition;
57
        }
58
		return null;
59
	}
60

  
61
	public AbstractDocument createDocument() {
62
		return new ChartDocument(this);
63
	}
64

  
65
	public String getTypeName() {
66
		return TYPENAME;
67
	}
68

  
69
    public ImageIcon getIcon() {
70
        return PluginServices.getIconTheme().get("document-chart-unselect");
71
    }
72
    
73
    public ImageIcon getIconSelected() {
74
        return PluginServices.getIconTheme().get("document-chart-select");
75
    }
76
    
77
    public String getTitle() {
78
        return PluginServices.getText(this, "Charts");
79
    }
80
	
81
	public IWindow getMainWindow(Document doc, WindowLayout layout) {
82
		IDocumentWindow chartPanel;
83
//		chartPanel =
84
//            (IDocumentWindow) PluginServices.getMDIManager()
85
//                .getSingletonWindow(getMainWindowClass(), doc);
86
		chartPanel = (IDocumentWindow) this.getDocumentWindow(doc);
87
        if (chartPanel != null) {
88
            // The table window document is already created, return it.
89
            return chartPanel;
90
        }
91
        
92
        chartPanel = (IDocumentWindow) this.createDocumentWindow(doc);
93
        if(chartPanel instanceof DefaultChartDocumentPanel){
94
        	((ChartDocument)doc).addChartPropertiesChangeEventListener((DefaultChartDocumentPanel)chartPanel);
95
        }
96
        this.registerDocumentWindow(doc, (JPanel) chartPanel);
97
        if (layout != null && chartPanel != null) {
98
        	chartPanel.setWindowLayout(layout);
99
        }
100
        ((AbstractDocument) doc).raiseEventCreateWindow(chartPanel);
101
        return chartPanel;
102
	}
103
	
104
	private void registerDocumentWindow(Document doc, JPanel chartPanel) {
105
		documents.put(doc, chartPanel);
106
	}
107

  
108
	private IWindow getDocumentWindow(Document doc){
109
		if(documents.containsKey(doc)){
110
			return (IWindow) documents.get(doc);
111
		}
112
		return null;
113
	}
114
	
115
	public IWindow getPropertiesWindow(Document doc) {
116
//		if(propertiesPanel == null) {			
117
		propertiesPanel = new DefaultEditorGroupedChartIWindow(((ChartDocument)doc));
118
//		}
119
		return (IWindow) propertiesPanel;
120
	}
121

  
122

  
123
	@Override
124
	protected Class getDocumentClass() {
125
		return ChartDocument.class;
126
	}
127

  
128
	public static void register() {
129
		ChartDocumentManager factory = new ChartDocumentManager();
130
  		// A?adimos nuestra extension para el tratamiento de la apertura de ficheros
131
  		// dentro de gvSIG
132
  		ToolsLocator.getExtensionPointManager().
133
  			add("FileChartOpenDialog", "")
134
  				.append("FileOpenChart", "",	FilesystemExplorerWizardPanel.class);
135
    	
136
  		ProjectManager.getInstance().registerDocumentFactory(factory);
137

  
138
//        ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"copy",new CopyDocumentContextMenuAction());
139
//        ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"cut",new CutDocumentContextMenuAction());
140
//        ProjectFactory.getInstance().registerDocumentAction(TYPENAME,"paste",new PasteDocumentContextMenuAction());
141

  
142
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
143
        manager.registerFactory(factory);
144
        
145
        if (factory.persistenceDefinition == null){
146
            DynObjectManager dynman = ToolsLocator.getDynObjectManager();
147
            factory.persistenceDefinition = dynman.createDynClass(PersistenceManager.PERSISTENCE_NAMESPACE,
148
                PERSISTENCE_CHART_DOCUMENT_DEFINITION_NAME,
149
                "Chart document Persistence definition");
150
            factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
151

  
152
            factory.persistenceDefinition.addDynFieldObject("store").setClassOfValue(FeatureStore.class).setMandatory(true);
153
            factory.persistenceDefinition.addDynFieldString("featureTypeId").setMandatory(false);
154
            factory.persistenceDefinition.addDynFieldArray("attributeNames").setClassOfItems(String.class).setMandatory(false);
155
            factory.persistenceDefinition.addDynFieldObject("query").setClassOfValue(FeatureQuery.class).setMandatory(false);
156
        }
157
        
158
	}
159

  
160
//    public Iterator<? extends Document> createDocumentsByUser() {
161
//        AddLayerDialog fopen = null;
162
//        try {
163
//            fopen =
164
//                new AddLayerDialog(PluginServices.getText(this, "Nueva_grafica"));
165
//            List<WizardPanel> wizards =
166
//                ApplicationLocator.getManager().getWizardPanels();
167
//            WizardPanel panel;
168
//            Iterator<WizardPanel> iter = wizards.iterator();
169
//            while (iter.hasNext()) {
170
//                panel = iter.next();
171
//                fopen.addWizardTab(panel.getTabName(), panel);
172
//                panel.initWizard();
173
//            }
174
//            PluginServices.getMDIManager().addWindow(fopen);
175
//            if (fopen.isAccepted()) {
176
//                panel = (WizardPanel) fopen.getSelectedTab();
177
//                @SuppressWarnings("unchecked")
178
//                List<ChartDocument> docs =
179
//                    (List<ChartDocument>) panel.executeWizard();
180
//                return docs.iterator();
181
//            }
182
//        } catch (Exception e) {
183
//            NotificationManager.addError(e);
184
//        } finally {
185
//            if (fopen != null) {
186
//                fopen.dispose();
187
//                fopen = null;
188
//            }
189
//        }
190
//        return null;
191
//    }
192
//
193
//    public AbstractDocument createDocumentByUser() {
194
//        return (AbstractDocument) createDocumentsByUser().next();
195
//    }
196
	
197
	public AbstractDocument createDocumentByUser(){
198
		AbstractDocument doc = createDocument();
199
		IWindow  propsWindow = getPropertiesWindow(doc);
200
		return doc;
201
	}
202
    
203
	public boolean manages(Object object) {
204
		return object instanceof ChartDocument;
205
	}
206

  
207
	public Class getMainWindowClass() {
208
		return DefaultChartDocumentPanel.class;
209
	}
210
	
211

  
212
}
0 213

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.140/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.140/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.140/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.140/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.140/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.140/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
		
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff