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