Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tilecache / trunk / org.gvsig.raster.tilecache / org.gvsig.raster.tilecache.app / src / main / java / org / gvsig / raster / tilecache / app / CacheExtension.java @ 1174

History | View | Annotate | Download (8.49 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.raster.tilecache.app;
23

    
24
import java.awt.Component;
25
import java.util.prefs.Preferences;
26

    
27
import javax.swing.JOptionPane;
28

    
29
import org.gvsig.about.AboutManager;
30
import org.gvsig.about.AboutParticipant;
31
import org.gvsig.andami.IconThemeHelper;
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.plugins.Extension;
34
import org.gvsig.app.ApplicationLocator;
35
import org.gvsig.app.ApplicationManager;
36
import org.gvsig.app.project.documents.view.toc.ITocItem;
37
import org.gvsig.fmap.dal.coverage.RasterLibrary;
38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.raster.cache.tile.TileCache;
40
import org.gvsig.raster.cache.tile.TileCacheLibrary;
41
import org.gvsig.raster.cache.tile.TileCacheLocator;
42
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.extensionpoint.ExtensionPoint;
44
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
45

    
46

    
47
/**
48
 * Tile cache extension for gvSIG
49
 * 
50
 * @author Nacho Brodin (nachobrodin@gmail.com)
51
 */
52
public class CacheExtension extends Extension implements ConfigurationListener {
53

    
54
        /*
55
         * (non-Javadoc)
56
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
57
         */
58
        public void execute(String actionCommand) {
59
                
60
        }
61

    
62
        private void addAboutInfo() {
63
        ApplicationManager application = ApplicationLocator.getManager();
64
        
65
        AboutManager about = application.getAbout();
66
        about.addDeveloper("PRODEVELOP", getClass().getClassLoader()
67
            .getResource("about/tilecache-about.html"), 2);
68

    
69
        AboutParticipant participant = about.getDeveloper("PRODEVELOP");
70
        participant.addContribution(
71
            "Cach? de teselas",
72
            "Cach? de teselas para fuentes de datos r?ster y remotas", 
73
            2011,1,1, 
74
            2011,1,30
75
        );      
76
    }
77

    
78
        /*
79
         * (non-Javadoc)
80
         * @see com.iver.andami.plugins.IExtension#initialize()
81
         */
82
        public void initialize() {
83
                IconThemeHelper.registerIcon(null, "pref-tilecache-icon", this);
84
                
85
                Configuration.addValueChangedListener(this);
86
                Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
87
                prefs.put("DataFolder", System.getProperty("user.home"));
88
                
89
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
90
                ExtensionPoint point = extensionPoints.add("AplicationPreferences");
91
                point.append("TileCachePreferences", "", TileCachePreferences.class);
92
                
93
                TileCacheLibrary.DEFAULT_TILEWIDTH = Configuration.getValue("tilesize", Integer.valueOf(TileCacheLibrary.DEFAULT_TILEWIDTH));
94
                TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
95
                
96
                TileCacheLibrary.ALTERNATIVE_TILESIZE = Configuration.getValue("tilesizewms", Integer.valueOf(TileCacheLibrary.ALTERNATIVE_TILESIZE));
97
        }
98
        
99
        /*
100
         * (non-Javadoc)
101
         * @see com.iver.andami.plugins.IExtension#isEnabled()
102
         */
103
        public boolean isEnabled() {
104
                return false;
105
        }
106

    
107
        public boolean isVisible() {
108
                return false;
109
        }
110

    
111
        /*
112
         * (non-Javadoc)
113
         * @see org.gvsig.raster.util.ConfigurationListener#actionConfigurationChanged(org.gvsig.raster.util.ConfigurationEvent)
114
         */
115
        public void actionConfigurationChanged(ConfigurationEvent e) {
116

    
117
                if (e.getKey().equals("path_tilecache")) {
118
                        if(e.getValue() instanceof String) {
119
                                String value = (String)e.getValue();
120
                                if(value != null && value.compareTo("") != 0) {
121
                                        RasterLibrary.pathTileCache =  (String)e.getValue();
122
                                        TileCache tc = TileCacheLocator.getManager().getTileCache(RasterLibrary.pathTileCache);
123
                                        tc.updateBaseDirectory(RasterLibrary.pathTileCache);
124
                                }
125
                        }
126
                        return;
127
                }
128
                
129
                if (e.getKey().equals("tile_levels")) {
130
                        if(e.getValue() instanceof String)
131
                                try {
132
                                        TileCacheLibrary.DEFAULT_LEVELS = new Integer((String) e
133
                                                        .getValue()).intValue();
134
                                } catch (NumberFormatException exc) {
135
                                        //Valor por defecto en la cache
136
                                }
137
                        if(e.getValue() instanceof Integer)
138
                                TileCacheLibrary.DEFAULT_LEVELS = ((Integer) e.getValue()).intValue();
139
                        return;
140
                }
141
                
142
                if (e.getKey().equals("tilesize")) {
143
                        if(e.getValue() instanceof String) {
144
                                try {
145
                                        String text = (String) e.getValue();
146
                                        text = text.replaceAll("\\.", "");
147
                                        text = text.replaceAll(",", "\\.");
148
                                        TileCacheLibrary.DEFAULT_TILEWIDTH = new Integer(text).intValue();
149
                                        TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
150
                                } catch (NumberFormatException exc) {
151
                                        //Valor por defecto en la cache
152
                                }
153
                        }
154
                        if(e.getValue() instanceof Integer) {
155
                                TileCacheLibrary.DEFAULT_TILEWIDTH = ((Integer) e.getValue()).intValue();
156
                                TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
157
                        }
158
                        return;
159
                }
160
                
161
                if (e.getKey().equals("tilesizewms")) {
162
                        if(e.getValue() instanceof String) {
163
                                try {
164
                                        String text = (String) e.getValue();
165
                                        text = text.replaceAll("\\.", "");
166
                                        text = text.replaceAll(",", "\\.");
167
                                        TileCacheLibrary.ALTERNATIVE_TILESIZE = new Integer(text).intValue();
168
                                } catch (NumberFormatException exc) {
169
                                        //Valor por defecto en la cache
170
                                }
171
                        }
172
                        if(e.getValue() instanceof Integer) {
173
                                TileCacheLibrary.ALTERNATIVE_TILESIZE = ((Integer) e.getValue()).intValue();
174
                        }
175
                        return;
176
                }
177
                
178
                if (e.getKey().equals("tilecache_size")) {
179
                        if(e.getValue() instanceof String)
180
                                try {
181
                                        String text = (String) e.getValue();
182
                                        text = text.replaceAll("\\.", "");
183
                                        text = text.replaceAll(",", "\\.");
184
                                        TileCacheLibrary.MAX_CACHE_SIZE = new Integer((String) e
185
                                                        .getValue()).intValue();
186
                                } catch (NumberFormatException exc) {
187
                                        //Valor por defecto en la cache
188
                                }
189
                        if(e.getValue() instanceof Integer)
190
                                TileCacheLibrary.MAX_CACHE_SIZE = ((Integer) e.getValue()).intValue();
191
                        return;
192
                }
193
                
194
                if (e.getKey().equals("cache_struct")) {
195
                        if(e.getValue() instanceof String)
196
                                TileCacheLibrary.DEFAULT_STRUCTURE = (String)e.getValue();
197
                        return;
198
                }
199
        }
200

    
201
        /*
202
         * (non-Javadoc)
203
         * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
204
         */
205
        public void execute(ITocItem item, FLayer[] selectedItems) {
206

    
207
        }
208

    
209
        public void postInitialize() {
210
                super.postInitialize();
211
        //                storeLibrary.postInitialize();
212
                addAboutInfo();
213
        }
214
        
215
        /**
216
         * Shows an error dialog with a text and a accept button 
217
         * @param msg Message to show in the dialog
218
         * @param parentWindow Parent window
219
         */
220
        public static void messageBoxError(String msg, Object parentWindow){
221
                String string = PluginServices.getText(parentWindow, "accept");
222
                Object[] options = {string};
223
                JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
224
                                        "<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>",
225
                                        PluginServices.getText(parentWindow, "confirmacion"),
226
                                        JOptionPane.OK_OPTION,
227
                                        JOptionPane.ERROR_MESSAGE,
228
                                        null,
229
                                        options,
230
                                        string);
231
        }
232
        
233
        /**
234
         * Shows an error dialog with a text and a YesOrNot button 
235
         * @param msg Message to show in the dialog.
236
         * @param parentWindow Parent window
237
         * @return Selected button by the button. Returns true if the user has selected Yes
238
         * and false if he has selected No. 
239
         */
240
        public static boolean messageBoxYesOrNot(String msg, Object parentWindow){
241
                String string1 = PluginServices.getText(parentWindow, "yes");
242
                String string2 = PluginServices.getText(parentWindow, "no");
243
                Object[] options = {string1, string2};
244
                int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
245
                                        "<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>",
246
                                        PluginServices.getText(parentWindow, "confirmacion"),
247
                                        JOptionPane.YES_NO_OPTION,
248
                                        JOptionPane.QUESTION_MESSAGE,
249
                                        null,
250
                                        options,
251
                                        string1);
252
                if (n == JOptionPane.YES_OPTION)
253
                        return true;
254
                else
255
                        return false;
256
        }
257
}