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