svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFramePicture.java @ 1822
History | View | Annotate | Download (7.09 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout.fframes; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
import com.iver.andami.messages.NotificationManager; |
49 |
|
50 |
import com.iver.cit.gvsig.fmap.DriverException; |
51 |
import com.iver.cit.gvsig.gui.layout.Layout; |
52 |
|
53 |
import com.iver.utiles.XMLEntity; |
54 |
|
55 |
import com.sun.jimi.core.Jimi; |
56 |
|
57 |
import java.awt.Graphics2D; |
58 |
import java.awt.Image; |
59 |
import java.awt.geom.AffineTransform; |
60 |
import java.awt.geom.Rectangle2D; |
61 |
import java.awt.image.BufferedImage; |
62 |
|
63 |
import javax.swing.ImageIcon; |
64 |
|
65 |
|
66 |
/**
|
67 |
* FFrame para introducir una imagen en el Layout.
|
68 |
*
|
69 |
* @author Vicente Caballero Navarro
|
70 |
*/
|
71 |
public class FFramePicture extends FFrame { |
72 |
private static final int PRESENTACION = 0; |
73 |
private static final int BORRADOR = 1; |
74 |
private static final int ACTIVO = 1; |
75 |
private static final int SIEMPRE = 0; |
76 |
private BufferedImage m_image = null; |
77 |
private int m_quality = PRESENTACION; |
78 |
private int m_viewing = ACTIVO; |
79 |
private String m_path = null; |
80 |
|
81 |
/**
|
82 |
* Creates a new FFramePicture object.
|
83 |
*/
|
84 |
public FFramePicture() {
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
89 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
90 |
* de dibujar.
|
91 |
*
|
92 |
* @param g Graphics
|
93 |
* @param at Transformada afin.
|
94 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
95 |
* @param imgBase Imagen para acelerar el dibujado.
|
96 |
*/
|
97 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
98 |
BufferedImage imgBase) {
|
99 |
Rectangle2D.Double r = getBoundingBox(at);
|
100 |
double x = r.getMinX();
|
101 |
double y = r.getMinY();
|
102 |
double w = r.getWidth();
|
103 |
double h = r.getHeight();
|
104 |
|
105 |
if (intersects(rv, r)) {
|
106 |
if (m_image == null) { //Que no hay una imagen. |
107 |
drawEmpty(g); |
108 |
} else {
|
109 |
if ((rv == null) || (getQuality() == PRESENTACION)) { |
110 |
double scalex = (double) w / m_image.getWidth(null); |
111 |
double scaley = (double) h / m_image.getHeight(null); |
112 |
AffineTransform xform = AffineTransform.getScaleInstance(scalex, |
113 |
scaley); |
114 |
AffineTransform xpos = AffineTransform.getTranslateInstance(x, |
115 |
y); |
116 |
xpos.concatenate(xform); |
117 |
g.drawRenderedImage(m_image, xpos); |
118 |
} else {
|
119 |
drawDraft(g); |
120 |
} |
121 |
} |
122 |
} |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Rellena la calidad seg?n el entero que se pasa como par?metro.
|
127 |
*
|
128 |
* @param q entero que representa el tipo de calidad elegido.
|
129 |
*/
|
130 |
public void setQuality(int q) { |
131 |
m_quality = q; |
132 |
} |
133 |
|
134 |
/**
|
135 |
* Devuelve la calidad que est? seleccionada.
|
136 |
*
|
137 |
* @return entero que representa la calidad seleccionada.
|
138 |
*/
|
139 |
public int getQuality() { |
140 |
return m_quality;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Devuelve un entero que representa la forma en que se actualiza la vista.
|
145 |
*
|
146 |
* @return forma que se actualiza la vista.
|
147 |
*/
|
148 |
public int getViewing() { |
149 |
return m_viewing;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Rellena la forma de actualizar la vista.
|
154 |
*
|
155 |
* @param v entero que representa la forma de actualizar la vista.
|
156 |
*/
|
157 |
public void setViewing(int v) { |
158 |
m_viewing = v; |
159 |
} |
160 |
|
161 |
/**
|
162 |
* Rellena el nombre de la imagen.
|
163 |
*
|
164 |
* @param path nombre de la imagen.
|
165 |
*/
|
166 |
public void setPath(String path) { |
167 |
m_path = path; |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Devuelve la ruta del fichero.
|
172 |
*
|
173 |
* @return String
|
174 |
*/
|
175 |
public String getPath() { |
176 |
return m_path;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Rellena la imagen.
|
181 |
*
|
182 |
* @param image
|
183 |
*/
|
184 |
public void setImage(BufferedImage image) { |
185 |
m_image = image; |
186 |
} |
187 |
|
188 |
/**
|
189 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
190 |
*/
|
191 |
public XMLEntity getXMLEntity() {
|
192 |
XMLEntity xml = new XMLEntity();
|
193 |
xml.putProperty("className", this.getClass().getName()); |
194 |
xml.putProperty("m_name", m_name);
|
195 |
xml.putProperty("x", getBoundBox().x);
|
196 |
xml.putProperty("y", getBoundBox().y);
|
197 |
xml.putProperty("w", getBoundBox().width);
|
198 |
xml.putProperty("h", getBoundBox().height);
|
199 |
xml.putProperty("m_Selected", m_Selected);
|
200 |
xml.putProperty("type", Layout.RECTANGLEPICTURE);
|
201 |
xml.putProperty("m_path", m_path);
|
202 |
xml.putProperty("m_quality", m_quality);
|
203 |
xml.putProperty("m_viewing", m_viewing);
|
204 |
xml.putProperty("tag", getTag());
|
205 |
|
206 |
return xml;
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Carga la imagen a partir del nombre del fichero.
|
211 |
*
|
212 |
* @param file Fichero imagen.
|
213 |
*
|
214 |
* @return Imagen
|
215 |
*/
|
216 |
public Image load(String file) { |
217 |
ImageIcon tmpIcon = null; |
218 |
String iString = file.toLowerCase();
|
219 |
|
220 |
if (iString.endsWith("jpg") || iString.endsWith("jpeg") || |
221 |
iString.endsWith("gif")) {
|
222 |
tmpIcon = new ImageIcon(Jimi.getImage(file, Jimi.VIRTUAL_MEMORY)); //((File)main.allImages.elementAt(x)).getAbsolutePath()); |
223 |
} else if (iString.endsWith("png") || iString.endsWith("tif") || |
224 |
iString.endsWith("ico") || iString.endsWith("xpm") || |
225 |
iString.endsWith("bmp")) {
|
226 |
tmpIcon = new ImageIcon(Jimi.getImage(file, Jimi.VIRTUAL_MEMORY)); //new ImageIcon(f.getPath()); |
227 |
} |
228 |
|
229 |
Image image = tmpIcon.getImage();
|
230 |
setPath(file); |
231 |
|
232 |
BufferedImage bi = new BufferedImage((int) image.getWidth(null), |
233 |
(int) image.getHeight(null), BufferedImage.TYPE_INT_ARGB); |
234 |
Graphics2D biContext = bi.createGraphics();
|
235 |
biContext.drawImage(image, 0, 0, null); |
236 |
setImage(bi); |
237 |
|
238 |
return image;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* Incorpora los atributos del XMLEntity en el objeto actual.
|
243 |
*
|
244 |
* @param xml XMLEntity
|
245 |
* @param l Referencia al Layout.
|
246 |
*/
|
247 |
public void setXMLEntity(XMLEntity xml, Layout l) { |
248 |
if (xml.getIntProperty("m_Selected") != 0) { |
249 |
this.setSelected(true); |
250 |
} else {
|
251 |
this.setSelected(false); |
252 |
} |
253 |
|
254 |
this.m_path = xml.getStringProperty("m_path"); |
255 |
|
256 |
try {
|
257 |
load(this.m_path);
|
258 |
} catch (Exception ex) { |
259 |
NotificationManager.addError("Excepci?n :", ex);
|
260 |
} |
261 |
|
262 |
this.m_quality = xml.getIntProperty("m_quality"); |
263 |
this.m_viewing = xml.getIntProperty("m_viewing"); |
264 |
} |
265 |
|
266 |
/**
|
267 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
268 |
*/
|
269 |
public String getNameFFrame() { |
270 |
return PluginServices.getText(this, "imagen") + num; |
271 |
} |
272 |
|
273 |
/**
|
274 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
275 |
* java.awt.geom.AffineTransform)
|
276 |
*/
|
277 |
public void print(Graphics2D g, AffineTransform at) |
278 |
throws DriverException {
|
279 |
draw(g, at, null, null); |
280 |
} |
281 |
} |