Revision 440

View differences:

org.gvsig.chart/tags/org.gvsig.chart-1.0.76/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.76/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.76/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.76/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.76/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.76/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.76/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){
422
						if(editorChartServicePanel.isEditing()){
423
							getEditorPanel().getGroupedChart().updateChartService(
424
									editorChartServicePanel.getChartServiceIndexEdited(), 
425
									editorChartServicePanel.getNewChartService());
426
							ChartServiceDataPanel dataPanel = (ChartServiceDataPanel)observable;
427
							dataPanel.fillTableData();
428
							getEditorPanel().getGroupedChart().updateChartService(
429
									editorChartServicePanel.getChartServiceIndexEdited(), 
430
									editorChartServicePanel.getPreviousChartService());
431
						}else{
432
							getEditorPanel().getGroupedChart().addChartService(editorChartServicePanel.getNewChartService());
433
							getEditorPanel().notifyObservers(getEditorPanel().getGroupedChart(), editorChartServicePanel.getNewChartService());
434
//							ChartServiceDataPanel dataPanel = (ChartServiceDataPanel)observable;
435
//							editorChartServicePanel.getNewChartService().createChartLegendItems();
436
//							dataPanel.fillTableData();
437
							getEditorPanel().getGroupedChart().deleteChartService(editorChartServicePanel.getNewChartService());
438
						}
439
					}
440
					
441

  
442
					refreshChartServiceData((ChartService)notification);
443
				} catch (DataException e) {
444
					// TODO Auto-generated catch block
445
					e.printStackTrace();
446
				}
447
			}
448
			if(notification == null){
449
				initializeDataSource(((ChartServiceDataPanel)observable));
450
			}
451
		}
452
		if(observable instanceof GroupedCharts){
453
//			if(notification != null && notification instanceof ChartService){
454
//				try {
455
//					refreshChartServiceData((ChartService)notification);
456
//				} catch (DataException e) {
457
//					// TODO Auto-generated catch block
458
//					e.printStackTrace();
459
//				}
460
//			}else{
461
				refreshGroupedChartsData();
462
//			}
463
		}
464
	}
465
	
466
	public void createNewChartVariable(int index) {
467
	
468
		ChartSwingManager swingManager = ChartSwingLocator.getSwingManager().getChartSwingManager();
469
		editorChartServicePanel = swingManager.createEditorChartPanel(index, this.charts);
470
		editorChartServicePanel.addObserver(getEditorPanel());
471
		ChartService service =  EditorChartServiceJDialog.showDialog(
472
				this.swingManager.getTranslation("Edit_a_variable"),
473
				editorChartServicePanel);
474
		if(service != null){
475
			getEditorPanel().getGroupedChart().updateChartService(index, service);
476
			getEditorPanel().getGroupedChart().refreshCharts();
477
			getEditorPanel().getGroupedChart().redrawCharts();
478
			getEditorPanel().getGroupedChart().notifyChange(
479
					getEditorPanel().getGroupedChart());
480
			getEditorPanel().notifyObservers(getEditorPanel().getGroupedChart(), service);
481

  
482
		}
483
		editorChartServicePanel = null;
484
	}
485

  
486
	public ChartDocument getChartDocument(){
487
		return this.document;
488
	}
489
	
490
	private void updateDocument(){
491
		getChartDocument().setChartService(this.charts);
492
	}
493
	
494
	/**
495
	 * We read the actual data and create the ChartDataSet
496
	 * @param cs
497
	 * @throws DataException
498
	 */
499
	public void refreshChartServiceData(ChartService cs) throws DataException{
500
		ApplicationManager appManager = ApplicationLocator.getManager();
501
		Project project = appManager.getCurrentProject();
502
		
503
		ChartProperties cp = cs.getChartProperties();
504

  
505
		FeatureSet fs;
506
		String tableName = cs.getChartProperties().getChartTableName();
507
		if(tableName != null){
508
			TableDocument table = (TableDocument) project.getDocument(
509
					tableName, TableManager.TYPENAME);
510

  
511
			if (table == null) {
512
				throw new RuntimeException("No se encuentra la tabla "
513
						+ tableName);
514
			}
515
			ChartDataSet dataSet = cs.getChartDataSet();
516
			FeatureSelection fsel = table.getStore().getFeatureSelection();
517
			fs = table.getStore().getFeatureSet(); 
518
			
519
			DisposableIterator it = null;
520
			
521
			if (cp.getUseSelectedFeatures()) {
522
				it = fsel.fastIterator();
523
			}
524
			else {
525
				it = fs.fastIterator();
526
			}
527

  
528
			int[] fieldIDs = new int[cp.getRequiredFields().size()];
529
			ArrayList[] data = new ArrayList[cp.getRequiredFields().size()];
530

  
531
			// Buscamos los ID de los campos que vamos a usar.
532
			for (int j = 0; j < cp.getRequiredFields().size(); j++) {
533
				RequiredField rq = cp.getRequiredFields().get(j);
534

  
535
					if (fs.getDefaultFeatureType()
536
							.getAttributeDescriptor(rq.getValue()) == null)
537
						fieldIDs[j] = -1;
538
					else{
539
						fieldIDs[j] = fs.getDefaultFeatureType()
540
							.getAttributeDescriptor(rq.getValue()).getIndex();
541
					}
542

  
543
				ArrayList<Object> aux = new ArrayList<Object>();
544
				data[j] = aux;
545
			}
546

  
547
			// if onlyRecordsSelected is set, we should iterate by selected features only
548
			while (it.hasNext()) {
549
				Feature f = (Feature) it.next();
550
				for (int j = 0; j < fieldIDs.length; j++) {
551
					if (fieldIDs[j] != -1)
552
						data[j].add(f.get(fieldIDs[j]));
553
				}
554
			}
555
			for (int j = 0; j < fieldIDs.length; j++) {
556
				RequiredField rq = cp.getRequiredFields().get(j);
557
				if (fieldIDs[j] != -1)
558
					dataSet.addData(rq.getName(),
559
						data[j]);
560
			}
561
			it.dispose();
562
			cs.setChartDataSet(dataSet);
563
		}
564
	}
565
	
566
	public void refreshGroupedChartsData() {
567
		List<ChartService> chartServices = charts.getChartServices();
568
		for (int i = 0; i < chartServices.size(); i++) {
569
			try {
570
				ChartService cs = chartServices.get(i);
571
				refreshChartServiceData(cs);
572
			} catch (DataException e) {
573
				// TODO Auto-generated catch block
574
				e.printStackTrace();
575
			}
576
		}
577
		
578
//		try {
579
//			overlay = this.chartDocumentContext.getMainChart();
580
//			
581
//			if(overlay instanceof GroupedCharts){
582
//				GroupedCharts oc = (GroupedCharts)overlay;
583
//				oc.setChartServices(chartServices);
584
//				
585
//				this.previewPanel.setChartService(overlay);
586
//			}
587
//			
588
//		} catch (ServiceException e) {
589
//			// TODO Auto-generated catch block
590
//			e.printStackTrace();
591
//		}
592
		
593
	}
594

  
595
	public void setEditorChartServicePanel(
596
			EditorChartServicePanel createNewChartPanel) {
597
		this.editorChartServicePanel = createNewChartPanel;
598
	}
599

  
600
}
601

  
0 602

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.76/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/gui/DefaultChartDocumentPanel.java
1
package org.gvsig.app.project.documents.chart.gui;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Dimension;
5
import java.beans.PropertyChangeEvent;
6
import java.beans.PropertyChangeListener;
7

  
8
import javax.swing.JPanel;
9

  
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.andami.ui.mdiManager.IWindowListener;
12
import org.gvsig.andami.ui.mdiManager.IWindowTransform;
13
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
14
import org.gvsig.andami.ui.mdiManager.WindowInfo;
15
import org.gvsig.app.project.documents.Document;
16
import org.gvsig.app.project.documents.chart.ChartDocument;
17
import org.gvsig.app.project.documents.chart.events.ChartPropertiesChangeEvent;
18
import org.gvsig.app.project.documents.chart.events.ChartPropertiesChangeListener;
19
import org.gvsig.app.project.documents.gui.IDocumentWindow;
20
import org.gvsig.app.project.documents.gui.WindowLayout;
21
import org.gvsig.chart.swing.ChartSwingLocator;
22
import org.gvsig.chart.swing.ViewChartPanel;
23

  
24
public class DefaultChartDocumentPanel extends JPanel 
25
	implements ChartPropertiesChangeListener,IDocumentWindow, IWindowListener, IWindowTransform, SingletonWindow {
26
	/**
27
	 * 
28
	 */
29
	private static final long serialVersionUID = -3830098539680196793L;
30

  
31
    private static final int DEFAULT_HEIGHT = 400;
32
    private static final int DEFAULT_WIDTH = 800;
33
		
34
//	private static MapControlManager mapControlManager = MapControlLocator.getMapControlManager();
35

  
36
	private ChartDocument model = null;
37
	
38
    private WindowInfo m_viewInfo = null;
39
    
40
    private ViewChartPanel mainPanel = null;
41
    
42
	public DefaultChartDocumentPanel(){
43
		super();
44
    	this.initialize();
45
	}
46
	
47
	public DefaultChartDocumentPanel(Document document) {
48
    	super();
49
    	this.model = (ChartDocument) document;
50
    	this.initialize();
51
    	
52
    	this.setDocument(document);
53
    }
54
	
55
	public void initialize() {
56
    	this.setName("Chart");
57

  
58
//    	//TODO Remove this when the system to load libraries is finished
59
//    	if (mapControlManager == null){
60
//    		 mapControlManager = MapControlLocator.getMapControlManager();
61
//    	}
62
    	
63
		ViewChartPanel chartPanel = ChartSwingLocator.getSwingManager().getChartSwingManager().createViewChartPanel(getChartDocument().getChartService());
64
		this.mainPanel = chartPanel;
65
		
66
		this.setLayout(new BorderLayout());
67
		this.add(chartPanel.getComponent(), BorderLayout.CENTER);
68
	}
69

  
70
	public void windowActivated() {
71
		// TODO Auto-generated method stub
72
		
73
	}
74

  
75
	public void windowClosed() {
76
		// TODO Auto-generated method stub
77
		
78
	}
79

  
80
	public void toPalette() {
81
		// TODO Auto-generated method stub
82
		
83
	}
84

  
85
	public void restore() {
86
		// TODO Auto-generated method stub
87
		
88
	}
89

  
90
	public boolean isPalette() {
91
		// TODO Auto-generated method stub
92
		return false;
93
	}
94

  
95
	public Object getWindowModel() {
96
		return this.model.getName();
97
	}
98

  
99
	public WindowInfo getWindowInfo() {
100
		if (m_viewInfo == null) {
101
            m_viewInfo =
102
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
103
                    | WindowInfo.MAXIMIZABLE);
104
            m_viewInfo.setWidth(DEFAULT_WIDTH);
105
            m_viewInfo.setHeight(DEFAULT_HEIGHT);
106
            
107
            m_viewInfo.setTitle(PluginServices.getText(this, "Chart") + " : "
108
                + this.getWindowModel());
109
        }
110
        return m_viewInfo;
111
	}
112

  
113
	public Object getWindowProfile() {
114
		return WindowInfo.PROPERTIES_PROFILE;
115
	}
116

  
117
	public WindowLayout getWindowLayout() {
118
		return null;
119
	}
120

  
121
	public void setWindowLayout(WindowLayout layout) {
122
	}
123

  
124
	public void setDocument(Document document) {
125
		if(this.model == null){
126
			this.model = (ChartDocument) document;
127
		}
128
		this.setName(document.getName());
129
//			chartProperties = this.model.getChartProperties();
130
//			ChartService chartService = ChartLocator.getServiceManager().getChartManager().createChart(chartProperties);
131
////			chartService.setDataset(data)
132
////			ChartDataSet chartDataset = this.model.getChartDataset();
133
////			chartService.setDataset(chartDataset);
134
//			getChartPanel().setChartService(chartService);
135
//			this.getChartPanel().setChartService(chartService);
136
//		} catch (ServiceException e) {
137
//			// TODO Auto-generated catch block
138
//			e.printStackTrace();
139
//		}
140

  
141
		this.model.addPropertyChangeListener(new PropertyChangeListener() {
142

  
143
            public void propertyChange(PropertyChangeEvent evt) {
144
                if (evt.getPropertyName().equals("name")) {
145
                    PluginServices
146
                        .getMDIManager()
147
                        .getWindowInfo(DefaultChartDocumentPanel.this)
148
                        .setTitle(
149
                            PluginServices.getText(this, "Chart") + " : "
150
                                + (String) evt.getNewValue());
151
                }
152
            }
153
        });
154
	}
155

  
156
	public Document getDocument() {
157
		return this.model;
158
	}
159
	
160
	public ChartDocument getChartDocument() {
161
		if(this.model instanceof ChartDocument)
162
			return (ChartDocument) this.model;
163
		return null;
164
	}
165
	
166
	 public ViewChartPanel getChartPanel() {
167
	    return this.mainPanel;
168
	 }
169
	 
170
	 public void setChartPanel(ViewChartPanel panel) {
171
        if (this.mainPanel != null) {
172
            remove(this.mainPanel.getComponent());
173
        }
174
        this.mainPanel = panel;
175
        add(this.mainPanel.getComponent());
176
        Dimension prefSize = this.mainPanel.getComponent().getPreferredSize();
177
        this.setSize(prefSize);
178
        this.repaint();
179
	 }
180

  
181
	
182
	// Cuando el Properties cambia, repinta le panel
183
	public void chartPropertiesChange(ChartPropertiesChangeEvent evt) {
184
		System.out.println("ChartDocument: chartPropertiesChange");
185
		getChartPanel().setOverlayChart(this.getChartDocument().getChartService());
186
		repaint();
187
////		this.getChartDocument().getChartService().draw(
188
////				(Graphics2D) this.getGraphics(), 
189
////				this.getBounds());
190
//		
191
	}
192

  
193
}
0 194

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.76/org.gvsig.chart.app/org.gvsig.chart.app.mainplugin/src/main/java/org/gvsig/app/project/documents/chart/gui/DefaultEditorChartServiceJDialog.java
1
package org.gvsig.app.project.documents.chart.gui;
2

  
3
import java.awt.Dimension;
4
import java.awt.event.ComponentEvent;
5
import java.awt.event.ComponentListener;
6

  
7
import javax.swing.JDialog;
8

  
9
import org.gvsig.chart.ChartService;
10
import org.gvsig.chart.swing.editors.EditorChartServicePanel;
11

  
12
/**
13
 * A dialog for choosing a font from the available system fonts.
14
 *
15
 * @author Jos? Bad?a
16
 */
17
public class DefaultEditorChartServiceJDialog  extends JDialog {
18

  
19
    /**
20
	 * 
21
	 */
22
	private static final long serialVersionUID = 822457766380562414L;
23
	
24
    private EditorChartServicePanel editorPanel;
25

  
26
    /**
27
     * Standard constructor - builds a font chooser dialog owned by another dialog.
28
     *
29
     * @param owner  the dialog that 'owns' this dialog.
30
     * @param title  the title for the dialog.
31
     * @param modal  a boolean that indicates whether or not the dialog is modal.
32
     * @param font  the initial font displayed.
33
     */
34
    public DefaultEditorChartServiceJDialog(String title, boolean modal, EditorChartServicePanel panel) {
35
        super();
36
        editorPanel = panel;
37
        setTitle(title);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff