Statistics
| Revision:

root / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / Annotation_Extension.java @ 11545

History | View | Annotate | Download (6.66 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 com.hardcode.gdbms.engine.data.driver.DriverException;
46
import com.iver.andami.PluginServices;
47
import com.iver.andami.plugins.Extension;
48
import com.iver.andami.ui.mdiManager.IWindow;
49
import com.iver.cit.gvsig.fmap.MapContext;
50
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
51
import com.iver.cit.gvsig.fmap.layers.FLayer;
52
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
53
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
54
import com.iver.cit.gvsig.gui.panels.FPanelAbout;
55
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard;
56
import com.iver.cit.gvsig.project.documents.gui.Annotation_ConfigureLabel;
57
import com.iver.cit.gvsig.project.documents.gui.Annotation_Create;
58
import com.iver.cit.gvsig.project.documents.gui.Annotation_FieldSelect;
59
import com.iver.cit.gvsig.project.documents.gui.Annotation_Open;
60
import com.iver.cit.gvsig.project.documents.view.IProjectView;
61

    
62

    
63
/**
64
 * Extension to create an annotation layer.
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class Annotation_Extension extends Extension {
69
    private MapContext map = null;
70

    
71
    /**
72
     * @see com.iver.andami.plugins.IExtension#initialize()
73
     */
74
    public void initialize() {
75
        System.out.println("A?ado WizardAnnotation.");
76
        AddLayer.addWizard(Annotation_Open.class);
77
    }
78
    
79
    public void postInitialize() {
80
                // TODO Auto-generated method stub
81
                super.postInitialize();
82
                About about=(About)PluginServices.getExtension(About.class);
83
                FPanelAbout panelAbout=about.getAboutPanel();
84
                java.net.URL aboutURL = this.getClass().getResource(
85
                "/about.htm");
86
                panelAbout.addAboutUrl(PluginServices.getText(this,"annotations"),aboutURL);
87

    
88
        }
89

    
90
        /**
91
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
92
     */
93
    public void execute(String actionCommand) {
94
        if ("ANNOTATIONLAYER".equals(actionCommand)) {
95
            ImageIcon Logo = new javax.swing.ImageIcon(this.getClass()
96
                                                           .getClassLoader()
97
                                                           .getResource("images/package_graphics.png"));
98

    
99
            SimpleWizard wizard = new SimpleWizard(Logo);
100

    
101
            FLyrVect lv = (FLyrVect) map.getLayers().getActives()[0];
102
            Annotation_Layer la = new Annotation_Layer();
103
            la.setSource(lv.getSource());
104
            la.setProjection(lv.getProjection());
105
            la.setName(lv.getName());
106

    
107
            Annotation_FieldSelect panel1 = new Annotation_FieldSelect(wizard.getWizardComponents(),
108
                    la);
109
            Annotation_ConfigureLabel panel2 = new Annotation_ConfigureLabel(wizard.getWizardComponents(),
110
                    la);
111

    
112
            wizard.getWizardComponents().addWizardPanel(panel1);
113
            wizard.getWizardComponents().addWizardPanel(panel2);
114

    
115
            wizard.getWizardComponents().setFinishAction(new Annotation_Create(
116
                    wizard.getWizardComponents(), map, la));
117

    
118
            wizard.getWindowInfo().setWidth(540);
119
            wizard.getWindowInfo().setHeight(380);
120
            wizard.getWindowInfo().setTitle(PluginServices.getText(this,
121
                    "to_annotation"));
122

    
123
            PluginServices.getMDIManager().addWindow(wizard);
124

    
125
            /*
126
            FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
127
            FLyrAnnotation la=new FLyrAnnotation();
128
            la.setSource(lv.getSource());
129

130
                    MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
131
            PluginServices.getMDIManager().addView(mfta);
132

133
            if (mfta.isOk()){
134
                map.getLayers().addLayer(la);
135
                map.getLayers().removeLayer(lv);
136
            }
137
            */
138
        }
139
    }
140

    
141
    /**
142
     * @see com.iver.andami.plugins.IExtension#isEnabled()
143
     */
144
    public boolean isEnabled() {
145
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
146

    
147
        if ((v != null) &&
148
                v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
149
            com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) v;
150
            IProjectView model = vista.getModel();
151
            map = model.getMapContext();
152

    
153
            FLayer[] layers = map.getLayers().getActives();
154

    
155
            if (layers.length == 1) {
156
                if (layers[0].isAvailable() && layers[0] instanceof FLyrVect) {
157
                    FLyrVect lv = (FLyrVect) layers[0];
158

    
159
                    //                                    ReadableVectorial src = lv.getSource();
160
                    try {
161
                        //                                                if (src == null || src.getShapeType()==FShape.POLYGON || src.getShapeType()==FShape.LINE)
162
                        //                                                        return false;
163
                        SelectableDataSource sds = lv.getSource().getRecordset();
164

    
165
                        if (sds.getFieldCount() > 0) {
166
                            return true;
167
                        }
168
                    } catch (DriverException e) {
169
                        return false;
170
                    }
171
                }
172
            }
173
        }
174

    
175
        return false;
176
    }
177

    
178
    /**
179
     * @see com.iver.andami.plugins.IExtension#isVisible()
180
     */
181
    public boolean isVisible() {
182
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
183

    
184
        if (v == null) {
185
            return false;
186
        } else if (v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
187
            return true;
188
        } else {
189
            return false;
190
        }
191
    }
192
}