root / branches / v2_0_0_prep / libraries / 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 @ 34294
History | View | Annotate | Download (4.2 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.Rectangle; |
45 |
import java.io.File; |
46 |
import java.io.IOException; |
47 |
import java.net.URL; |
48 |
|
49 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
50 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
51 |
import org.gvsig.remoteclient.utils.Utilities; |
52 |
import org.gvsig.tools.ToolsLocator; |
53 |
import org.gvsig.tools.dynobject.DynStruct; |
54 |
import org.gvsig.tools.persistence.PersistenceManager; |
55 |
import org.gvsig.tools.persistence.PersistentState; |
56 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
57 |
import org.gvsig.tools.util.Callable; |
58 |
|
59 |
/**
|
60 |
*
|
61 |
* RemoteFileStyle.java
|
62 |
*
|
63 |
*
|
64 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Feb 13, 2008
|
65 |
*
|
66 |
*/
|
67 |
public class RemoteFileStyle extends BackgroundFileStyle { |
68 |
public static final String REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME = "RemoteFileStyle"; |
69 |
private static final String SOURCE = "source"; |
70 |
|
71 |
private BackgroundFileStyle bgStyle;
|
72 |
|
73 |
@Override
|
74 |
public Rectangle getBounds() { |
75 |
return bgStyle.getBounds();
|
76 |
} |
77 |
|
78 |
@Override
|
79 |
public void setSource(URL url) throws IOException { |
80 |
File f = Utilities.downloadFile(url, "remote_picture_symbol_style", null); |
81 |
source = url; |
82 |
bgStyle = BackgroundFileStyle.createStyleByURL(f.toURI().toURL()); |
83 |
} |
84 |
|
85 |
public void drawInsideRectangle(Graphics2D g, Rectangle r, boolean keepAspectRatio) throws SymbolDrawingException { |
86 |
bgStyle.drawInsideRectangle(g, r, keepAspectRatio); |
87 |
} |
88 |
|
89 |
public void drawOutline(Graphics2D g, Rectangle r) throws SymbolDrawingException { |
90 |
bgStyle.drawOutline(g, r); |
91 |
} |
92 |
|
93 |
public boolean isSuitableFor(ISymbol symbol) { |
94 |
return bgStyle.isSuitableFor(symbol);
|
95 |
} |
96 |
|
97 |
public String getClassName() { |
98 |
return getClass().getName();
|
99 |
} |
100 |
|
101 |
public void loadFromState(PersistentState state) |
102 |
throws PersistenceException {
|
103 |
try {
|
104 |
setSource(state.getURL(SOURCE)); |
105 |
} catch (Exception e) { |
106 |
throw new PersistenceCantSetSourceException(e); |
107 |
} |
108 |
} |
109 |
|
110 |
public void saveToState(PersistentState state) throws PersistenceException { |
111 |
state.set(SOURCE, source); |
112 |
} |
113 |
|
114 |
public static class RegisterPersistence implements Callable { |
115 |
|
116 |
public Object call() throws Exception { |
117 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
118 |
if( manager.getDefinition(REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME)==null ) { |
119 |
DynStruct definition = manager.addDefinition( |
120 |
RemoteFileStyle.class, |
121 |
REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME, |
122 |
REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
123 |
null,
|
124 |
null
|
125 |
); |
126 |
|
127 |
// Extend the Style base definition
|
128 |
definition.extend(manager.getDefinition(BACKGROUND_FILE_STYLE_PERSISTENCE_DEFINITION_NAME)); |
129 |
|
130 |
definition.addDynFieldURL(SOURCE); |
131 |
} |
132 |
return Boolean.TRUE; |
133 |
} |
134 |
} |
135 |
} |