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