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