Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / InsertPolygonExtension.java @ 38539

History | View | Annotate | Download (4.95 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 org.gvsig.editing;
42

    
43
import org.gvsig.andami.PluginServices;
44
import org.gvsig.andami.messages.NotificationManager;
45
import org.gvsig.andami.plugins.Extension;
46
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
47
import org.gvsig.editing.gui.cad.tools.CircleCADTool;
48
import org.gvsig.editing.gui.cad.tools.EditVertexCADTool;
49
import org.gvsig.editing.gui.cad.tools.EllipseCADTool;
50
import org.gvsig.editing.gui.cad.tools.PolygonCADTool;
51
import org.gvsig.editing.gui.cad.tools.RectangleCADTool;
52
import org.gvsig.fmap.dal.exception.ReadException;
53
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
54
import org.gvsig.fmap.mapcontrol.MapControl;
55

    
56

    
57
/**
58
 * Extensi?n que gestiona la inserci?n de poligonos en edici?n.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class InsertPolygonExtension extends Extension {
63
        private DefaultViewPanel view;
64

    
65
        private MapControl mapControl;
66
        private PolygonCADTool polygon;
67

    
68
        /**
69
         * @see org.gvsig.andami.plugins.IExtension#initialize()
70
         */
71
        public void initialize() {
72
                polygon = new PolygonCADTool();
73
                CircleCADTool circle=new CircleCADTool();
74
        RectangleCADTool rectangle=new RectangleCADTool();
75
        EllipseCADTool ellipse=new EllipseCADTool();
76
        EditVertexCADTool editvertex=new EditVertexCADTool();
77
                CADExtension.addCADTool("_polygon", polygon);
78
                CADExtension.addCADTool("_circle",circle);
79
            CADExtension.addCADTool("_rectangle", rectangle);
80
            CADExtension.addCADTool("_ellipse", ellipse);
81
            CADExtension.addCADTool("_editvertex",editvertex);
82

    
83
            registerIcons();
84
        }
85

    
86
        private void registerIcons(){
87
                PluginServices.getIconTheme().registerDefault(
88
                                "edition-insert-geometry-poligon",
89
                                this.getClass().getClassLoader().getResource("images/Poligon.png")
90
                        );
91

    
92
                PluginServices.getIconTheme().registerDefault(
93
                                "edition-insert-geometry-rectangle",
94
                                this.getClass().getClassLoader().getResource("images/Rectangle.png")
95
                        );
96

    
97
                PluginServices.getIconTheme().registerDefault(
98
                                "edition-insert-geometry-circle",
99
                                this.getClass().getClassLoader().getResource("images/Circle.png")
100
                        );
101

    
102
                PluginServices.getIconTheme().registerDefault(
103
                                "edition-insert-geometry-ellipse",
104
                                this.getClass().getClassLoader().getResource("images/Ellipse.png")
105
                        );
106

    
107
                PluginServices.getIconTheme().registerDefault(
108
                                "edition-geometry-edit-vertex",
109
                                this.getClass().getClassLoader().getResource("images/EditVertex.png")
110
                        );
111
        }
112

    
113
        /**
114
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
115
         */
116
        public void execute(String s) {
117
                CADExtension.initFocus();
118
                if (s.equals("_polygon")||
119
                                s.equals("_circle")||
120
                                s.equals("_ellipse")||
121
                                s.equals("_rectangle")||
122
                                s.equals("_editvertex")) {
123
                CADExtension.setCADTool(s,true);
124
        }
125
                CADExtension.getEditionManager().setMapControl(mapControl);
126
                CADExtension.getCADToolAdapter().configureMenu();
127
        }
128

    
129
        /**
130
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
131
         */
132
        public boolean isEnabled() {
133

    
134
                try {
135
                        if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
136
                                view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
137
                                mapControl = view.getMapControl();
138
                                if (CADExtension.getEditionManager().getActiveLayerEdited()==null)
139
                                        return false;
140
                                FLyrVect lv=(FLyrVect)CADExtension.getEditionManager().getActiveLayerEdited().getLayer();
141
                                if (polygon.isApplicable(lv.getShapeType())){
142
                                        return true;
143
                                }
144
                        }
145
                } catch (ReadException e) {
146
                        NotificationManager.addError(e.getMessage(),e);
147
                }
148
                return false;
149
        }
150

    
151
        /**
152
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
153
         */
154
        public boolean isVisible() {
155
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
156
                        return true;
157
                return false;
158
        }
159
}