root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeToAnnotationExtension.java @ 14821
History | View | Annotate | Download (9.81 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig; |
42 |
|
43 |
import java.util.ArrayList; |
44 |
|
45 |
import javax.swing.ImageIcon; |
46 |
|
47 |
import jwizardcomponent.FinishAction; |
48 |
import jwizardcomponent.JWizardComponents; |
49 |
|
50 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.andami.plugins.Extension; |
53 |
import com.iver.andami.ui.mdiManager.IWindow; |
54 |
import com.iver.cit.gvsig.fmap.MapContext; |
55 |
import com.iver.cit.gvsig.fmap.core.FShape; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
59 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
60 |
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation; |
61 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
62 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
63 |
import com.iver.cit.gvsig.gui.panels.annotation.ConfigureLabel; |
64 |
import com.iver.cit.gvsig.gui.panels.annotation.SelectAnnotationLayerNameAndField; |
65 |
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard; |
66 |
import com.iver.cit.gvsig.project.Project; |
67 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
68 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
69 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
70 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
71 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
72 |
|
73 |
|
74 |
/**
|
75 |
* DOCUMENT ME!
|
76 |
*
|
77 |
* @author Vicente Caballero Navarro
|
78 |
*/
|
79 |
public class ThemeToAnnotationExtension extends Extension { |
80 |
private MapContext map=null; |
81 |
private IWindow view=null; |
82 |
/**
|
83 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
84 |
*/
|
85 |
public void initialize() { |
86 |
registerIcons(); |
87 |
} |
88 |
|
89 |
private void registerIcons(){ |
90 |
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
95 |
*/
|
96 |
|
97 |
public class MyFinishAction extends FinishAction { |
98 |
private JWizardComponents myWizardComponents;
|
99 |
private MapContext map;
|
100 |
private FLyrVect layerVectorial;
|
101 |
private FLyrAnnotation layerAnnotation;
|
102 |
|
103 |
public MyFinishAction(JWizardComponents wizardComponents, MapContext map,FLyrVect layerVectorial, FLyrAnnotation layerAnnotation ) {
|
104 |
super(wizardComponents);
|
105 |
this.map = map;
|
106 |
this.layerVectorial = layerVectorial;
|
107 |
this.layerAnnotation = layerAnnotation;
|
108 |
myWizardComponents = wizardComponents; |
109 |
|
110 |
} |
111 |
|
112 |
public void performAction() { |
113 |
|
114 |
myWizardComponents.getFinishButton().setEnabled(false);
|
115 |
SelectAnnotationLayerNameAndField panel1 = (SelectAnnotationLayerNameAndField) myWizardComponents.getWizardPanel(0);
|
116 |
ConfigureLabel panel2 = (ConfigureLabel) myWizardComponents.getWizardPanel(1);
|
117 |
|
118 |
|
119 |
SelectableDataSource source; |
120 |
MappingAnnotation mapping=new MappingAnnotation();
|
121 |
|
122 |
try {
|
123 |
source = this.layerAnnotation.getRecordset();
|
124 |
|
125 |
|
126 |
|
127 |
mapping.setColumnText(source.getFieldIndexByName(panel1.getField())); |
128 |
|
129 |
if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
130 |
mapping.setColumnRotate(source.getFieldIndexByName(panel2.getAngleFieldName())); |
131 |
} |
132 |
|
133 |
if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
134 |
mapping.setColumnColor(source.getFieldIndexByName(panel2.getColorFieldName())); |
135 |
} |
136 |
|
137 |
if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
138 |
mapping.setColumnHeight(source.getFieldIndexByName(panel2.getSizeFieldName())); |
139 |
} |
140 |
this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
|
141 |
|
142 |
if (!panel2.getFontFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
143 |
mapping.setColumnTypeFont(source.getFieldIndexByName(panel2.getFontFieldName())); |
144 |
} |
145 |
} catch (ReadDriverException e) {
|
146 |
e.printStackTrace(); |
147 |
return;
|
148 |
} |
149 |
|
150 |
|
151 |
this.layerAnnotation.setName(panel1.getNewLayerName());
|
152 |
this.layerAnnotation.setMapping(mapping);
|
153 |
|
154 |
|
155 |
this.map.getLayers().addLayer(this.layerAnnotation); |
156 |
this.map.getLayers().removeLayer(this.layerVectorial); |
157 |
|
158 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
159 |
ArrayList projectTables=project.getDocumentsByType(ProjectTableFactory.registerName);
|
160 |
for (int i=0;i<projectTables.size();i++){ |
161 |
ProjectTable pt=(ProjectTable)projectTables.get(i); |
162 |
if (pt.getAssociatedTable()!=null && pt.getAssociatedTable().equals(this.layerVectorial)){ |
163 |
pt.setAssociatedTable(this.layerAnnotation);
|
164 |
} |
165 |
} |
166 |
|
167 |
this.layerAnnotation.setActive(true); |
168 |
this.myWizardComponents.getCancelAction().performAction();
|
169 |
} |
170 |
|
171 |
} |
172 |
public void execute(String actionCommand) { |
173 |
if ("LAYERTOANNOTATION".equals(actionCommand)) { |
174 |
ImageIcon Logo = new javax.swing.ImageIcon(this.getClass().getClassLoader() |
175 |
.getResource("images/package_graphics.png"));
|
176 |
|
177 |
SimpleWizard wizard = new SimpleWizard(Logo);
|
178 |
|
179 |
FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
|
180 |
FLyrAnnotation la=new FLyrAnnotation();
|
181 |
LayerListener[] layerListeners=lv.getLayerListeners();
|
182 |
for (int i=0;i<layerListeners.length;i++) { |
183 |
la.addLayerListener(layerListeners[i]); |
184 |
} |
185 |
|
186 |
la.setSource(lv.getSource()); |
187 |
la.setProjection(lv.getProjection()); |
188 |
|
189 |
SelectAnnotationLayerNameAndField panel1 = new SelectAnnotationLayerNameAndField(wizard.getWizardComponents(),la);
|
190 |
ConfigureLabel panel2 = new ConfigureLabel(wizard.getWizardComponents(),la);
|
191 |
|
192 |
|
193 |
|
194 |
wizard.getWizardComponents().addWizardPanel(panel1); |
195 |
wizard.getWizardComponents().addWizardPanel(panel2); |
196 |
|
197 |
wizard.getWizardComponents().setFinishAction( |
198 |
new MyFinishAction(wizard.getWizardComponents(),
|
199 |
map,lv, la)); |
200 |
|
201 |
wizard.getWindowInfo().setWidth(540);
|
202 |
wizard.getWindowInfo().setHeight(380);
|
203 |
wizard.getWindowInfo().setTitle(PluginServices.getText(this,"to_annotation")); |
204 |
|
205 |
PluginServices.getMDIManager().addWindow(wizard); |
206 |
((ProjectDocument)((View)view).getModel()).setModified(true); |
207 |
|
208 |
|
209 |
/*
|
210 |
FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
|
211 |
FLyrAnnotation la=new FLyrAnnotation();
|
212 |
la.setSource(lv.getSource());
|
213 |
|
214 |
MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
|
215 |
PluginServices.getMDIManager().addView(mfta);
|
216 |
|
217 |
if (mfta.isOk()){
|
218 |
map.getLayers().addLayer(la);
|
219 |
map.getLayers().removeLayer(lv);
|
220 |
}
|
221 |
*/
|
222 |
|
223 |
} |
224 |
} |
225 |
|
226 |
/**
|
227 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
228 |
*/
|
229 |
public boolean isEnabled() { |
230 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
231 |
|
232 |
if (v != null && v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) { |
233 |
com.iver.cit.gvsig.project.documents.view.gui.View vista=(com.iver.cit.gvsig.project.documents.view.gui.View)v; |
234 |
IProjectView model = vista.getModel(); |
235 |
map = model.getMapContext(); |
236 |
FLayer[] layers=map.getLayers().getActives();
|
237 |
if (layers.length==1){ |
238 |
if (layers[0].isAvailable() && layers[0] instanceof FLyrVect){ |
239 |
FLyrVect lv=(FLyrVect)layers[0];
|
240 |
ReadableVectorial src = lv.getSource(); |
241 |
try {
|
242 |
if (src == null || src.getShapeType()==FShape.POLYGON || src.getShapeType()==FShape.LINE) |
243 |
return false; |
244 |
SelectableDataSource sds=lv.getSource().getRecordset(); |
245 |
if (sds.getFieldCount()>0) |
246 |
return true; |
247 |
} catch (ReadDriverException e) {
|
248 |
return false; |
249 |
} |
250 |
} |
251 |
} |
252 |
} |
253 |
return false; |
254 |
} |
255 |
|
256 |
/**
|
257 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
258 |
*/
|
259 |
public boolean isVisible() { |
260 |
view = PluginServices.getMDIManager().getActiveWindow(); |
261 |
|
262 |
if (view == null) { |
263 |
return false; |
264 |
} else if (view instanceof com.iver.cit.gvsig.project.documents.view.gui.View) { |
265 |
return true; |
266 |
} else {
|
267 |
return false; |
268 |
} |
269 |
} |
270 |
|
271 |
|
272 |
} |