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

History | View | Annotate | Download (7.15 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.andami.PluginServices;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.app.project.documents.view.toc.ITocItem;
32
import org.gvsig.fmap.dal.coverage.RasterLibrary;
33
import org.gvsig.fmap.mapcontext.layers.FLayer;
34
import org.gvsig.raster.cache.tile.TileCache;
35
import org.gvsig.raster.cache.tile.TileCacheLibrary;
36
import org.gvsig.raster.cache.tile.TileCacheLocator;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.extensionpoint.ExtensionPoint;
39
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
40

    
41

    
42
/**
43
 * Tile cache extension for gvSIG
44
 * 
45
 * @author Nacho Brodin (nachobrodin@gmail.com)
46
 */
47
public class CacheExtension extends Extension implements ConfigurationListener {
48

    
49
        /*
50
         * (non-Javadoc)
51
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
52
         */
53
        public void execute(String actionCommand) {
54
                
55
        }
56

    
57
        /*
58
         * (non-Javadoc)
59
         * @see com.iver.andami.plugins.IExtension#initialize()
60
         */
61
        public void initialize() {
62
                PluginServices.getIconTheme().registerDefault(
63
                                "pref-tilecache-icon",
64
                                this.getClass().getClassLoader().getResource("images/tilecache-pref.jpeg")
65
                        );
66
                
67
                Configuration.addValueChangedListener(this);
68
                Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
69
                prefs.put("DataFolder", System.getProperty("user.home"));
70
                
71
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
72
                ExtensionPoint point = extensionPoints.add("AplicationPreferences");
73
                point.append("TileCachePreferences", "", TileCachePreferences.class);
74
                
75
                TileCacheLibrary.DEFAULT_TILEWIDTH = Configuration.getValue("tilesize", Integer.valueOf(TileCacheLibrary.DEFAULT_TILEWIDTH));
76
                TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
77
        }
78
        
79
        /*
80
         * (non-Javadoc)
81
         * @see com.iver.andami.plugins.IExtension#isEnabled()
82
         */
83
        public boolean isEnabled() {
84
                return false;
85
        }
86

    
87
        public boolean isVisible() {
88
                return false;
89
        }
90

    
91
        /*
92
         * (non-Javadoc)
93
         * @see org.gvsig.raster.util.ConfigurationListener#actionConfigurationChanged(org.gvsig.raster.util.ConfigurationEvent)
94
         */
95
        public void actionConfigurationChanged(ConfigurationEvent e) {
96

    
97
                if (e.getKey().equals("path_tilecache")) {
98
                        if(e.getValue() instanceof String) {
99
                                String value = (String)e.getValue();
100
                                if(value != null && value.compareTo("") != 0) {
101
                                        RasterLibrary.pathTileCache =  (String)e.getValue();
102
                                        TileCache tc = TileCacheLocator.getManager().getTileCache(RasterLibrary.pathTileCache);
103
                                        tc.updateBaseDirectory(RasterLibrary.pathTileCache);
104
                                }
105
                        }
106
                        return;
107
                }
108
                
109
                if (e.getKey().equals("tile_levels")) {
110
                        if(e.getValue() instanceof String)
111
                                try {
112
                                        TileCacheLibrary.DEFAULT_LEVELS = new Integer((String) e
113
                                                        .getValue()).intValue();
114
                                } catch (NumberFormatException exc) {
115
                                        //Valor por defecto en la cache
116
                                }
117
                        if(e.getValue() instanceof Integer)
118
                                TileCacheLibrary.DEFAULT_LEVELS = ((Integer) e.getValue()).intValue();
119
                        return;
120
                }
121
                
122
                if (e.getKey().equals("tilesize")) {
123
                        if(e.getValue() instanceof String) {
124
                                try {
125
                                        String text = (String) e.getValue();
126
                                        text = text.replaceAll("\\.", "");
127
                                        text = text.replaceAll(",", "\\.");
128
                                        TileCacheLibrary.DEFAULT_TILEWIDTH = new Integer(text).intValue();
129
                                        TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
130
                                } catch (NumberFormatException exc) {
131
                                        //Valor por defecto en la cache
132
                                }
133
                        }
134
                        if(e.getValue() instanceof Integer) {
135
                                TileCacheLibrary.DEFAULT_TILEWIDTH = ((Integer) e.getValue()).intValue();
136
                                TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH;
137
                        }
138
                        return;
139
                }
140
                
141
                if (e.getKey().equals("tilecache_size")) {
142
                        if(e.getValue() instanceof String)
143
                                try {
144
                                        String text = (String) e.getValue();
145
                                        text = text.replaceAll("\\.", "");
146
                                        text = text.replaceAll(",", "\\.");
147
                                        TileCacheLibrary.MAX_CACHE_SIZE = new Integer((String) e
148
                                                        .getValue()).intValue();
149
                                } catch (NumberFormatException exc) {
150
                                        //Valor por defecto en la cache
151
                                }
152
                        if(e.getValue() instanceof Integer)
153
                                TileCacheLibrary.MAX_CACHE_SIZE = ((Integer) e.getValue()).intValue();
154
                        return;
155
                }
156
                
157
                if (e.getKey().equals("cache_struct")) {
158
                        if(e.getValue() instanceof String)
159
                                TileCacheLibrary.DEFAULT_STRUCTURE = (String)e.getValue();
160
                        return;
161
                }
162
        }
163

    
164
        /*
165
         * (non-Javadoc)
166
         * @see org.gvsig.raster.gui.IGenericToolBarMenuItem#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
167
         */
168
        public void execute(ITocItem item, FLayer[] selectedItems) {
169

    
170
        }
171

    
172
        public void postInitialize() {
173
                super.postInitialize();
174
//                storeLibrary.postInitialize();
175
        }
176
        
177
        /**
178
         * Shows an error dialog with a text and a accept button 
179
         * @param msg Message to show in the dialog
180
         * @param parentWindow Parent window
181
         */
182
        public static void messageBoxError(String msg, Object parentWindow){
183
                String string = PluginServices.getText(parentWindow, "accept");
184
                Object[] options = {string};
185
                JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
186
                                        "<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>",
187
                                        PluginServices.getText(parentWindow, "confirmacion"),
188
                                        JOptionPane.OK_OPTION,
189
                                        JOptionPane.ERROR_MESSAGE,
190
                                        null,
191
                                        options,
192
                                        string);
193
        }
194
        
195
        /**
196
         * Shows an error dialog with a text and a YesOrNot button 
197
         * @param msg Message to show in the dialog.
198
         * @param parentWindow Parent window
199
         * @return Selected button by the button. Returns true if the user has selected Yes
200
         * and false if he has selected No. 
201
         */
202
        public static boolean messageBoxYesOrNot(String msg, Object parentWindow){
203
                String string1 = PluginServices.getText(parentWindow, "yes");
204
                String string2 = PluginServices.getText(parentWindow, "no");
205
                Object[] options = {string1, string2};
206
                int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
207
                                        "<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>",
208
                                        PluginServices.getText(parentWindow, "confirmacion"),
209
                                        JOptionPane.YES_NO_OPTION,
210
                                        JOptionPane.QUESTION_MESSAGE,
211
                                        null,
212
                                        options,
213
                                        string1);
214
                if (n == JOptionPane.YES_OPTION)
215
                        return true;
216
                else
217
                        return false;
218
        }
219
}