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