Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / com / iver / cit / gvsig / AutoCompletePolygonExtension.java @ 27221

History | View | Annotate | Download (2.12 KB)

1
package com.iver.cit.gvsig;
2

    
3
import org.gvsig.fmap.dal.exception.ReadException;
4
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
5
import org.gvsig.fmap.mapcontrol.MapControl;
6

    
7
import com.iver.andami.PluginServices;
8
import com.iver.andami.messages.NotificationManager;
9
import com.iver.andami.plugins.Extension;
10
import com.iver.cit.gvsig.gui.cad.tools.AutoCompletePolygon;
11
import com.iver.cit.gvsig.project.documents.view.gui.View;
12

    
13
public class AutoCompletePolygonExtension extends Extension {
14
        private View view;
15

    
16
        private MapControl mapControl;
17

    
18
        private AutoCompletePolygon theTool;
19

    
20
        public void initialize() {
21
                theTool = new AutoCompletePolygon();
22
                CADExtension.addCADTool("_autocompletepolygon", theTool);
23
                registerIcons();
24
        }
25
        private void registerIcons(){
26
                PluginServices.getIconTheme().registerDefault(
27
                                "edition-geometry-autocompletepolygon",
28
                                this.getClass().getClassLoader().getResource("images/polygon_autocomplete.png")
29
                        );
30

    
31
        }
32
        public void execute(String actionCommand) {
33
                CADExtension.initFocus();
34
                if (actionCommand.equals("AUTOCOMPLETE_POLYGON")) {
35
                        CADExtension.setCADTool("_autocompletepolygon", true);
36
                        CADExtension.getEditionManager().setMapControl(mapControl);
37
                }
38
                CADExtension.getCADToolAdapter().configureMenu();
39

    
40
        }
41

    
42
        public boolean isEnabled() {
43
                try {
44
                        if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
45
                                view = (View) PluginServices.getMDIManager().getActiveWindow();
46
                                mapControl = view.getMapControl();
47
                                if (CADExtension.getEditionManager().getActiveLayerEdited() == null)
48
                                        return false;
49
                                FLyrVect lv = (FLyrVect) CADExtension.getEditionManager()
50
                                                .getActiveLayerEdited().getLayer();
51
                                if (theTool.isApplicable(lv.getShapeType())) {
52
                                        return true;
53
                                }
54
                        }
55
                } catch (ReadException e) {
56
                        NotificationManager.addError(e.getMessage(), e);
57
                }
58
                return false;
59
        }
60

    
61
        public boolean isVisible() {
62
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
63
                        return true;
64
                return false;
65
        }
66

    
67
}