svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / style / RemoteFileStyle.java @ 40560
History | View | Annotate | Download (3.95 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style; |
25 |
|
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.Rectangle; |
28 |
import java.io.File; |
29 |
import java.io.IOException; |
30 |
import java.net.URL; |
31 |
|
32 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
34 |
import org.gvsig.remoteclient.utils.Utilities; |
35 |
import org.gvsig.tools.ToolsLocator; |
36 |
import org.gvsig.tools.dynobject.DynStruct; |
37 |
import org.gvsig.tools.persistence.PersistenceManager; |
38 |
import org.gvsig.tools.persistence.PersistentState; |
39 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
40 |
import org.gvsig.tools.util.Callable; |
41 |
|
42 |
/**
|
43 |
*
|
44 |
* RemoteFileStyle.java
|
45 |
*
|
46 |
*
|
47 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Feb 13, 2008
|
48 |
*
|
49 |
*/
|
50 |
public class RemoteFileStyle extends BackgroundFileStyle { |
51 |
public static final String REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME = "RemoteFileStyle"; |
52 |
private static final String SOURCE = "source"; |
53 |
|
54 |
private BackgroundFileStyle bgStyle;
|
55 |
|
56 |
@Override
|
57 |
public Rectangle getBounds() { |
58 |
return bgStyle.getBounds();
|
59 |
} |
60 |
|
61 |
@Override
|
62 |
public void setSource(URL url) throws IOException { |
63 |
File f = Utilities.downloadFile(url, "remote_picture_symbol_style", null); |
64 |
source = url; |
65 |
bgStyle = BackgroundFileStyle.createStyleByURL(f.toURI().toURL()); |
66 |
} |
67 |
|
68 |
public void drawInsideRectangle(Graphics2D g, Rectangle r, boolean keepAspectRatio) throws SymbolDrawingException { |
69 |
bgStyle.drawInsideRectangle(g, r, keepAspectRatio); |
70 |
} |
71 |
|
72 |
public void drawOutline(Graphics2D g, Rectangle r) throws SymbolDrawingException { |
73 |
bgStyle.drawOutline(g, r); |
74 |
} |
75 |
|
76 |
public boolean isSuitableFor(ISymbol symbol) { |
77 |
return bgStyle.isSuitableFor(symbol);
|
78 |
} |
79 |
|
80 |
public String getClassName() { |
81 |
return getClass().getName();
|
82 |
} |
83 |
|
84 |
public void loadFromState(PersistentState state) |
85 |
throws PersistenceException {
|
86 |
try {
|
87 |
setSource(state.getURL(SOURCE)); |
88 |
} catch (Exception e) { |
89 |
throw new PersistenceCantSetSourceException(e); |
90 |
} |
91 |
} |
92 |
|
93 |
public void saveToState(PersistentState state) throws PersistenceException { |
94 |
state.set(SOURCE, source); |
95 |
} |
96 |
|
97 |
public static class RegisterPersistence implements Callable { |
98 |
|
99 |
public Object call() throws Exception { |
100 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
101 |
if( manager.getDefinition(REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME)==null ) { |
102 |
DynStruct definition = manager.addDefinition( |
103 |
RemoteFileStyle.class, |
104 |
REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME, |
105 |
REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
106 |
null,
|
107 |
null
|
108 |
); |
109 |
|
110 |
// Extend the Style base definition
|
111 |
definition.extend(manager.getDefinition(BACKGROUND_FILE_STYLE_PERSISTENCE_DEFINITION_NAME)); |
112 |
|
113 |
definition.addDynFieldURL(SOURCE); |
114 |
} |
115 |
return Boolean.TRUE; |
116 |
} |
117 |
} |
118 |
} |