Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / AutoCompletePolygonExtension.java @ 38560

History | View | Annotate | Download (2.15 KB)

1 29616 jpiera
package org.gvsig.editing;
2 27221 vcaballero
3 29616 jpiera
import org.gvsig.andami.PluginServices;
4
import org.gvsig.andami.messages.NotificationManager;
5
import org.gvsig.andami.plugins.Extension;
6 31496 jjdelcerro
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
7 29616 jpiera
import org.gvsig.editing.gui.cad.tools.AutoCompletePolygon;
8 27221 vcaballero
import org.gvsig.fmap.dal.exception.ReadException;
9
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
10
import org.gvsig.fmap.mapcontrol.MapControl;
11
12
13
public class AutoCompletePolygonExtension extends Extension {
14 31496 jjdelcerro
        private DefaultViewPanel view;
15 27221 vcaballero
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 31496 jjdelcerro
                                view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
46 27221 vcaballero
                                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
}