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