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 @ 142

History | View | Annotate | Download (3.72 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
 * ThematicMap Measure tool extension
39
 * 
40
 * @author gvSIG Team
41
 * @version $Id$
42
 * 
43
 */
44
public class ThematicMapMeasureToolsExtension extends Extension implements
45
    MapControlToolRegistrant {
46

    
47
    public void initialize() {
48
        // Nothing to do
49

    
50
    }
51

    
52
    @Override
53
    public void postInitialize() {
54

    
55
        // Register tools
56
        ThematicMapSwingLocator.getSwingManager().addMapControlRegistrant(this);
57
    }
58

    
59
    public boolean isEnabled() {
60
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
61

    
62
        if (window instanceof ThematicMapDocumentViewer) {
63
            ThematicMapDocumentViewer viewer =
64
                (ThematicMapDocumentViewer) window;
65

    
66
            FLayers layers =
67
                viewer.getThematicMap().getMapContext().getLayers();
68

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

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

    
83
    public void registerTools(MapControl mapControl) {
84
        // Medir
85

    
86
        MeasureListener mli = new MeasureListener(mapControl);
87
        mapControl.addBehavior("medicion", new PolylineBehavior(mli));
88

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

    
93
    }
94

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