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