svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / styles / ImageStyle.java @ 19509
History | View | Annotate | Download (3.26 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 com.iver.cit.gvsig.fmap.core.styles; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Rectangle; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.io.File; |
48 |
import java.io.IOException; |
49 |
|
50 |
import javax.imageio.ImageIO; |
51 |
|
52 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
53 |
import com.iver.utiles.XMLEntity; |
54 |
|
55 |
/**
|
56 |
* Controls the style of an image to be correctly painted. This class controls
|
57 |
* aspects like the source path of the image, creates a rectangle to paint inside
|
58 |
* the image, draws the outline of the image and so on.
|
59 |
*
|
60 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
61 |
*/
|
62 |
public class ImageStyle extends BackgroundFileStyle { |
63 |
private BufferedImage img; |
64 |
/**
|
65 |
* Creates a rectangle with the dimensions of the buffered image
|
66 |
* @return Rectangle
|
67 |
*/
|
68 |
public Rectangle getBounds() { |
69 |
return new Rectangle(new Dimension(img.getWidth(), img.getHeight())); |
70 |
} |
71 |
/**
|
72 |
* Defines the source (file) from where the buffered image will be taken.
|
73 |
* @param f,File
|
74 |
*/
|
75 |
public void setSource(File f) throws IOException { |
76 |
sourceFile = f.getAbsolutePath(); |
77 |
img = ImageIO.read(f);
|
78 |
} |
79 |
|
80 |
public void drawInsideRectangle(Graphics2D g, Rectangle r) { |
81 |
g.setClip(r); |
82 |
g.drawRenderedImage(img, null);
|
83 |
} |
84 |
|
85 |
public boolean isSuitableFor(ISymbol symbol) { |
86 |
// TODO Implement it
|
87 |
throw new Error("Not yet implemented!"); |
88 |
|
89 |
} |
90 |
|
91 |
public void drawOutline(Graphics2D g, Rectangle r) { |
92 |
drawInsideRectangle(g, r); |
93 |
} |
94 |
|
95 |
public String getClassName() { |
96 |
return getClass().getName();
|
97 |
} |
98 |
|
99 |
public XMLEntity getXMLEntity() {
|
100 |
XMLEntity xml = new XMLEntity();
|
101 |
xml.putProperty("className", getClassName());
|
102 |
xml.putProperty("source", getSource());
|
103 |
xml.putProperty("desc", getDescription());
|
104 |
return xml;
|
105 |
} |
106 |
|
107 |
public void setXMLEntity(XMLEntity xml) { |
108 |
try {
|
109 |
setSource(new File(xml.getStringProperty("source"))); |
110 |
setDescription(xml.getStringProperty("desc"));
|
111 |
} catch (IOException e) { |
112 |
// TODO Auto-generated catch block
|
113 |
e.printStackTrace(); |
114 |
} |
115 |
} |
116 |
} |