svn-gvsig-desktop / tags / Root_v06 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrame.java @ 4811
History | View | Annotate | Download (23.6 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 17-may-2004
|
||
3 | *
|
||
4 | */
|
||
5 | 1103 | fjp | /* 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 | 312 | fernando | package com.iver.cit.gvsig.gui.layout.fframes; |
46 | |||
47 | 649 | vcaballero | import com.iver.andami.PluginServices; |
48 | import com.iver.andami.messages.NotificationManager; |
||
49 | |||
50 | 2268 | fjp | import com.iver.cit.gvsig.AddLayer; |
51 | 4209 | jaume | import com.iver.cit.gvsig.ProjectExtension; |
52 | 654 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
53 | 649 | vcaballero | import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
54 | 686 | vcaballero | import com.iver.cit.gvsig.gui.layout.Layout; |
55 | 1073 | vcaballero | import com.iver.cit.gvsig.gui.layout.dialogs.Tag; |
56 | 3183 | caballero | import com.iver.cit.gvsig.gui.project.OpenException; |
57 | 4209 | jaume | import com.iver.cit.gvsig.gui.project.SaveException; |
58 | 1222 | fernando | import com.iver.cit.gvsig.project.Project; |
59 | 649 | vcaballero | |
60 | import com.iver.utiles.XMLEntity; |
||
61 | |||
62 | 312 | fernando | import java.awt.Color; |
63 | import java.awt.Cursor; |
||
64 | import java.awt.Font; |
||
65 | import java.awt.Graphics2D; |
||
66 | 398 | vcaballero | import java.awt.Image; |
67 | 312 | fernando | import java.awt.Rectangle; |
68 | import java.awt.geom.AffineTransform; |
||
69 | import java.awt.geom.Point2D; |
||
70 | import java.awt.geom.Rectangle2D; |
||
71 | import java.awt.image.BufferedImage; |
||
72 | 649 | vcaballero | |
73 | 398 | vcaballero | import java.net.URL; |
74 | 312 | fernando | |
75 | 398 | vcaballero | import javax.swing.ImageIcon; |
76 | 312 | fernando | |
77 | 398 | vcaballero | |
78 | 312 | fernando | /**
|
79 | * Clase que implementa la interface IFFrame con los m?todos por defecto de
|
||
80 | * todos los FFrames que extenderan de este, dejando uno como m?todo
|
||
81 | * abstracto para implementar por todos los FFrames para ser dibujados.
|
||
82 | *
|
||
83 | * @author Vicente Caballero Navarro
|
||
84 | */
|
||
85 | public abstract class FFrame implements IFFrame { |
||
86 | 3135 | caballero | private static final int N = 1; |
87 | private static final int NE = 2; |
||
88 | private static final int E = 3; |
||
89 | private static final int SE = 4; |
||
90 | private static final int S = 5; |
||
91 | private static final int SO = 6; |
||
92 | private static final int O = 7; |
||
93 | private static final int NO = 8; |
||
94 | private static final int RECT = 9; |
||
95 | protected String m_name = "FFrame"; |
||
96 | private Rectangle2D.Double m_BoundBox = new Rectangle2D.Double(); |
||
97 | private Rectangle2D.Double m_BoundingBox = new Rectangle2D.Double(); |
||
98 | protected int m_Selected = 0; |
||
99 | private Rectangle n = new Rectangle(); |
||
100 | private Rectangle ne = new Rectangle(); |
||
101 | private Rectangle e = new Rectangle(); |
||
102 | private Rectangle se = new Rectangle(); |
||
103 | private Rectangle s = new Rectangle(); |
||
104 | private Rectangle so = new Rectangle(); |
||
105 | private Rectangle o = new Rectangle(); |
||
106 | private Rectangle no = new Rectangle(); |
||
107 | private String tag = null; |
||
108 | protected int num = 0; |
||
109 | private double m_rotation = 0; |
||
110 | private int level = -1; |
||
111 | 312 | fernando | |
112 | 3135 | caballero | /**
|
113 | * Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
||
114 | * par?metro.
|
||
115 | *
|
||
116 | * @param g Graphics sobre el que dibujar.
|
||
117 | */
|
||
118 | public void drawHandlers(Graphics2D g) { |
||
119 | int size = 10; |
||
120 | Rectangle2D r = getBoundingBox(null); |
||
121 | Point2D p = new Point2D.Double(); |
||
122 | g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2), |
||
123 | r.getY() + (r.getHeight() / 2));
|
||
124 | 398 | vcaballero | |
125 | 3135 | caballero | AffineTransform atRotate = new AffineTransform(); |
126 | atRotate.rotate(Math.toRadians(getRotation()),
|
||
127 | r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
||
128 | 312 | fernando | |
129 | 3135 | caballero | g.fillRect((int) r.getX() - size, (int) r.getY() - size, size, size); |
130 | atRotate.transform(new Point2D.Double(r.getX() - size, r.getY() - size), |
||
131 | p); |
||
132 | no.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
133 | 312 | fernando | |
134 | 3135 | caballero | g.fillRect((int) r.getMaxX(), (int) r.getY() - size, size, size); |
135 | atRotate.transform(new Point2D.Double(r.getMaxX(), r.getY() - size), p); |
||
136 | ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
137 | 312 | fernando | |
138 | 3135 | caballero | g.fillRect((int) r.getX() - size, (int) r.getMaxY(), size, size); |
139 | atRotate.transform(new Point2D.Double(r.getX() - size, r.getMaxY()), p); |
||
140 | so.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
141 | 312 | fernando | |
142 | 3135 | caballero | g.fillRect((int) r.getMaxX(), (int) r.getMaxY(), size, size); |
143 | atRotate.transform(new Point2D.Double(r.getMaxX(), r.getMaxY()), p); |
||
144 | se.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
145 | 312 | fernando | |
146 | 3135 | caballero | g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size, |
147 | size, size); |
||
148 | atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
||
149 | r.getY() - size), p); |
||
150 | n.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
151 | 312 | fernando | |
152 | 3135 | caballero | g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY(), size, |
153 | size); |
||
154 | atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
||
155 | r.getMaxY()), p); |
||
156 | s.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
157 | 312 | fernando | |
158 | 3135 | caballero | g.fillRect((int) r.getX() - size, (int) r.getCenterY() - (size / 2), |
159 | size, size); |
||
160 | atRotate.transform(new Point2D.Double(r.getX() - size, |
||
161 | r.getCenterY() - (size / 2)), p);
|
||
162 | o.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
163 | 312 | fernando | |
164 | 3135 | caballero | g.fillRect((int) r.getMaxX(), (int) r.getCenterY() - (size / 2), size, |
165 | size); |
||
166 | atRotate.transform(new Point2D.Double(r.getMaxX(), |
||
167 | r.getCenterY() - (size / 2)), p);
|
||
168 | e.setRect((int) p.getX(), (int) p.getY(), size, size); |
||
169 | g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2), |
||
170 | r.getY() + (r.getHeight() / 2));
|
||
171 | } |
||
172 | 312 | fernando | |
173 | 3135 | caballero | /**
|
174 | * Establece que tipo de selecci?n se realiza sobre el fframe.
|
||
175 | *
|
||
176 | * @param p punto sobre el que se debe de establecer si se selecciona o no
|
||
177 | * el fframe.
|
||
178 | */
|
||
179 | public void setSelected(Point2D.Double p) { |
||
180 | m_Selected = getContains(p); |
||
181 | } |
||
182 | 312 | fernando | |
183 | 3135 | caballero | /**
|
184 | * Actualiza el BoundBox del FFrame a partir de su rect?ngulo en pixels y
|
||
185 | * la matriz de transformaci?n.
|
||
186 | *
|
||
187 | * @param r Rect?ngulo.
|
||
188 | * @param at Matriz de transformaci?n.
|
||
189 | */
|
||
190 | public void updateRect(Rectangle2D r, AffineTransform at) { |
||
191 | Rectangle2D.Double rec = FLayoutUtilities.toSheetRect(r, at);
|
||
192 | rec.setRect((int) rec.getMinX(), (int) rec.getMinY(), |
||
193 | (int) rec.getWidth(), (int) rec.getHeight()); |
||
194 | setBoundBox(rec); |
||
195 | } |
||
196 | 312 | fernando | |
197 | 3135 | caballero | /**
|
198 | * Devuelve el rect?ngulo a partir del desplazamiento en el eje x y el
|
||
199 | * desplazamiento en el eje y.
|
||
200 | *
|
||
201 | * @param difx desplazamiento sobre el eje x.
|
||
202 | * @param dify desplazamiento sobre el eje y.
|
||
203 | *
|
||
204 | * @return rect?ngulo modificado en funci?n del desplazamiento realizado.
|
||
205 | */
|
||
206 | public Rectangle2D getMovieRect(int difx, int dify) { |
||
207 | double x = 0; |
||
208 | double y = 0; |
||
209 | double w = 0; |
||
210 | double h = 0; |
||
211 | 312 | fernando | |
212 | 3135 | caballero | Rectangle2D.Double rectaux = new Rectangle2D.Double(this.getBoundingBox( |
213 | null).x, this.getBoundingBox(null).y, |
||
214 | this.getBoundingBox(null).width, |
||
215 | this.getBoundingBox(null).height); |
||
216 | Rectangle2D.Double rec = this.getBoundingBox(null); |
||
217 | int difn = 0; |
||
218 | difn = difx; |
||
219 | x = rectaux.x; |
||
220 | y = rectaux.y; |
||
221 | w = rectaux.width; |
||
222 | h = rectaux.height; |
||
223 | 312 | fernando | |
224 | 3135 | caballero | switch (this.getSelected()) { |
225 | case (RECT):
|
||
226 | rectaux.setRect((x + difx), (y + dify), w, h); |
||
227 | 312 | fernando | |
228 | 3135 | caballero | break;
|
229 | 312 | fernando | |
230 | 3135 | caballero | case (N):
|
231 | 312 | fernando | |
232 | 3135 | caballero | if ((y + dify) > rec.getMaxY()) {
|
233 | y = rec.getMaxY(); |
||
234 | } else {
|
||
235 | y = y + dify; |
||
236 | } |
||
237 | 312 | fernando | |
238 | 3135 | caballero | rectaux.setRect(x, y, w, Math.abs(h - dify));
|
239 | 312 | fernando | |
240 | 3135 | caballero | break;
|
241 | 312 | fernando | |
242 | 3135 | caballero | case (O):
|
243 | 312 | fernando | |
244 | 3135 | caballero | if ((x + difx) > rec.getMaxX()) {
|
245 | x = rec.getMaxX(); |
||
246 | } else {
|
||
247 | x = x + difx; |
||
248 | } |
||
249 | 312 | fernando | |
250 | 3135 | caballero | rectaux.setRect(x, y, Math.abs(w - difx), h);
|
251 | 312 | fernando | |
252 | 3135 | caballero | break;
|
253 | 312 | fernando | |
254 | 3135 | caballero | case (S):
|
255 | 312 | fernando | |
256 | 3135 | caballero | if (y > (rec.getMaxY() + dify)) {
|
257 | y = rec.getMaxY() + dify; |
||
258 | } |
||
259 | 312 | fernando | |
260 | 3135 | caballero | rectaux.setRect(x, y, w, Math.abs(h + dify));
|
261 | 312 | fernando | |
262 | 3135 | caballero | break;
|
263 | 312 | fernando | |
264 | 3135 | caballero | case (E):
|
265 | 312 | fernando | |
266 | 3135 | caballero | if (x > (rec.getMaxX() + difx)) {
|
267 | x = rec.getMaxX() + difx; |
||
268 | } |
||
269 | 312 | fernando | |
270 | 3135 | caballero | rectaux.setRect(x, y, Math.abs(w + difx), h);
|
271 | 312 | fernando | |
272 | 3135 | caballero | break;
|
273 | 312 | fernando | |
274 | 3135 | caballero | case (NE):
|
275 | 312 | fernando | |
276 | 3135 | caballero | if ((y - difn) > rec.getMaxY()) {
|
277 | y = rec.getMaxY(); |
||
278 | x = rec.getMaxX() + difn; |
||
279 | } else {
|
||
280 | y = y - difn; |
||
281 | } |
||
282 | 312 | fernando | |
283 | 3135 | caballero | rectaux.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn)); |
284 | 312 | fernando | |
285 | 3135 | caballero | break;
|
286 | 312 | fernando | |
287 | 3135 | caballero | case (NO):
|
288 | 312 | fernando | |
289 | 3135 | caballero | if ((y + difn) > rec.getMaxY()) {
|
290 | y = rec.getMaxY(); |
||
291 | x = rec.getMaxX(); |
||
292 | } else {
|
||
293 | x = x + difn; |
||
294 | y = y + difn; |
||
295 | } |
||
296 | 312 | fernando | |
297 | 3135 | caballero | rectaux.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
298 | 312 | fernando | |
299 | 3135 | caballero | break;
|
300 | 312 | fernando | |
301 | 3135 | caballero | case (SE):
|
302 | 312 | fernando | |
303 | 3135 | caballero | if (y > (rec.getMaxY() + difn)) {
|
304 | y = rec.getMaxY() + difn; |
||
305 | x = rec.getMaxX() + difn; |
||
306 | } |
||
307 | 312 | fernando | |
308 | 3135 | caballero | rectaux.setRect(x, y, Math.abs(w + difn), Math.abs(h + difn)); |
309 | 312 | fernando | |
310 | 3135 | caballero | break;
|
311 | 312 | fernando | |
312 | 3135 | caballero | case (SO):
|
313 | 312 | fernando | |
314 | 3135 | caballero | if ((x + difn) > rec.getMaxX()) {
|
315 | x = rec.getMaxX(); |
||
316 | y = rec.getMaxY() - difn; |
||
317 | } else {
|
||
318 | x = x + difn; |
||
319 | } |
||
320 | 312 | fernando | |
321 | 3135 | caballero | rectaux.setRect(x, y, Math.abs(w - difn), Math.abs(h - difn)); |
322 | 312 | fernando | |
323 | 3135 | caballero | break;
|
324 | 312 | fernando | |
325 | 3135 | caballero | default:
|
326 | rectaux.setRect((x), (y), w, h); |
||
327 | } |
||
328 | 312 | fernando | |
329 | 3135 | caballero | return rectaux;
|
330 | } |
||
331 | 312 | fernando | |
332 | 3135 | caballero | /**
|
333 | * Devuelve un entero que representa el tipo de selecci?n que se ha
|
||
334 | * realizado sobre el fframe.
|
||
335 | *
|
||
336 | * @return tipo de selecci?n que se ha realizado.
|
||
337 | */
|
||
338 | public int getSelected() { |
||
339 | return m_Selected;
|
||
340 | } |
||
341 | 312 | fernando | |
342 | 3135 | caballero | /**
|
343 | * Devuelve true, si el punto que se pasa como par?metro esta contenido
|
||
344 | * dentro del boundingbox del fframe.
|
||
345 | *
|
||
346 | * @param p punto a comprobar.
|
||
347 | *
|
||
348 | * @return true si el punto esta dentro del boundingbox.
|
||
349 | */
|
||
350 | public boolean contains(Point2D.Double p) { |
||
351 | return getBoundingBox(null).contains(p.x, p.y); |
||
352 | } |
||
353 | 312 | fernando | |
354 | 3135 | caballero | /**
|
355 | * Devuelve un entero que representa donde esta contenido el punto que se
|
||
356 | * pasa como par?metro.
|
||
357 | *
|
||
358 | * @param p punto a comparar.
|
||
359 | *
|
||
360 | * @return entero que representa como esta contenido el punto.
|
||
361 | */
|
||
362 | public int getContains(Point2D.Double p) { |
||
363 | if (n.contains(p.x, p.y)) {
|
||
364 | return N;
|
||
365 | } else if (ne.contains(p.x, p.y)) { |
||
366 | return NE;
|
||
367 | } else if (e.contains(p.x, p.y)) { |
||
368 | return E;
|
||
369 | } else if (e.contains(p.x, p.y)) { |
||
370 | return E;
|
||
371 | } else if (se.contains(p.x, p.y)) { |
||
372 | return SE;
|
||
373 | } else if (s.contains(p.x, p.y)) { |
||
374 | return S;
|
||
375 | } else if (so.contains(p.x, p.y)) { |
||
376 | return SO;
|
||
377 | } else if (o.contains(p.x, p.y)) { |
||
378 | return O;
|
||
379 | } else if (no.contains(p.x, p.y)) { |
||
380 | return NO;
|
||
381 | } else if (getBoundingBox(null).contains(p.x, p.y)) { |
||
382 | return RECT;
|
||
383 | } |
||
384 | 312 | fernando | |
385 | 3135 | caballero | return 0; |
386 | } |
||
387 | 312 | fernando | |
388 | 3135 | caballero | /**
|
389 | * Devuelve el Cursor adecuado seg?n como est? contenido el punto, si es
|
||
390 | * para desplazamiento, o cambio de tama?o.
|
||
391 | *
|
||
392 | * @param p punto a comprobar.
|
||
393 | *
|
||
394 | * @return Cursor adecuado a la posici?n.
|
||
395 | */
|
||
396 | public Cursor getMapCursor(Point2D.Double p) { |
||
397 | int select = getContains(p);
|
||
398 | 312 | fernando | |
399 | 3135 | caballero | switch (select) {
|
400 | case (N):
|
||
401 | return Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR); |
||
402 | 312 | fernando | |
403 | 3135 | caballero | case (NE):
|
404 | return Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR); |
||
405 | 312 | fernando | |
406 | 3135 | caballero | case (E):
|
407 | return Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); |
||
408 | 312 | fernando | |
409 | 3135 | caballero | case (SE):
|
410 | return Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR); |
||
411 | 312 | fernando | |
412 | 3135 | caballero | case (S):
|
413 | return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR); |
||
414 | 312 | fernando | |
415 | 3135 | caballero | case (SO):
|
416 | return Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR); |
||
417 | 312 | fernando | |
418 | 3135 | caballero | case (O):
|
419 | return Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR); |
||
420 | 312 | fernando | |
421 | 3135 | caballero | case (NO):
|
422 | return Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR); |
||
423 | 312 | fernando | |
424 | 3135 | caballero | case (RECT):
|
425 | return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); |
||
426 | } |
||
427 | 312 | fernando | |
428 | 3135 | caballero | return null; |
429 | } |
||
430 | 2183 | fernando | |
431 | 3135 | caballero | /**
|
432 | * Este m?todo se implementa en cada una de las fframe, ya que cada una se
|
||
433 | * dibuja de una forma diferente sobre el graphics. M?todo que dibuja
|
||
434 | * sobre el graphics que se le pasa como par?metro, seg?n la transformada
|
||
435 | * afin que se debe de aplicar y el rect?ngulo que se debe de dibujar.
|
||
436 | * M?todo que dibuja sobre el graphics que se le pasa como par?metro,
|
||
437 | * seg?n la transformada afin que se debe de aplicar y el rect?ngulo que
|
||
438 | * se debe de dibujar.
|
||
439 | *
|
||
440 | * @param g Graphics
|
||
441 | * @param at Transformada afin.
|
||
442 | * @param r rect?ngulo sobre el que hacer un clip.
|
||
443 | * @param imgBase DOCUMENT ME!
|
||
444 | *
|
||
445 | * @throws DriverException
|
||
446 | */
|
||
447 | public abstract void draw(Graphics2D g, AffineTransform at, Rectangle2D r, |
||
448 | BufferedImage imgBase) throws DriverException; |
||
449 | 2183 | fernando | |
450 | 3135 | caballero | /**
|
451 | * Devuelve el nombre que representa al fframe.
|
||
452 | *
|
||
453 | * @return String
|
||
454 | */
|
||
455 | public String getName() { |
||
456 | return m_name;
|
||
457 | } |
||
458 | 2183 | fernando | |
459 | 3135 | caballero | /**
|
460 | * Rellena el String que representa al nombre del fframe.
|
||
461 | *
|
||
462 | * @param n nombre del fframe.
|
||
463 | */
|
||
464 | public void setName(String n) { |
||
465 | m_name = n; |
||
466 | } |
||
467 | 2183 | fernando | |
468 | 3135 | caballero | /**
|
469 | * Devuelve el boundingBox del fframe en funci?n de la transformada af?n
|
||
470 | * que se pasa como par?metro. Si se pasa como par?metro null, devuelve el
|
||
471 | * ?ltimo boundingbox que se calcul?.
|
||
472 | *
|
||
473 | * @param at Transformada af?n
|
||
474 | *
|
||
475 | * @return Rect?ngulo que representa el BoundingBox del fframe.
|
||
476 | */
|
||
477 | public Rectangle2D.Double getBoundingBox(AffineTransform at) { |
||
478 | if (at == null) { |
||
479 | return m_BoundingBox;
|
||
480 | } |
||
481 | 2183 | fernando | |
482 | 3135 | caballero | m_BoundingBox = FLayoutUtilities.fromSheetRect(m_BoundBox, at); |
483 | 312 | fernando | |
484 | 3135 | caballero | return m_BoundingBox;
|
485 | } |
||
486 | 1073 | vcaballero | |
487 | 3135 | caballero | /**
|
488 | * Rellena con el rect?ngulo que se pasa como par?metro el boundBox(en
|
||
489 | * cent?metros) del fframe del cual con una transformaci?n se podr?
|
||
490 | * calcular el BoundingBox (en pixels).
|
||
491 | *
|
||
492 | * @param r Rect?ngulo en cent?metros.
|
||
493 | */
|
||
494 | public void setBoundBox(Rectangle2D r) { |
||
495 | m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
||
496 | } |
||
497 | 1073 | vcaballero | |
498 | 3135 | caballero | /**
|
499 | * Devuelve el rect?ngulo que representa el fframe en cent?metros.
|
||
500 | *
|
||
501 | * @return Rect?ngulo en centimetros.
|
||
502 | */
|
||
503 | public Rectangle2D.Double getBoundBox() { |
||
504 | return m_BoundBox;
|
||
505 | } |
||
506 | 312 | fernando | |
507 | 3135 | caballero | /**
|
508 | * Pasando como par?metro true, se toma como que esta seleccionado el
|
||
509 | * fframe y si es false como que esta sin seleccionar, de esta forma se
|
||
510 | * selecciona un fframe directamente sin comprobar si un punto esta
|
||
511 | * contenido en ?l.
|
||
512 | *
|
||
513 | * @param b true si se quiere seleccionar y false si se quiere
|
||
514 | * deseleccionar.
|
||
515 | */
|
||
516 | public void setSelected(boolean b) { |
||
517 | if (b) {
|
||
518 | m_Selected = RECT; |
||
519 | } else {
|
||
520 | m_Selected = IFFrame.NOSELECT; |
||
521 | } |
||
522 | } |
||
523 | 312 | fernando | |
524 | 3135 | caballero | /**
|
525 | * Crea un Objeto FFrame seg?n el tipo que sea, a partir de la informaci?n
|
||
526 | * del XMLEntity.
|
||
527 | *
|
||
528 | * @param xml XMLEntity
|
||
529 | * @param l Layout.
|
||
530 | * @param p Proyecto.
|
||
531 | *
|
||
532 | * @return Objeto de esta clase.
|
||
533 | */
|
||
534 | public static IFFrame createFFrame03(XMLEntity xml, Layout l, Project p) { |
||
535 | IFFrame fframe = null;
|
||
536 | 312 | fernando | |
537 | 3135 | caballero | try {
|
538 | Class clase = Class.forName(xml.getStringProperty("className")); |
||
539 | fframe = (IFFrame) clase.newInstance(); |
||
540 | } catch (Exception e) { |
||
541 | NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
|
||
542 | e); |
||
543 | } |
||
544 | 312 | fernando | |
545 | 3135 | caballero | if (fframe instanceof FFrameView) { |
546 | ((FFrameView) fframe).setProject(p); |
||
547 | } |
||
548 | 3168 | caballero | fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
549 | xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
||
550 | xml.getDoubleProperty("h")));
|
||
551 | 3135 | caballero | fframe.setXMLEntity03(xml, l); |
552 | fframe.setName(xml.getStringProperty("m_name"));
|
||
553 | 312 | fernando | |
554 | 3168 | caballero | |
555 | 3135 | caballero | fframe.setTag(xml.getStringProperty("tag"));
|
556 | 312 | fernando | |
557 | 3135 | caballero | return fframe;
|
558 | } |
||
559 | 312 | fernando | |
560 | 3135 | caballero | /**
|
561 | * Crea un Objeto FFrame seg?n el tipo que sea, a partir de la informaci?n
|
||
562 | * del XMLEntity.
|
||
563 | *
|
||
564 | * @param xml XMLEntity
|
||
565 | * @param p Proyecto.
|
||
566 | *
|
||
567 | * @return Objeto de esta clase.
|
||
568 | */
|
||
569 | 3183 | caballero | public static IFFrame createFFrame(XMLEntity xml, Project p) throws OpenException { |
570 | IFFrame fframe = null;
|
||
571 | String className="IFFrame"; |
||
572 | 4209 | jaume | Class clase=null; |
573 | try {
|
||
574 | className=xml.getStringProperty("className");
|
||
575 | clase = Class.forName(className);
|
||
576 | } catch (ClassNotFoundException e) { |
||
577 | NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",e);
|
||
578 | } |
||
579 | try {
|
||
580 | fframe = (IFFrame) clase.newInstance(); |
||
581 | } catch (InstantiationException e) { |
||
582 | NotificationManager.addError("Fallo creando el Frame: "+clase.getName(),e);
|
||
583 | } catch (IllegalAccessException e) { |
||
584 | NotificationManager.addError("Fallo creando el Frame: "+clase.getName(),e);
|
||
585 | } |
||
586 | |||
587 | try{
|
||
588 | if (fframe instanceof FFrameView) { |
||
589 | ((FFrameView) fframe).setProject(p); |
||
590 | } |
||
591 | |||
592 | fframe.setXMLEntity(xml); |
||
593 | |||
594 | if (xml.contains("level")) { |
||
595 | fframe.setLevel(xml.getIntProperty("level"));
|
||
596 | } |
||
597 | |||
598 | fframe.setName(xml.getStringProperty("m_name"));
|
||
599 | fframe.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
||
600 | xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
||
601 | xml.getDoubleProperty("h")));
|
||
602 | fframe.setTag(xml.getStringProperty("tag"));
|
||
603 | }catch (Exception e) { |
||
604 | throw new OpenException(e,className); |
||
605 | } |
||
606 | 3183 | caballero | return fframe;
|
607 | 3135 | caballero | } |
608 | 3106 | caballero | |
609 | 3135 | caballero | /**
|
610 | * Dibuja sobre el graphics el rect?ngulo del fframe en modo borrador.
|
||
611 | *
|
||
612 | * @param g Graphics so bre el que dibujar.
|
||
613 | */
|
||
614 | public void drawDraft(Graphics2D g) { |
||
615 | Rectangle2D r = getBoundingBox(null); |
||
616 | |||
617 | g.setColor(Color.lightGray);
|
||
618 | g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
||
619 | (int) r.getHeight());
|
||
620 | g.setColor(Color.black);
|
||
621 | |||
622 | int scale = (int) (r.getWidth() / 12); |
||
623 | Font f = new Font("SansSerif", Font.PLAIN, scale); |
||
624 | g.setFont(f); |
||
625 | g.drawString(getName(), |
||
626 | (int) (r.getCenterX() - ((getName().length() * scale) / 4)), |
||
627 | (int) (r.getCenterY()));
|
||
628 | } |
||
629 | |||
630 | /**
|
||
631 | * Rellena con el n?mero de FFrame.
|
||
632 | *
|
||
633 | * @param i n?mero
|
||
634 | */
|
||
635 | public void setNum(int i) { |
||
636 | num = i; |
||
637 | } |
||
638 | |||
639 | /**
|
||
640 | * Dibuja sobre el graphics el rect?ngulo del fframe pero vacio, mostrando
|
||
641 | * el nombre del fframe y vacio.
|
||
642 | *
|
||
643 | * @param g Graphics sobre el que dibujar.
|
||
644 | */
|
||
645 | public void drawEmpty(Graphics2D g) { |
||
646 | Rectangle2D r = getBoundingBox(null); |
||
647 | g.setColor(Color.lightGray);
|
||
648 | g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
||
649 | (int) r.getHeight());
|
||
650 | g.setColor(Color.black);
|
||
651 | |||
652 | int scale = (int) (r.getWidth() / 12); |
||
653 | Font f = new Font("SansSerif", Font.PLAIN, scale); |
||
654 | g.setFont(f); |
||
655 | |||
656 | String s = this.getNameFFrame() + " " + |
||
657 | PluginServices.getText(this, "vacia"); |
||
658 | |||
659 | g.drawString(s, (int) (r.getCenterX() - ((s.length() * scale) / 4)), |
||
660 | (int) (r.getCenterY()));
|
||
661 | } |
||
662 | |||
663 | /**
|
||
664 | * Devuelve true si el rect?ngulo primero es null o si es distinto de null
|
||
665 | * e intersecta.
|
||
666 | *
|
||
667 | * @param rv Rect?ngulo
|
||
668 | * @param r Rect?ngulo
|
||
669 | *
|
||
670 | * @return True si intersecta o es null.
|
||
671 | */
|
||
672 | public boolean intersects(Rectangle2D rv, Rectangle2D r) { |
||
673 | return (((rv != null) && rv.intersects(r)) || (rv == null)); |
||
674 | } |
||
675 | |||
676 | /**
|
||
677 | * Abre el di?logo para cambiar o a?adir el tag.
|
||
678 | */
|
||
679 | public void openTag() { |
||
680 | Tag tag = new Tag(this); |
||
681 | PluginServices.getMDIManager().addView(tag); |
||
682 | } |
||
683 | |||
684 | /**
|
||
685 | * Rellena el tag del FFrame.
|
||
686 | *
|
||
687 | * @param s String que representa el valor a guardar en el tag.
|
||
688 | */
|
||
689 | public void setTag(String s) { |
||
690 | tag = s; |
||
691 | } |
||
692 | |||
693 | /**
|
||
694 | * Devuelve el tag.
|
||
695 | *
|
||
696 | * @return tag.
|
||
697 | */
|
||
698 | public String getTag() { |
||
699 | return tag;
|
||
700 | } |
||
701 | |||
702 | /**
|
||
703 | * Dibuja sobre el graphics que se pasa como par?metro el icono que
|
||
704 | * representa que contiene un tag.
|
||
705 | *
|
||
706 | * @param g Graphics sobre el que dibujar el icono.
|
||
707 | */
|
||
708 | public void drawSymbolTag(Graphics2D g) { |
||
709 | Rectangle2D rec = getBoundingBox(null); |
||
710 | g.rotate(Math.toRadians(getRotation()),
|
||
711 | rec.getX() + (rec.getWidth() / 2),
|
||
712 | rec.getY() + (rec.getHeight() / 2));
|
||
713 | |||
714 | try {
|
||
715 | URL url = AddLayer.class.getClassLoader().getResource("images/symbolTag.gif"); |
||
716 | Image image = new ImageIcon(url).getImage(); |
||
717 | g.drawImage(image, (int) rec.getX(), (int) rec.getY(), 25, 30, null); |
||
718 | } catch (NullPointerException npe) { |
||
719 | } |
||
720 | |||
721 | g.rotate(Math.toRadians(-getRotation()),
|
||
722 | rec.getX() + (rec.getWidth() / 2),
|
||
723 | rec.getY() + (rec.getHeight() / 2));
|
||
724 | } |
||
725 | |||
726 | /**
|
||
727 | * Rellenar la rotaci?n para aplicar al FFrame.
|
||
728 | *
|
||
729 | * @param rotation rotaci?n que se quiere aplicar.
|
||
730 | */
|
||
731 | public void setRotation(double rotation) { |
||
732 | m_rotation = rotation; |
||
733 | } |
||
734 | |||
735 | /**
|
||
736 | * Devuelve la rotaci?n del FFrame.
|
||
737 | *
|
||
738 | * @return Rotaci?n del FFrame.
|
||
739 | */
|
||
740 | public double getRotation() { |
||
741 | return m_rotation;
|
||
742 | } |
||
743 | |||
744 | /**
|
||
745 | * Devuelve el nivel en el que se encuentra el FFrame.
|
||
746 | *
|
||
747 | * @return nivel
|
||
748 | */
|
||
749 | public int getLevel() { |
||
750 | return level;
|
||
751 | } |
||
752 | |||
753 | /**
|
||
754 | * Inserta el nivel al que se encuentra el FFrame.
|
||
755 | *
|
||
756 | * @param l entero que refleja el nivel del FFrame.
|
||
757 | */
|
||
758 | public void setLevel(int l) { |
||
759 | level = l; |
||
760 | } |
||
761 | 4209 | jaume | |
762 | /**
|
||
763 | * DOCUMENT ME!
|
||
764 | *
|
||
765 | * @param layout DOCUMENT ME!
|
||
766 | *
|
||
767 | * @return DOCUMENT ME!
|
||
768 | */
|
||
769 | public IFFrame cloneFFrame(Layout layout) {
|
||
770 | return null; |
||
771 | } |
||
772 | |||
773 | /**
|
||
774 | * DOCUMENT ME!
|
||
775 | *
|
||
776 | * @return DOCUMENT ME!
|
||
777 | * @throws SaveException
|
||
778 | *
|
||
779 | * @throws SaveException DOCUMENT ME!
|
||
780 | */
|
||
781 | public XMLEntity getXMLEntity() throws SaveException, SaveException { |
||
782 | XMLEntity xml = new XMLEntity();
|
||
783 | xml.putProperty("className", this.getClass().getName()); |
||
784 | xml.putProperty("m_name", m_name);
|
||
785 | xml.putProperty("x", getBoundBox().x);
|
||
786 | xml.putProperty("y", getBoundBox().y);
|
||
787 | xml.putProperty("w", getBoundBox().width);
|
||
788 | xml.putProperty("h", getBoundBox().height);
|
||
789 | xml.putProperty("m_Selected", m_Selected);
|
||
790 | xml.putProperty("tag", getTag());
|
||
791 | xml.putProperty("m_rotation", getRotation());
|
||
792 | |||
793 | return xml;
|
||
794 | } |
||
795 | |||
796 | 312 | fernando | } |