Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.app / org.gvsig.raster.wmts.app.wmtsclient / src / main / java / org / gvsig / raster / wmts / app / wmtsclient / WMTSClientExtension.java @ 1174

History | View | Annotate | Download (5.79 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
 
23
package org.gvsig.raster.wmts.app.wmtsclient;
24

    
25
import java.awt.Component;
26
import java.awt.geom.Point2D;
27

    
28
import javax.swing.JOptionPane;
29

    
30
import org.gvsig.about.AboutManager;
31
import org.gvsig.about.AboutParticipant;
32
import org.gvsig.andami.IconThemeHelper;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.plugins.Extension;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.app.ApplicationLocator;
37
import org.gvsig.app.ApplicationManager;
38
import org.gvsig.app.extension.AddLayer;
39
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
40
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
41
import org.gvsig.fmap.geom.primitive.Envelope;
42
import org.gvsig.fmap.mapcontext.ViewPort;
43
import org.gvsig.fmap.mapcontext.layers.FLayer;
44
import org.gvsig.fmap.mapcontext.layers.FLayers;
45
import org.gvsig.fmap.mapcontrol.MapControl;
46
import org.gvsig.raster.fmap.layers.Multiresolution;
47
import org.gvsig.raster.wmts.app.wmtsclient.gui.toc.WMTSPropsTocMenuEntry;
48
import org.gvsig.raster.wmts.app.wmtsclient.gui.wizard.WMTSWizard;
49
import org.gvsig.raster.wmts.app.wmtsclient.layer.DynObjectSetWMTSInfo;
50
import org.gvsig.raster.wmts.app.wmtsclient.layer.FLyrWMTS;
51
import org.gvsig.tools.ToolsLocator;
52
import org.gvsig.tools.extensionpoint.ExtensionPoint;
53

    
54

    
55
/**
56
 * Extension for adding WMTS support to gvSIG.
57
 *
58
 * @author Nacho Brodin (nachobrodin@gmail.com)
59
 */
60
public class WMTSClientExtension extends Extension {
61
        
62
        /*
63
         * (non-Javadoc)
64
         * @see org.gvsig.andami.plugins.IExtension#initialize()
65
         */
66
    public void initialize() {
67
            // Adds an entry to the TOC's floating menu to those layers defined in this extension
68
                ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("View_TocActions");
69
                exPoint.append("WMTSPropsTocMenuEntry", "", new WMTSPropsTocMenuEntry());
70

    
71
        // Adds a new tab to the "add layer" wizard for WMTS layer creation
72
            AddLayer.addWizard(WMTSWizard.class);
73

    
74
            //ToolsLocator.getExtensionPointManager().add("CatalogLayers").append("OGC:WMTS", "", FLyrWMTS.class);
75
            initilizeIcons();
76
            DynObjectSetWMTSInfo.registerDynClass();
77
    }
78
    
79
    /*
80
         * (non-Javadoc)
81
         * @see org.gvsig.andami.plugins.Extension#postInitialize()
82
         */
83
        public void postInitialize() {
84
                FLyrWMTS.registerPersistent();
85
                addAboutInfo();
86
        }
87
        
88
        private void addAboutInfo() {
89
        ApplicationManager application = ApplicationLocator.getManager();
90
        
91
        AboutManager about = application.getAbout();
92
        about.addDeveloper("PRODEVELOP", getClass().getClassLoader()
93
            .getResource("about/wmts-about.html"), 2);
94

    
95
        AboutParticipant participant = about.getDeveloper("PRODEVELOP");
96
        participant.addContribution(
97
            "WMTS",
98
            "Cliente para Web Map Tile Service", 
99
            2011,3,1, 
100
            2011,3,30
101
        );      
102
    }
103

    
104
    @SuppressWarnings("deprecation")
105
        public void execute(String actionCommand) {
106
            AbstractViewPanel theView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
107
                MapControl mapCtrl = theView.getMapControl();
108
                ViewPort viewPort = mapCtrl.getViewPort();
109
                
110
                Multiresolution lyrMultires = null;
111
                
112
                FLayers lyrs = mapCtrl.getMapContext().getLayers();
113
                for (int i = 0; i < lyrs.getLayersCount(); i++) {
114
                        FLayer lyr = lyrs.getLayer(i);
115
                        if(lyr instanceof FLyrWMTS) {
116
                                lyrMultires = ((Multiresolution)lyr);
117
                        }
118
                }
119
                
120
            if(actionCommand.compareTo("NEXT_LEVEL") == 0) {
121
                    if(!lyrMultires.increaseZoomLevel()) {
122
                            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "max_zoom_reached");
123
                            return;
124
                    }
125
            }
126
            
127
            if(actionCommand.compareTo("PREV_LEVEL") == 0) {
128
                    if(!lyrMultires.decreaseZoomLevel()) {
129
                            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), "min_zoom_reached");
130
                            return;
131
                    }
132
            }
133
            
134
            Point2D center = new Point2D.Double(viewPort.getExtent().getCenterX(), viewPort.getExtent().getCenterY());
135
                Envelope r;
136
                try {
137
                        r = lyrMultires.getCoordsInLevel(center, lyrMultires.getZoomLevel(), 
138
                                        viewPort.getImageWidth(), viewPort.getImageHeight());
139
                } catch (CreateEnvelopeException e) {
140
                        return;
141
                }
142
                
143
                mapCtrl.getViewPort().setEnvelope(r);
144
                mapCtrl.invalidate();
145
    }
146

    
147
    public boolean isEnabled() {
148
        return true;
149
    }
150

    
151
    public boolean isVisible() {
152
            IWindow window = PluginServices.getMDIManager().getActiveWindow();
153
            if(window instanceof AbstractViewPanel) {
154
                    AbstractViewPanel theView = (AbstractViewPanel) window;
155
                    MapControl mapCtrl = theView.getMapControl();
156
                    FLayers lyrs = mapCtrl.getMapContext().getLayers();
157
                    for (int i = 0; i < lyrs.getLayersCount(); i++) {
158
                            if(lyrs.getLayer(i) instanceof FLyrWMTS)
159
                                    return true;
160
                    }
161
            }
162
        return false;
163
    }
164

    
165

    
166
    void initilizeIcons(){
167
                IconThemeHelper.registerIcon(null, "level-plus", this);
168
                IconThemeHelper.registerIcon(null, "level-less", this);
169
                IconThemeHelper.registerIcon(null, "icon-layer-wms", this);
170
    }
171
}