Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeToAnnotationExtension.java @ 11359

History | View | Annotate | Download (8.26 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 10626 caballero
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
49 4224 caballero
import com.iver.andami.PluginServices;
50
import com.iver.andami.plugins.Extension;
51 6877 cesar
import com.iver.andami.ui.mdiManager.IWindow;
52 6878 cesar
import com.iver.cit.gvsig.fmap.MapContext;
53 6729 caballero
import com.iver.cit.gvsig.fmap.core.FShape;
54 4224 caballero
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 5908 caballero
import com.iver.cit.gvsig.fmap.layers.LayerListener;
58 5457 jmvivo
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation;
59 6400 jmvivo
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
60 4224 caballero
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
61 6117 jaume
import com.iver.cit.gvsig.gui.panels.annotation.ConfigureLabel;
62
import com.iver.cit.gvsig.gui.panels.annotation.SelectAnnotationLayerNameAndField;
63 5457 jmvivo
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard;
64 9532 caballero
import com.iver.cit.gvsig.project.documents.ProjectDocument;
65 7392 sbayarri
import com.iver.cit.gvsig.project.documents.view.IProjectView;
66 9532 caballero
import com.iver.cit.gvsig.project.documents.view.gui.View;
67 4224 caballero
68
69
/**
70
 * DOCUMENT ME!
71
 *
72
 * @author Vicente Caballero Navarro
73
 */
74 5005 jorpiell
public class ThemeToAnnotationExtension extends Extension {
75 6878 cesar
    private MapContext map=null;
76 9532 caballero
    private IWindow view=null;
77 4224 caballero
        /**
78 5005 jorpiell
     * @see com.iver.andami.plugins.IExtension#initialize()
79 4224 caballero
     */
80 5005 jorpiell
    public void initialize() {
81 4224 caballero
    }
82
83
    /**
84 5005 jorpiell
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
85 4224 caballero
     */
86 5694 caballero
87 5457 jmvivo
    public class MyFinishAction extends FinishAction {
88
            private JWizardComponents myWizardComponents;
89 6878 cesar
            private MapContext map;
90 5457 jmvivo
            private FLyrVect layerVectorial;
91
            private FLyrAnnotation layerAnnotation;
92
93 6878 cesar
                public MyFinishAction(JWizardComponents wizardComponents, MapContext map,FLyrVect layerVectorial, FLyrAnnotation layerAnnotation ) {
94 5457 jmvivo
                        super(wizardComponents);
95
                        this.map = map;
96
                        this.layerVectorial = layerVectorial;
97
                        this.layerAnnotation = layerAnnotation;
98
                        myWizardComponents = wizardComponents;
99 5694 caballero
100 5457 jmvivo
                }
101
102
                public void performAction() {
103 5694 caballero
104 5481 jmvivo
                        myWizardComponents.getFinishButton().setEnabled(false);
105 5457 jmvivo
                        SelectAnnotationLayerNameAndField panel1 = (SelectAnnotationLayerNameAndField) myWizardComponents.getWizardPanel(0);
106
                        ConfigureLabel panel2 = (ConfigureLabel) myWizardComponents.getWizardPanel(1);
107 5694 caballero
108
109 5457 jmvivo
                        SelectableDataSource source;
110
                        MappingAnnotation mapping=new MappingAnnotation();
111 5694 caballero
112 5457 jmvivo
                        try {
113
                                source = this.layerAnnotation.getRecordset();
114
115 5694 caballero
116
117 5457 jmvivo
                                mapping.setColumnText(source.getFieldIndexByName(panel1.getField()));
118 5694 caballero
119 5485 jmvivo
                                if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
120 5457 jmvivo
                                        mapping.setColumnRotate(source.getFieldIndexByName(panel2.getAngleFieldName()));
121
                                }
122 5694 caballero
123 5485 jmvivo
                                if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
124 5457 jmvivo
                                        mapping.setColumnColor(source.getFieldIndexByName(panel2.getColorFieldName()));
125
                                }
126 5694 caballero
127 5485 jmvivo
                                if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
128 5694 caballero
                                        mapping.setColumnHeight(source.getFieldIndexByName(panel2.getSizeFieldName()));
129 5457 jmvivo
                                }
130 5485 jmvivo
                                this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
131 5694 caballero
132 5485 jmvivo
                                if (!panel2.getFontFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
133 5457 jmvivo
                                        mapping.setColumnTypeFont(source.getFieldIndexByName(panel2.getFontFieldName()));
134
                                }
135 10626 caballero
                        } catch (ReadDriverException e) {
136 5457 jmvivo
                                e.printStackTrace();
137
                                return;
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 6880 cesar
                        wizard.getWindowInfo().setWidth(540);
183
                        wizard.getWindowInfo().setHeight(380);
184
                        wizard.getWindowInfo().setTitle(PluginServices.getText(this,"to_annotation"));
185 5694 caballero
186 6880 cesar
                        PluginServices.getMDIManager().addWindow(wizard);
187 9532 caballero
                        ((ProjectDocument)((View)view).getModel()).setModified(true);
188 5694 caballero
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 6880 cesar
            IWindow v = PluginServices.getMDIManager().getActiveWindow();
212 4224 caballero
213 7304 caballero
        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 7392 sbayarri
                IProjectView model = vista.getModel();
216 4224 caballero
                    map = model.getMapContext();
217
                    FLayer[] layers=map.getLayers().getActives();
218
                    if (layers.length==1){
219 6778 jmvivo
                            if (layers[0].isAvailable() && layers[0] instanceof FLyrVect){
220 4224 caballero
                                    FLyrVect lv=(FLyrVect)layers[0];
221 6400 jmvivo
                                    ReadableVectorial src = lv.getSource();
222 4224 caballero
                                    try {
223 6729 caballero
                                                if (src == null || src.getShapeType()==FShape.POLYGON || src.getShapeType()==FShape.LINE)
224
                                                        return false;
225
                                                SelectableDataSource sds=lv.getSource().getRecordset();
226 4224 caballero
                                                if (sds.getFieldCount()>0)
227
                                                        return true;
228 10626 caballero
                                        } catch (ReadDriverException e) {
229 4224 caballero
                                                return false;
230
                                        }
231
                            }
232
                    }
233
        }
234 6778 jmvivo
        return false;
235 4224 caballero
    }
236
237
    /**
238 5005 jorpiell
     * @see com.iver.andami.plugins.IExtension#isVisible()
239 4224 caballero
     */
240
    public boolean isVisible() {
241 9532 caballero
        view = PluginServices.getMDIManager().getActiveWindow();
242 4224 caballero
243 9532 caballero
        if (view == null) {
244 4224 caballero
            return false;
245 9532 caballero
        } else if (view instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
246 4224 caballero
            return true;
247
        } else {
248
            return false;
249
        }
250
    }
251 5457 jmvivo
252 5694 caballero
253 4224 caballero
}