Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCAD / src / com / iver / cit / gvsig / EquidistanceExtension.java @ 22932

History | View | Annotate | Download (3.65 KB)

1 8934 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
package com.iver.cit.gvsig;
42
43 21911 jmvivo
import org.gvsig.fmap.data.ReadException;
44 21666 vcaballero
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
45
import org.gvsig.fmap.mapcontrol.MapControl;
46
47 8934 caballero
import com.iver.andami.PluginServices;
48 12739 caballero
import com.iver.andami.messages.NotificationManager;
49 8934 caballero
import com.iver.andami.plugins.Extension;
50
import com.iver.cit.gvsig.gui.cad.tools.EquidistanceCADTool;
51
import com.iver.cit.gvsig.project.documents.view.gui.View;
52
53
/**
54
 * Extensi?n para crear una geometr?a equidistante a otra.
55
 *
56
 * @author Vicente Caballero Navarro
57
 */
58
public class EquidistanceExtension extends Extension {
59
        private View view;
60
61
        private MapControl mapControl;
62
        private EquidistanceCADTool equidistanceCADTool;
63
64
        /**
65
         * @see com.iver.andami.plugins.IExtension#initialize()
66
         */
67
        public void initialize() {
68
                equidistanceCADTool=new EquidistanceCADTool();
69
                CADExtension.addCADTool("_equidistance",equidistanceCADTool);
70 21666 vcaballero
71 14810 jmvivo
                registerIcons();
72 8934 caballero
        }
73
74 14810 jmvivo
        private void registerIcons(){
75 15637 jmvivo
                PluginServices.getIconTheme().registerDefault(
76 14810 jmvivo
                                "edition-geometry-equidistance",
77
                                this.getClass().getClassLoader().getResource("images/Equidistance.png")
78
                        );
79
        }
80 21666 vcaballero
81 8934 caballero
        /**
82
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
83
         */
84
        public void execute(String s) {
85
                CADExtension.initFocus();
86
                if (s.equals("_equidistance")) {
87
                CADExtension.setCADTool(s,true);
88
        }
89
                CADExtension.getEditionManager().setMapControl(mapControl);
90
                CADExtension.getCADToolAdapter().configureMenu();
91
        }
92
93
        /**
94
         * @see com.iver.andami.plugins.IExtension#isEnabled()
95
         */
96
        public boolean isEnabled() {
97
98
                try {
99
                        if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
100
                                view = (View) PluginServices.getMDIManager().getActiveWindow();
101
                                mapControl = view.getMapControl();
102
                                EditionManager em=CADExtension.getEditionManager();
103 9377 jmvivo
                                if (em.getActiveLayerEdited()==null)
104
                                        return false;
105 8934 caballero
                                FLyrVect lv=(FLyrVect)em.getActiveLayerEdited().getLayer();
106 10626 caballero
107 9377 jmvivo
                                if (lv.getRecordset().getSelection().cardinality()!=1)
108 8934 caballero
                                        return false;
109
                                if (equidistanceCADTool.isApplicable(lv.getShapeType())){
110
                                        return true;
111
                                }
112
                        }
113 21666 vcaballero
                } catch (ReadException e) {
114 12739 caballero
                        NotificationManager.addError(e.getMessage(),e);
115 8934 caballero
                }
116
                return false;
117
        }
118
119
        /**
120
         * @see com.iver.andami.plugins.IExtension#isVisible()
121
         */
122
        public boolean isVisible() {
123
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
124
                        return true;
125
                return false;
126
        }
127
}