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 @ 9532
History | View | Annotate | Download (8.16 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 |
public void execute(String actionCommand) { |
55 |
|
56 |
} |
57 |
|
58 |
// private void addAboutInfo() {
|
59 |
// ApplicationManager application = ApplicationLocator.getManager();
|
60 |
//
|
61 |
// AboutManager about = application.getAbout();
|
62 |
// about.addDeveloper("PRODEVELOP", getClass().getClassLoader()
|
63 |
// .getResource("about/tilecache-about.html"), 2);
|
64 |
//
|
65 |
// AboutParticipant participant = about.getDeveloper("PRODEVELOP");
|
66 |
// participant.addContribution(
|
67 |
// "Cach? de teselas",
|
68 |
// "Cach? de teselas para fuentes de datos r?ster y remotas",
|
69 |
// 2011,1,1,
|
70 |
// 2011,1,30
|
71 |
// );
|
72 |
// }
|
73 |
|
74 |
public void initialize() { |
75 |
IconThemeHelper.registerIcon(null, "pref-tilecache-icon", this); |
76 |
|
77 |
Configuration.addValueChangedListener(this); |
78 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
79 |
prefs.put("DataFolder", System.getProperty("user.home")); |
80 |
|
81 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
82 |
ExtensionPoint point = extensionPoints.add("AplicationPreferences");
|
83 |
point.append("TileCachePreferences", "", TileCachePreferences.class); |
84 |
|
85 |
TileCacheLibrary.DEFAULT_TILEWIDTH = Configuration.getValue("tilesize", Integer.valueOf(TileCacheLibrary.DEFAULT_TILEWIDTH)); |
86 |
TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH; |
87 |
|
88 |
TileCacheLibrary.ALTERNATIVE_TILESIZE = Configuration.getValue("tilesizewms", Integer.valueOf(TileCacheLibrary.ALTERNATIVE_TILESIZE)); |
89 |
|
90 |
ApplicationManager appGvSigMan = ApplicationLocator.getManager(); |
91 |
appGvSigMan.registerPrepareOpenLayer(new PrepareLayerAskUsingTiles());
|
92 |
appGvSigMan.registerPrepareOpenDataStoreParameters(new PrepareLayerAskUsingTiles());
|
93 |
} |
94 |
|
95 |
public boolean isEnabled() { |
96 |
return false; |
97 |
} |
98 |
|
99 |
public boolean isVisible() { |
100 |
return false; |
101 |
} |
102 |
|
103 |
public void actionConfigurationChanged(ConfigurationEvent e) { |
104 |
|
105 |
if (e.getKey().equals("path_tilecache")) { |
106 |
if(e.getValue() instanceof String) { |
107 |
String value = (String)e.getValue(); |
108 |
if(value != null && value.compareTo("") != 0) { |
109 |
RasterLibrary.pathTileCache = (String)e.getValue();
|
110 |
TileCache tc = TileCacheLocator.getManager().getTileCache(RasterLibrary.pathTileCache); |
111 |
tc.updateBaseDirectory(RasterLibrary.pathTileCache); |
112 |
} |
113 |
} |
114 |
return;
|
115 |
} |
116 |
|
117 |
if (e.getKey().equals("tile_levels")) { |
118 |
if(e.getValue() instanceof String) |
119 |
try {
|
120 |
TileCacheLibrary.DEFAULT_LEVELS = new Integer((String) e |
121 |
.getValue()).intValue(); |
122 |
} catch (NumberFormatException exc) { |
123 |
//Valor por defecto en la cache
|
124 |
} |
125 |
if(e.getValue() instanceof Integer) |
126 |
TileCacheLibrary.DEFAULT_LEVELS = ((Integer) e.getValue()).intValue();
|
127 |
return;
|
128 |
} |
129 |
|
130 |
if (e.getKey().equals("tilesize")) { |
131 |
if(e.getValue() instanceof String) { |
132 |
try {
|
133 |
String text = (String) e.getValue(); |
134 |
text = text.replaceAll("\\.", ""); |
135 |
text = text.replaceAll(",", "\\."); |
136 |
TileCacheLibrary.DEFAULT_TILEWIDTH = new Integer(text).intValue(); |
137 |
TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH; |
138 |
} catch (NumberFormatException exc) { |
139 |
//Valor por defecto en la cache
|
140 |
} |
141 |
} |
142 |
if(e.getValue() instanceof Integer) { |
143 |
TileCacheLibrary.DEFAULT_TILEWIDTH = ((Integer) e.getValue()).intValue();
|
144 |
TileCacheLibrary.DEFAULT_TILEHEIGHT = TileCacheLibrary.DEFAULT_TILEWIDTH; |
145 |
} |
146 |
return;
|
147 |
} |
148 |
|
149 |
if (e.getKey().equals("tilesizewms")) { |
150 |
if(e.getValue() instanceof String) { |
151 |
try {
|
152 |
String text = (String) e.getValue(); |
153 |
text = text.replaceAll("\\.", ""); |
154 |
text = text.replaceAll(",", "\\."); |
155 |
TileCacheLibrary.ALTERNATIVE_TILESIZE = new Integer(text).intValue(); |
156 |
} catch (NumberFormatException exc) { |
157 |
//Valor por defecto en la cache
|
158 |
} |
159 |
} |
160 |
if(e.getValue() instanceof Integer) { |
161 |
TileCacheLibrary.ALTERNATIVE_TILESIZE = ((Integer) e.getValue()).intValue();
|
162 |
} |
163 |
return;
|
164 |
} |
165 |
|
166 |
if (e.getKey().equals("tilecache_size")) { |
167 |
if(e.getValue() instanceof String) |
168 |
try {
|
169 |
String text = (String) e.getValue(); |
170 |
text = text.replaceAll("\\.", ""); |
171 |
text = text.replaceAll(",", "\\."); |
172 |
TileCacheLibrary.MAX_CACHE_SIZE = new Integer((String) e |
173 |
.getValue()).intValue(); |
174 |
} catch (NumberFormatException exc) { |
175 |
//Valor por defecto en la cache
|
176 |
} |
177 |
if(e.getValue() instanceof Integer) |
178 |
TileCacheLibrary.MAX_CACHE_SIZE = ((Integer) e.getValue()).intValue();
|
179 |
return;
|
180 |
} |
181 |
|
182 |
if (e.getKey().equals("cache_struct")) { |
183 |
if(e.getValue() instanceof String) |
184 |
TileCacheLibrary.DEFAULT_STRUCTURE = (String)e.getValue();
|
185 |
return;
|
186 |
} |
187 |
} |
188 |
|
189 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
190 |
|
191 |
} |
192 |
|
193 |
public void postInitialize() { |
194 |
super.postInitialize();
|
195 |
// storeLibrary.postInitialize();
|
196 |
// addAboutInfo();
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Shows an error dialog with a text and a accept button
|
201 |
* @param msg Message to show in the dialog
|
202 |
* @param parentWindow Parent window
|
203 |
*/
|
204 |
public static void messageBoxError(String msg, Object parentWindow){ |
205 |
String string = PluginServices.getText(parentWindow, "accept"); |
206 |
Object[] options = {string}; |
207 |
JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
208 |
"<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>", |
209 |
PluginServices.getText(parentWindow, "confirmacion"),
|
210 |
JOptionPane.OK_OPTION,
|
211 |
JOptionPane.ERROR_MESSAGE,
|
212 |
null,
|
213 |
options, |
214 |
string); |
215 |
} |
216 |
|
217 |
/**
|
218 |
* Shows an error dialog with a text and a YesOrNot button
|
219 |
* @param msg Message to show in the dialog.
|
220 |
* @param parentWindow Parent window
|
221 |
* @return Selected button by the button. Returns true if the user has selected Yes
|
222 |
* and false if he has selected No.
|
223 |
*/
|
224 |
public static boolean messageBoxYesOrNot(String msg, Object parentWindow){ |
225 |
String string1 = PluginServices.getText(parentWindow, "yes"); |
226 |
String string2 = PluginServices.getText(parentWindow, "no"); |
227 |
Object[] options = {string1, string2}; |
228 |
int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
229 |
"<html>" + PluginServices.getText(parentWindow, msg).replaceAll("\n", "<br>") + "</html>", |
230 |
PluginServices.getText(parentWindow, "confirmacion"),
|
231 |
JOptionPane.YES_NO_OPTION,
|
232 |
JOptionPane.QUESTION_MESSAGE,
|
233 |
null,
|
234 |
options, |
235 |
string1); |
236 |
if (n == JOptionPane.YES_OPTION) |
237 |
return true; |
238 |
else
|
239 |
return false; |
240 |
} |
241 |
} |