svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeToAnnotationExtension.java @ 9532
History | View | Annotate | Download (8.52 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 javax.swing.ImageIcon; |
44 |
|
45 |
import jwizardcomponent.FinishAction; |
46 |
import jwizardcomponent.JWizardComponents; |
47 |
|
48 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.andami.plugins.Extension; |
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
52 |
import com.iver.cit.gvsig.fmap.MapContext; |
53 |
import com.iver.cit.gvsig.fmap.core.FShape; |
54 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
58 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
59 |
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation; |
60 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
61 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
62 |
import com.iver.cit.gvsig.gui.panels.annotation.ConfigureLabel; |
63 |
import com.iver.cit.gvsig.gui.panels.annotation.SelectAnnotationLayerNameAndField; |
64 |
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard; |
65 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
66 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
67 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
68 |
|
69 |
|
70 |
/**
|
71 |
* DOCUMENT ME!
|
72 |
*
|
73 |
* @author Vicente Caballero Navarro
|
74 |
*/
|
75 |
public class ThemeToAnnotationExtension extends Extension { |
76 |
private MapContext map=null; |
77 |
private IWindow view=null; |
78 |
/**
|
79 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
80 |
*/
|
81 |
public void initialize() { |
82 |
} |
83 |
|
84 |
/**
|
85 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
86 |
*/
|
87 |
|
88 |
public class MyFinishAction extends FinishAction { |
89 |
private JWizardComponents myWizardComponents;
|
90 |
private MapContext map;
|
91 |
private FLyrVect layerVectorial;
|
92 |
private FLyrAnnotation layerAnnotation;
|
93 |
|
94 |
public MyFinishAction(JWizardComponents wizardComponents, MapContext map,FLyrVect layerVectorial, FLyrAnnotation layerAnnotation ) {
|
95 |
super(wizardComponents);
|
96 |
this.map = map;
|
97 |
this.layerVectorial = layerVectorial;
|
98 |
this.layerAnnotation = layerAnnotation;
|
99 |
myWizardComponents = wizardComponents; |
100 |
|
101 |
} |
102 |
|
103 |
public void performAction() { |
104 |
|
105 |
myWizardComponents.getFinishButton().setEnabled(false);
|
106 |
SelectAnnotationLayerNameAndField panel1 = (SelectAnnotationLayerNameAndField) myWizardComponents.getWizardPanel(0);
|
107 |
ConfigureLabel panel2 = (ConfigureLabel) myWizardComponents.getWizardPanel(1);
|
108 |
|
109 |
|
110 |
SelectableDataSource source; |
111 |
MappingAnnotation mapping=new MappingAnnotation();
|
112 |
|
113 |
try {
|
114 |
source = this.layerAnnotation.getRecordset();
|
115 |
|
116 |
|
117 |
|
118 |
mapping.setColumnText(source.getFieldIndexByName(panel1.getField())); |
119 |
|
120 |
if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
121 |
mapping.setColumnRotate(source.getFieldIndexByName(panel2.getAngleFieldName())); |
122 |
} |
123 |
|
124 |
if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
125 |
mapping.setColumnColor(source.getFieldIndexByName(panel2.getColorFieldName())); |
126 |
} |
127 |
|
128 |
if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
129 |
mapping.setColumnHeight(source.getFieldIndexByName(panel2.getSizeFieldName())); |
130 |
} |
131 |
this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
|
132 |
|
133 |
if (!panel2.getFontFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
134 |
mapping.setColumnTypeFont(source.getFieldIndexByName(panel2.getFontFieldName())); |
135 |
} |
136 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
137 |
// TODO Que hacemos aqui
|
138 |
e.printStackTrace(); |
139 |
return;
|
140 |
} catch (DriverException e) {
|
141 |
// TODO Auto-generated catch block
|
142 |
e.printStackTrace(); |
143 |
} |
144 |
|
145 |
|
146 |
this.layerAnnotation.setName(panel1.getNewLayerName());
|
147 |
this.layerAnnotation.setMapping(mapping);
|
148 |
|
149 |
|
150 |
this.map.getLayers().addLayer(this.layerAnnotation); |
151 |
this.map.getLayers().removeLayer(this.layerVectorial); |
152 |
|
153 |
this.layerAnnotation.setActive(true); |
154 |
this.myWizardComponents.getCancelAction().performAction();
|
155 |
} |
156 |
|
157 |
} |
158 |
public void execute(String actionCommand) { |
159 |
if ("LAYERTOANNOTATION".equals(actionCommand)) { |
160 |
ImageIcon Logo = new javax.swing.ImageIcon(this.getClass().getClassLoader() |
161 |
.getResource("images/package_graphics.png"));
|
162 |
|
163 |
SimpleWizard wizard = new SimpleWizard(Logo);
|
164 |
|
165 |
FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
|
166 |
FLyrAnnotation la=new FLyrAnnotation();
|
167 |
LayerListener[] layerListeners=lv.getLayerListeners();
|
168 |
for (int i=0;i<layerListeners.length;i++) { |
169 |
la.addLayerListener(layerListeners[i]); |
170 |
} |
171 |
|
172 |
la.setSource(lv.getSource()); |
173 |
la.setProjection(lv.getProjection()); |
174 |
|
175 |
SelectAnnotationLayerNameAndField panel1 = new SelectAnnotationLayerNameAndField(wizard.getWizardComponents(),la);
|
176 |
ConfigureLabel panel2 = new ConfigureLabel(wizard.getWizardComponents(),la);
|
177 |
|
178 |
|
179 |
|
180 |
wizard.getWizardComponents().addWizardPanel(panel1); |
181 |
wizard.getWizardComponents().addWizardPanel(panel2); |
182 |
|
183 |
wizard.getWizardComponents().setFinishAction( |
184 |
new MyFinishAction(wizard.getWizardComponents(),
|
185 |
map,lv, la)); |
186 |
|
187 |
wizard.getWindowInfo().setWidth(540);
|
188 |
wizard.getWindowInfo().setHeight(380);
|
189 |
wizard.getWindowInfo().setTitle(PluginServices.getText(this,"to_annotation")); |
190 |
|
191 |
PluginServices.getMDIManager().addWindow(wizard); |
192 |
((ProjectDocument)((View)view).getModel()).setModified(true); |
193 |
|
194 |
|
195 |
/*
|
196 |
FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
|
197 |
FLyrAnnotation la=new FLyrAnnotation();
|
198 |
la.setSource(lv.getSource());
|
199 |
|
200 |
MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
|
201 |
PluginServices.getMDIManager().addView(mfta);
|
202 |
|
203 |
if (mfta.isOk()){
|
204 |
map.getLayers().addLayer(la);
|
205 |
map.getLayers().removeLayer(lv);
|
206 |
}
|
207 |
*/
|
208 |
|
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
214 |
*/
|
215 |
public boolean isEnabled() { |
216 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
217 |
|
218 |
if (v != null && v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) { |
219 |
com.iver.cit.gvsig.project.documents.view.gui.View vista=(com.iver.cit.gvsig.project.documents.view.gui.View)v; |
220 |
IProjectView model = vista.getModel(); |
221 |
map = model.getMapContext(); |
222 |
FLayer[] layers=map.getLayers().getActives();
|
223 |
if (layers.length==1){ |
224 |
if (layers[0].isAvailable() && layers[0] instanceof FLyrVect){ |
225 |
FLyrVect lv=(FLyrVect)layers[0];
|
226 |
ReadableVectorial src = lv.getSource(); |
227 |
try {
|
228 |
if (src == null || src.getShapeType()==FShape.POLYGON || src.getShapeType()==FShape.LINE) |
229 |
return false; |
230 |
SelectableDataSource sds=lv.getSource().getRecordset(); |
231 |
if (sds.getFieldCount()>0) |
232 |
return true; |
233 |
} catch (DriverException e) {
|
234 |
return false; |
235 |
} catch (DriverIOException e1) {
|
236 |
e1.printStackTrace(); |
237 |
} |
238 |
} |
239 |
} |
240 |
} |
241 |
return false; |
242 |
} |
243 |
|
244 |
/**
|
245 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
246 |
*/
|
247 |
public boolean isVisible() { |
248 |
view = PluginServices.getMDIManager().getActiveWindow(); |
249 |
|
250 |
if (view == null) { |
251 |
return false; |
252 |
} else if (view instanceof com.iver.cit.gvsig.project.documents.view.gui.View) { |
253 |
return true; |
254 |
} else {
|
255 |
return false; |
256 |
} |
257 |
} |
258 |
|
259 |
|
260 |
} |