Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / InsertPolygonExtension.java @ 40557

History | View | Annotate | Download (4.63 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.editing;
25

    
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
31
import org.gvsig.editing.gui.cad.tools.CircleCADTool;
32
import org.gvsig.editing.gui.cad.tools.EditVertexCADTool;
33
import org.gvsig.editing.gui.cad.tools.EllipseCADTool;
34
import org.gvsig.editing.gui.cad.tools.PolygonCADTool;
35
import org.gvsig.editing.gui.cad.tools.RectangleCADTool;
36
import org.gvsig.fmap.dal.exception.ReadException;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.fmap.mapcontrol.MapControl;
39

    
40

    
41
/**
42
 * Extensi?n que gestiona la inserci?n de poligonos en edici?n.
43
 *
44
 * @author Vicente Caballero Navarro
45
 */
46
public class InsertPolygonExtension extends Extension {
47
        private DefaultViewPanel view;
48

    
49
        private MapControl mapControl;
50
        private PolygonCADTool polygon;
51

    
52
        /**
53
         * @see org.gvsig.andami.plugins.IExtension#initialize()
54
         */
55
        public void initialize() {
56
                polygon = new PolygonCADTool();
57
                CircleCADTool circle=new CircleCADTool();
58
        RectangleCADTool rectangle=new RectangleCADTool();
59
        EllipseCADTool ellipse=new EllipseCADTool();
60
        EditVertexCADTool editvertex=new EditVertexCADTool();
61
                CADExtension.addCADTool("_polygon", polygon);
62
                CADExtension.addCADTool("_circle",circle);
63
            CADExtension.addCADTool("_rectangle", rectangle);
64
            CADExtension.addCADTool("_ellipse", ellipse);
65
            CADExtension.addCADTool("_editvertex",editvertex);
66

    
67
            registerIcons();
68
        }
69

    
70
        private void registerIcons(){
71
                IconThemeHelper.registerIcon("action", "layer-modify-edit-vertex", this);
72
                IconThemeHelper.registerIcon("action", "layer-insert-ellipse", this);
73
                IconThemeHelper.registerIcon("action", "layer-insert-circle", this);
74
                IconThemeHelper.registerIcon("action", "layer-insert-rectangle", this);
75
                IconThemeHelper.registerIcon("action", "layer-insert-polygon", this);
76
        }
77

    
78
        /**
79
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
80
         */
81
        public void execute(String s) {
82
                CADExtension.initFocus();
83
                if ("layer-modify-edit-vertex".equalsIgnoreCase(s)) {
84
                        CADExtension.setCADTool("_editvertex",true);
85
                        
86
                } else if ("layer-insert-ellipse".equalsIgnoreCase(s)) {
87
                        CADExtension.setCADTool("_ellipse",true);
88
                
89
                } else if ("layer-insert-circle".equalsIgnoreCase(s)) {
90
                        CADExtension.setCADTool("_circle",true);
91
                
92
                } else if ("layer-insert-rectangle".equalsIgnoreCase(s)) {
93
                        CADExtension.setCADTool("_rectangle",true);
94
                
95
                } else if ("layer-insert-polygon".equalsIgnoreCase(s)) {
96
                        CADExtension.setCADTool("_polygon",true);
97
            
98
                }
99
                CADExtension.getEditionManager().setMapControl(mapControl);
100
                CADExtension.getCADToolAdapter().configureMenu();
101
        }
102

    
103
        /**
104
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
105
         */
106
        public boolean isEnabled() {
107

    
108
                try {
109
                        if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
110
                                view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
111
                                mapControl = view.getMapControl();
112
                                if (CADExtension.getEditionManager().getActiveLayerEdited()==null)
113
                                        return false;
114
                                FLyrVect lv=(FLyrVect)CADExtension.getEditionManager().getActiveLayerEdited().getLayer();
115
                                if (polygon.isApplicable(lv.getShapeType())){
116
                                        return true;
117
                                }
118
                        }
119
                } catch (ReadException e) {
120
                        NotificationManager.addError(e.getMessage(),e);
121
                }
122
                return false;
123
        }
124

    
125
        /**
126
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
127
         */
128
        public boolean isVisible() {
129
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
130
                        return true;
131
                return false;
132
        }
133
}