Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / Annotation_Extension.java @ 11589

History | View | Annotate | Download (7.67 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
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
62
import com.iver.cit.gvsig.project.documents.view.toc.actions.FLyrVectEditPropertiesTocMenuEntry;
63
import com.iver.cit.gvsig.project.documents.view.toc.gui.FLyrVectEditPropertiesTocMenuEntry2;
64
import com.iver.utiles.extensionPoints.ExtensionPoint;
65
import com.iver.utiles.extensionPoints.ExtensionPoints;
66
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
67

    
68

    
69
/**
70
 * Extension to create an annotation layer.
71
 *
72
 * @author Vicente Caballero Navarro
73
 */
74
public class Annotation_Extension extends Extension {
75
    private MapContext map = null;
76

    
77
    /**
78
     * @see com.iver.andami.plugins.IExtension#initialize()
79
     */
80
    public void initialize() {
81
            ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
82

    
83
            AbstractTocContextMenuAction ma=(AbstractTocContextMenuAction)((ExtensionPoint) extensionPoints.get("View_TocActions")).get("FLyrVectEditProperties");
84
            ((ExtensionPoint) extensionPoints.get("View_TocActions")).remove("FLyrVectEditProperties");
85
            ((ExtensionPoint) extensionPoints.get("View_TocActions")).put("FLyrVectEditProperties",new FLyrVectEditPropertiesTocMenuEntry2(ma));
86
        //extensionPoints.add("View_TocActions","FLyrVectEditProperties2",new FLyrVectEditPropertiesTocMenuEntry2());
87
        System.out.println("A?ado WizardAnnotation.");
88
        AddLayer.addWizard(Annotation_Open.class);
89
    }
90

    
91
    public void postInitialize() {
92
                // TODO Auto-generated method stub
93
                super.postInitialize();
94
                About about=(About)PluginServices.getExtension(About.class);
95
                FPanelAbout panelAbout=about.getAboutPanel();
96
                java.net.URL aboutURL = this.getClass().getResource(
97
                "/about.htm");
98
                panelAbout.addAboutUrl(PluginServices.getText(this,"annotations"),aboutURL);
99

    
100
        }
101

    
102
        /**
103
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
104
     */
105
    public void execute(String actionCommand) {
106
        if ("ANNOTATIONLAYER".equals(actionCommand)) {
107
            ImageIcon Logo = new javax.swing.ImageIcon(this.getClass()
108
                                                           .getClassLoader()
109
                                                           .getResource("images/package_graphics.png"));
110

    
111
            SimpleWizard wizard = new SimpleWizard(Logo);
112

    
113
            FLyrVect lv = (FLyrVect) map.getLayers().getActives()[0];
114
            Annotation_Layer la = new Annotation_Layer();
115
            la.setSource(lv.getSource());
116
            la.setProjection(lv.getProjection());
117
            la.setName(lv.getName());
118

    
119
            Annotation_FieldSelect panel1 = new Annotation_FieldSelect(wizard.getWizardComponents(),
120
                    la);
121
            Annotation_ConfigureLabel panel2 = new Annotation_ConfigureLabel(wizard.getWizardComponents(),
122
                    la);
123

    
124
            wizard.getWizardComponents().addWizardPanel(panel1);
125
            wizard.getWizardComponents().addWizardPanel(panel2);
126

    
127
            wizard.getWizardComponents().setFinishAction(new Annotation_Create(
128
                    wizard.getWizardComponents(), map, la));
129

    
130
            wizard.getWindowInfo().setWidth(540);
131
            wizard.getWindowInfo().setHeight(380);
132
            wizard.getWindowInfo().setTitle(PluginServices.getText(this,
133
                    "to_annotation"));
134

    
135
            PluginServices.getMDIManager().addWindow(wizard);
136

    
137
            /*
138
            FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
139
            FLyrAnnotation la=new FLyrAnnotation();
140
            la.setSource(lv.getSource());
141

142
                    MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
143
            PluginServices.getMDIManager().addView(mfta);
144

145
            if (mfta.isOk()){
146
                map.getLayers().addLayer(la);
147
                map.getLayers().removeLayer(lv);
148
            }
149
            */
150
        }
151
    }
152

    
153
    /**
154
     * @see com.iver.andami.plugins.IExtension#isEnabled()
155
     */
156
    public boolean isEnabled() {
157
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
158

    
159
        if ((v != null) &&
160
                v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
161
            com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) v;
162
            IProjectView model = vista.getModel();
163
            map = model.getMapContext();
164

    
165
            FLayer[] layers = map.getLayers().getActives();
166

    
167
            if (layers.length == 1) {
168
                if (layers[0].isAvailable() && layers[0] instanceof FLyrVect) {
169
                    FLyrVect lv = (FLyrVect) layers[0];
170

    
171
                    //                                    ReadableVectorial src = lv.getSource();
172
                    try {
173
                        //                                                if (src == null || src.getShapeType()==FShape.POLYGON || src.getShapeType()==FShape.LINE)
174
                        //                                                        return false;
175
                        SelectableDataSource sds = lv.getSource().getRecordset();
176

    
177
                        if (sds.getFieldCount() > 0) {
178
                            return true;
179
                        }
180
                    } catch (DriverException e) {
181
                        return false;
182
                    }
183
                }
184
            }
185
        }
186

    
187
        return false;
188
    }
189

    
190
    /**
191
     * @see com.iver.andami.plugins.IExtension#isVisible()
192
     */
193
    public boolean isVisible() {
194
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
195

    
196
        if (v == null) {
197
            return false;
198
        } else if (v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
199
            return true;
200
        } else {
201
            return false;
202
        }
203
    }
204
}