Statistics
| Revision:

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

History | View | Annotate | Download (4.95 KB)

1 4551 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 29616 jpiera
package org.gvsig.editing;
42 4551 caballero
43 29616 jpiera
import org.gvsig.andami.PluginServices;
44
import org.gvsig.andami.messages.NotificationManager;
45
import org.gvsig.andami.plugins.Extension;
46 31496 jjdelcerro
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
47 29616 jpiera
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 24500 jmvivo
import org.gvsig.fmap.dal.exception.ReadException;
53 21666 vcaballero
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
54
import org.gvsig.fmap.mapcontrol.MapControl;
55
56 4551 caballero
57
/**
58
 * Extensi?n que gestiona la inserci?n de poligonos en edici?n.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62 5005 jorpiell
public class InsertPolygonExtension extends Extension {
63 31496 jjdelcerro
        private DefaultViewPanel view;
64 4551 caballero
65
        private MapControl mapControl;
66 5170 caballero
        private PolygonCADTool polygon;
67 4551 caballero
68
        /**
69 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#initialize()
70 4551 caballero
         */
71 5005 jorpiell
        public void initialize() {
72 5170 caballero
                polygon = new PolygonCADTool();
73 4551 caballero
                CircleCADTool circle=new CircleCADTool();
74
        RectangleCADTool rectangle=new RectangleCADTool();
75
        EllipseCADTool ellipse=new EllipseCADTool();
76 4950 caballero
        EditVertexCADTool editvertex=new EditVertexCADTool();
77 5016 caballero
                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 21666 vcaballero
83 14810 jmvivo
            registerIcons();
84 4551 caballero
        }
85 21666 vcaballero
86 14810 jmvivo
        private void registerIcons(){
87 15637 jmvivo
                PluginServices.getIconTheme().registerDefault(
88 14810 jmvivo
                                "edition-insert-geometry-poligon",
89
                                this.getClass().getClassLoader().getResource("images/Poligon.png")
90
                        );
91 21666 vcaballero
92 15637 jmvivo
                PluginServices.getIconTheme().registerDefault(
93 14810 jmvivo
                                "edition-insert-geometry-rectangle",
94
                                this.getClass().getClassLoader().getResource("images/Rectangle.png")
95
                        );
96 21666 vcaballero
97 15637 jmvivo
                PluginServices.getIconTheme().registerDefault(
98 14810 jmvivo
                                "edition-insert-geometry-circle",
99
                                this.getClass().getClassLoader().getResource("images/Circle.png")
100
                        );
101 21666 vcaballero
102 15637 jmvivo
                PluginServices.getIconTheme().registerDefault(
103 14810 jmvivo
                                "edition-insert-geometry-ellipse",
104
                                this.getClass().getClassLoader().getResource("images/Ellipse.png")
105 21666 vcaballero
                        );
106
107 15637 jmvivo
                PluginServices.getIconTheme().registerDefault(
108 14810 jmvivo
                                "edition-geometry-edit-vertex",
109
                                this.getClass().getClassLoader().getResource("images/EditVertex.png")
110 21666 vcaballero
                        );
111 14810 jmvivo
        }
112 4551 caballero
113
        /**
114 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
115 4551 caballero
         */
116
        public void execute(String s) {
117 4899 caballero
                CADExtension.initFocus();
118 5016 caballero
                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 4551 caballero
        }
125
                CADExtension.getEditionManager().setMapControl(mapControl);
126
                CADExtension.getCADToolAdapter().configureMenu();
127
        }
128
129
        /**
130 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
131 4551 caballero
         */
132
        public boolean isEnabled() {
133
134
                try {
135
                        if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
136 31496 jjdelcerro
                                view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
137 6604 caballero
                                mapControl = view.getMapControl();
138 5526 caballero
                                if (CADExtension.getEditionManager().getActiveLayerEdited()==null)
139
                                        return false;
140 5170 caballero
                                FLyrVect lv=(FLyrVect)CADExtension.getEditionManager().getActiveLayerEdited().getLayer();
141
                                if (polygon.isApplicable(lv.getShapeType())){
142 4551 caballero
                                        return true;
143
                                }
144
                        }
145 21666 vcaballero
                } catch (ReadException e) {
146 12739 caballero
                        NotificationManager.addError(e.getMessage(),e);
147 4551 caballero
                }
148
                return false;
149
        }
150
151
        /**
152 29616 jpiera
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
153 4551 caballero
         */
154
        public boolean isVisible() {
155 4583 caballero
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
156 4551 caballero
                        return true;
157 6604 caballero
                return false;
158 4551 caballero
        }
159
}