svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / styles / BackgroundFileStyle.java @ 27789
History | View | Annotate | Download (4.51 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.styles; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Rectangle; |
46 |
import java.io.File; |
47 |
import java.io.IOException; |
48 |
import java.net.MalformedURLException; |
49 |
import java.net.URL; |
50 |
import org.apache.log4j.Logger; |
51 |
|
52 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
53 |
import com.iver.cit.gvsig.fmap.core.styles.AbstractStyle; |
54 |
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException; |
55 |
import com.iver.utiles.XMLEntity; |
56 |
|
57 |
/**
|
58 |
* Defines methods that allows the user to create an style based in a
|
59 |
* background file.For this reason, BackgroundFileStyle will
|
60 |
* have a parameter that will be an string in order to specify this source file.
|
61 |
*
|
62 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
63 |
*/
|
64 |
public abstract class BackgroundFileStyle extends AbstractStyle { |
65 |
|
66 |
public static BackgroundFileStyle createStyleByURL(URL url) throws IOException { |
67 |
BackgroundFileStyle bgImage; |
68 |
String l = url.toString().toLowerCase();
|
69 |
if (l.startsWith("http://") || |
70 |
l.startsWith("https://")) {
|
71 |
bgImage = new RemoteFileStyle();
|
72 |
} else if (l.toLowerCase().endsWith(".svg")) { |
73 |
bgImage = new SVGStyle();
|
74 |
} else {
|
75 |
bgImage = new ImageStyle();
|
76 |
} |
77 |
bgImage.setSource(url); |
78 |
return bgImage;
|
79 |
} |
80 |
protected URL sourceFile; |
81 |
protected boolean isRelativePath; |
82 |
/**
|
83 |
* Sets the file that is used as a source to create the Background
|
84 |
* @param f, File
|
85 |
* @throws IOException
|
86 |
*/
|
87 |
public abstract void setSource(URL url) throws IOException; |
88 |
/**
|
89 |
* Gets the bounding <code>Rectangle</code> of this <code>Rectangle</code>.
|
90 |
* <p>
|
91 |
* This method is included for completeness, to parallel the
|
92 |
* <code>getBounds</code> method of
|
93 |
* {@link Component}.
|
94 |
* @return a new <code>Rectangle</code>, equal to the
|
95 |
* bounding <code>Rectangle</code> for this <code>Rectangle</code>.
|
96 |
* @see java.awt.Component#getBounds
|
97 |
* @see #setBounds(Rectangle)
|
98 |
* @see #setBounds(int, int, int, int)
|
99 |
* @since JDK1.1
|
100 |
*/
|
101 |
public abstract Rectangle getBounds(); |
102 |
|
103 |
public XMLEntity getXMLEntity() {
|
104 |
|
105 |
XMLEntity xml = new XMLEntity();
|
106 |
String source=sourceFile.toString();
|
107 |
|
108 |
// if(isRelativePath)
|
109 |
// source=sourceFile.toString().substring(SymbologyFactory.SymbolLibraryPath.length()+1);
|
110 |
|
111 |
xml.putProperty("className", getClassName());
|
112 |
xml.putProperty("source", source);
|
113 |
xml.putProperty("desc", getDescription());
|
114 |
return xml;
|
115 |
} |
116 |
|
117 |
public void setXMLEntity(XMLEntity xml) { |
118 |
String strSource = xml.getStringProperty("source"); |
119 |
URL source = null; |
120 |
try {
|
121 |
try {
|
122 |
source = new URL(strSource); |
123 |
} catch (MalformedURLException e) { |
124 |
File fileSource = new File(SymbologyFactory.StyleLibraryPath + File.separator + strSource); |
125 |
source = fileSource.toURL(); |
126 |
} |
127 |
setSource(source); |
128 |
setDescription(xml.getStringProperty("desc"));
|
129 |
} catch (IOException ioEx) { |
130 |
Logger.getLogger(this.getClass()).error("Can't load image '"+strSource+"'"); |
131 |
} |
132 |
|
133 |
} |
134 |
/**
|
135 |
* Obtains the source of the file which is used to create the background
|
136 |
* @return
|
137 |
*/
|
138 |
public final URL getSource() { |
139 |
return sourceFile;
|
140 |
} |
141 |
|
142 |
public final void drawInsideRectangle(Graphics2D g, Rectangle r) throws SymbolDrawingException { |
143 |
drawInsideRectangle(g, r, true);
|
144 |
} |
145 |
|
146 |
public abstract void drawInsideRectangle(Graphics2D g, Rectangle r, boolean keepAspectRatio) throws SymbolDrawingException ; |
147 |
} |