Statistics
| Revision:

root / org.gvsig.educa.thematicmap.app / trunk / org.gvsig.educa.thematicmap.app / org.gvsig.educa.thematicmap.app.viewer / src / main / java / org / gvsig / educa / thematicmap / app / viewer / ThematicMapMeasureToolsExtension.java @ 141

History | View | Annotate | Download (3.67 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.educa.thematicmap.app.viewer;
23

    
24
import org.gvsig.andami.PluginServices;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.andami.ui.mdiManager.IWindow;
27
import org.gvsig.app.project.documents.view.toolListeners.AreaListener;
28
import org.gvsig.app.project.documents.view.toolListeners.MeasureListener;
29
import org.gvsig.educa.thematicmap.app.viewer.ui.ThematicMapDocumentViewer;
30
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingLocator;
31
import org.gvsig.educa.thematicmap.swing.viewer.MapControlToolRegistrant;
32
import org.gvsig.fmap.mapcontext.layers.FLayers;
33
import org.gvsig.fmap.mapcontrol.MapControl;
34
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolygonBehavior;
35
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior;
36

    
37
/**
38
 * @author gvSIG Team
39
 * @version $Id$
40
 * 
41
 */
42
public class ThematicMapMeasureToolsExtension extends Extension implements
43
    MapControlToolRegistrant {
44

    
45
    public void initialize() {
46
        // Nothing to do
47

    
48
    }
49

    
50
    @Override
51
    public void postInitialize() {
52

    
53
        // Register tools
54
        ThematicMapSwingLocator.getSwingManager().addMapControlRegistrant(this);
55
    }
56

    
57
    public boolean isEnabled() {
58
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
59

    
60
        if (window instanceof ThematicMapDocumentViewer) {
61
            ThematicMapDocumentViewer viewer =
62
                (ThematicMapDocumentViewer) window;
63

    
64
            FLayers layers =
65
                viewer.getThematicMap().getMapContext().getLayers();
66

    
67
            for (int i = 0; i < layers.getLayersCount(); i++) {
68
                if (layers.getLayer(i).isAvailable()) {
69
                    return true;
70
                }
71
            }
72
        }
73
        return false;
74
    }
75

    
76
    public boolean isVisible() {
77
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
78
        return window instanceof ThematicMapDocumentViewer;
79
    }
80

    
81
    public void registerTools(MapControl mapControl) {
82
        // Medir
83

    
84
        MeasureListener mli = new MeasureListener(mapControl);
85
        mapControl.addBehavior("medicion", new PolylineBehavior(mli));
86

    
87
        // Area
88
        AreaListener ali = new AreaListener(mapControl);
89
        mapControl.addBehavior("area", new PolygonBehavior(ali));
90

    
91
    }
92

    
93
    public void execute(String actionCommand) {
94
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
95
        if (!(window instanceof ThematicMapDocumentViewer)) {
96
            return;
97
        }
98
        ThematicMapDocumentViewer tmDocViewer =
99
            (ThematicMapDocumentViewer) window;
100
        MapControl mapCtrl = tmDocViewer.getViewer().getMapControl();
101
        if (actionCommand.equals("MEDICION")) {
102
            mapCtrl.setTool("medicion");
103
        }
104
        if (actionCommand.equals("AREA")) {
105
            mapCtrl.setTool("area");
106
        }
107
    }
108
}