root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameTable.java @ 9392
History | View | Annotate | Download (15.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
/* CVS MESSAGES:
|
42 |
*
|
43 |
* $Id: FFrameTable.java 9392 2006-12-20 14:50:10Z caballero $
|
44 |
* $Log$
|
45 |
* Revision 1.1 2006-12-20 14:42:06 caballero
|
46 |
* Remodelado Layout
|
47 |
*
|
48 |
* Revision 1.6 2006/12/11 17:40:35 caballero
|
49 |
* ajustar a grid en el Layout
|
50 |
*
|
51 |
* Revision 1.5 2006/09/15 10:41:30 caballero
|
52 |
* extensibilidad de documentos
|
53 |
*
|
54 |
* Revision 1.4 2006/08/01 09:16:24 caballero
|
55 |
* optimizar c?digo
|
56 |
*
|
57 |
* Revision 1.3 2006/05/26 06:51:08 caballero
|
58 |
* Proyectos de la versi?n 0.6
|
59 |
*
|
60 |
* Revision 1.2 2006/04/18 06:43:11 caballero
|
61 |
* Editar v?rtice
|
62 |
*
|
63 |
* Revision 1.1 2006/04/10 06:37:07 caballero
|
64 |
* FFrameTable
|
65 |
*
|
66 |
* Revision 1.1 2006/01/12 12:32:04 caballero
|
67 |
* box
|
68 |
*
|
69 |
*
|
70 |
*/
|
71 |
package com.iver.cit.gvsig.project.documents.layout.fframes; |
72 |
|
73 |
import java.awt.Color; |
74 |
import java.awt.Graphics2D; |
75 |
import java.awt.Image; |
76 |
import java.awt.event.MouseEvent; |
77 |
import java.awt.geom.AffineTransform; |
78 |
import java.awt.geom.Point2D; |
79 |
import java.awt.geom.Rectangle2D; |
80 |
import java.awt.image.BufferedImage; |
81 |
import java.util.ArrayList; |
82 |
|
83 |
import javax.swing.ImageIcon; |
84 |
|
85 |
import com.iver.andami.PluginServices; |
86 |
import com.iver.cit.gvsig.AddLayer; |
87 |
import com.iver.cit.gvsig.fmap.DriverException; |
88 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
89 |
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameBoxDialog; |
90 |
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
91 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
92 |
import com.iver.utiles.XMLEntity; |
93 |
|
94 |
|
95 |
/**
|
96 |
* DOCUMENT ME!
|
97 |
*
|
98 |
* @author Vicente Caballero Navarro
|
99 |
*/
|
100 |
public class FFrameTable extends FFrameGroup implements IFFrameGroupSelectable{ |
101 |
private int numColumns = 2; |
102 |
private int numRows = 2; |
103 |
private boolean selectFFrameBasic=false; |
104 |
private static final Image iMove = new ImageIcon(AddLayer.class |
105 |
.getClassLoader().getResource("images/Move.png")).getImage();
|
106 |
|
107 |
|
108 |
/**
|
109 |
* DOCUMENT ME!
|
110 |
*
|
111 |
* @param g DOCUMENT ME!
|
112 |
* @param at DOCUMENT ME!
|
113 |
* @param rv DOCUMENT ME!
|
114 |
* @param imgBase DOCUMENT ME!
|
115 |
*
|
116 |
* @throws DriverException DOCUMENT ME!
|
117 |
*/
|
118 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
119 |
BufferedImage imgBase) throws DriverException { |
120 |
Rectangle2D.Double r = getBoundingBox(at);
|
121 |
g.setColor(Color.black);
|
122 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
123 |
r.y + (r.height / 2));
|
124 |
drawRectangles(g,at,rv,imgBase); |
125 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
126 |
r.y + (r.height / 2));
|
127 |
super.draw(g,at,rv,imgBase);
|
128 |
} |
129 |
|
130 |
private void drawRectangles(Graphics2D g, AffineTransform at,Rectangle2D rv,BufferedImage imgBase) { |
131 |
IFFrame[] fframes=getFFrames();
|
132 |
for (int i =0;i<fframes.length;i++){ |
133 |
FFrameBasic basic=(FFrameBasic)fframes[i]; |
134 |
try {
|
135 |
basic.draw(g,at,rv,imgBase); |
136 |
} catch (DriverException e) {
|
137 |
e.printStackTrace(); |
138 |
} |
139 |
} |
140 |
} |
141 |
|
142 |
/**
|
143 |
* DOCUMENT ME!
|
144 |
*
|
145 |
* @param r DOCUMENT ME!
|
146 |
* @param g DOCUMENT ME!
|
147 |
*/
|
148 |
public void drawBox(Rectangle2D r, Graphics2D g) { |
149 |
calculateTable(r); |
150 |
IFFrame[] fframes=getFFrames();
|
151 |
for (int i =0;i<fframes.length;i++){ |
152 |
FFrameBasic basic=(FFrameBasic)fframes[i]; |
153 |
try {
|
154 |
basic.draw(g,new AffineTransform(),null,null); |
155 |
} catch (DriverException e) {
|
156 |
e.printStackTrace(); |
157 |
} |
158 |
} |
159 |
} |
160 |
|
161 |
/**
|
162 |
* DOCUMENT ME!
|
163 |
*
|
164 |
* @param g DOCUMENT ME!
|
165 |
* @param at DOCUMENT ME!
|
166 |
*
|
167 |
* @throws DriverException DOCUMENT ME!
|
168 |
*/
|
169 |
public void print(Graphics2D g, AffineTransform at) |
170 |
throws DriverException {
|
171 |
draw(g, at, null, null); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* DOCUMENT ME!
|
176 |
*
|
177 |
* @return DOCUMENT ME!
|
178 |
*
|
179 |
* @throws SaveException DOCUMENT ME!
|
180 |
*/
|
181 |
public XMLEntity getXMLEntity() throws SaveException { |
182 |
XMLEntity xml = super.getXMLEntity();
|
183 |
xml.putProperty("numColumns",numColumns);
|
184 |
xml.putProperty("numRows",numRows);
|
185 |
return xml;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* DOCUMENT ME!
|
190 |
*
|
191 |
* @param xml DOCUMENT ME!
|
192 |
*/
|
193 |
public void setXMLEntity(XMLEntity xml) { |
194 |
super.setXMLEntity(xml);
|
195 |
numColumns=xml.getIntProperty("numColumns");
|
196 |
numRows=xml.getIntProperty("numRows");
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* DOCUMENT ME!
|
201 |
*
|
202 |
* @param xml DOCUMENT ME!
|
203 |
* @param l DOCUMENT ME!
|
204 |
*/
|
205 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
206 |
// TODO Auto-generated method stub
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* DOCUMENT ME!
|
211 |
*
|
212 |
* @return DOCUMENT ME!
|
213 |
*/
|
214 |
public String getNameFFrame() { |
215 |
return PluginServices.getText(this, "box") + num; |
216 |
} |
217 |
|
218 |
/**
|
219 |
* DOCUMENT ME!
|
220 |
*
|
221 |
* @return DOCUMENT ME!
|
222 |
*/
|
223 |
public int getNumColumns() { |
224 |
return numColumns;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* DOCUMENT ME!
|
229 |
*
|
230 |
* @param numColumns DOCUMENT ME!
|
231 |
*/
|
232 |
public void setNumColumns(int numColumns) { |
233 |
this.numColumns = numColumns;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* DOCUMENT ME!
|
238 |
*
|
239 |
* @return DOCUMENT ME!
|
240 |
*/
|
241 |
public int getNumRows() { |
242 |
return numRows;
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* DOCUMENT ME!
|
247 |
*
|
248 |
* @param numRows DOCUMENT ME!
|
249 |
*/
|
250 |
public void setNumRows(int numRows) { |
251 |
this.numRows = numRows;
|
252 |
} |
253 |
|
254 |
public void calculateTable(Rectangle2D r) { |
255 |
double wC = r.getWidth() / numColumns;
|
256 |
double hR = r.getHeight() / numRows;
|
257 |
int rows = numRows;
|
258 |
clearFFrames(); |
259 |
for (int i = 0; i < numColumns; i++) { |
260 |
for (int j = 0; j < rows; j++) { |
261 |
double x=r.getX() + (wC * i);
|
262 |
double y=r.getY() + (hR * j);
|
263 |
double w=wC;
|
264 |
double h=hR;
|
265 |
Rectangle2D rBasic=new Rectangle2D.Double(x,y,w,h); |
266 |
FFrameBasic basic=new FFrameBasic(rBasic);
|
267 |
basic.setLayout(getLayout()); |
268 |
addFFrame(basic); |
269 |
} |
270 |
} |
271 |
} |
272 |
|
273 |
public void selectFFrame(boolean b) { |
274 |
selectFFrameBasic=b; |
275 |
} |
276 |
|
277 |
public IFFrame joinFFrame() {
|
278 |
IFFrame[] fframes=this.getFFrames(); |
279 |
Rectangle2D r=null; |
280 |
|
281 |
for (int i=fframes.length-1;i>=0;i--){ |
282 |
if (fframes[i].getSelected()!=IFFrame.NOSELECT){
|
283 |
if (r==null){ |
284 |
r=(Rectangle2D)fframes[i].getBoundBox().clone();
|
285 |
}else{
|
286 |
r.add(fframes[i].getBoundBox()); |
287 |
} |
288 |
this.removeFFrame(i);
|
289 |
} |
290 |
|
291 |
//removeFFrame(fframes[i]);
|
292 |
} |
293 |
if (r!=null){ |
294 |
//Layout layout=(Layout)PluginServices.getMDIManager().getActiveView();
|
295 |
IFFrame fframe=new FFrameBasic(r);
|
296 |
fframe.setLayout(getLayout()); |
297 |
this.addFFrame(fframe);
|
298 |
return this; |
299 |
} |
300 |
|
301 |
return null; |
302 |
} |
303 |
|
304 |
/*
|
305 |
public int getSelected() {
|
306 |
// if (!selectFFrameBasic)
|
307 |
return super.getSelected();
|
308 |
// IFFrame[] fframes=getFFrames();
|
309 |
// for (int i = 0;i<fframes.length;i++){
|
310 |
// int selection=fframes[i].getSelected();
|
311 |
// if (selection>0){
|
312 |
// return selection;
|
313 |
// }
|
314 |
// }
|
315 |
// return 0;
|
316 |
|
317 |
}
|
318 |
*/
|
319 |
public void setSelected(Point2D p,MouseEvent e) { |
320 |
if (!selectFFrameBasic)
|
321 |
super.setSelected(p,e);
|
322 |
else{
|
323 |
setSelectedGroup(p,e); |
324 |
} |
325 |
} |
326 |
|
327 |
public boolean contains(Point2D p) { |
328 |
if (!selectFFrameBasic)
|
329 |
return super.contains(p); |
330 |
return contains(p);
|
331 |
} |
332 |
|
333 |
public void drawHandlers(Graphics2D g) { |
334 |
if (!selectFFrameBasic)
|
335 |
super.drawHandlers(g);
|
336 |
else{
|
337 |
drawHandlersGroup(g); |
338 |
|
339 |
} |
340 |
} |
341 |
|
342 |
public int getContains(Point2D p) { |
343 |
if (!selectFFrameBasic)
|
344 |
return super.getContains(p); |
345 |
return getContainsGroup(p);
|
346 |
} |
347 |
|
348 |
public Rectangle2D getMovieRect(int difx, int dify) { |
349 |
//TODO Esto de momento lo dejo que no se pueda mover
|
350 |
//cuando se tiene seleccionada la herramienta de selecci?n de un FFrameBasic.
|
351 |
Rectangle2D r= super.getMovieRect(difx,dify); |
352 |
if (!selectFFrameBasic)
|
353 |
return r;
|
354 |
r= super.getMovieRect(0,0); |
355 |
return r;
|
356 |
} |
357 |
|
358 |
public Rectangle2D getMovieRectGroup(int difX, int difY) { |
359 |
Rectangle2D r=null; |
360 |
IFFrame[] fframes = getFFrames();
|
361 |
ArrayList selected=new ArrayList(); |
362 |
for (int i = 0; i < fframes.length; i++) { |
363 |
IFFrame fframe = fframes[i]; |
364 |
if (fframe.getSelected()!=IFFrame.NOSELECT){
|
365 |
selected.add(fframe); |
366 |
} |
367 |
} |
368 |
|
369 |
for (int i = 0; i < selected.size(); i++) { |
370 |
|
371 |
if (i==0){ |
372 |
r=((IFFrame)selected.get(i)).getMovieRect(difX,difY); |
373 |
}else
|
374 |
r.add(((IFFrame)selected.get(i)).getMovieRect(difX,difY)); |
375 |
} |
376 |
return r;
|
377 |
} |
378 |
|
379 |
public int getContainsGroup(Point2D p) { |
380 |
ArrayList selected=new ArrayList(); |
381 |
IFFrame[] fframes = getFFrames();
|
382 |
for (int i = 0; i < fframes.length; i++) { |
383 |
IFFrame fframe = fframes[i]; |
384 |
int contains=fframe.getContains(p);
|
385 |
if (contains != IFFrame.NOSELECT) {
|
386 |
if (contains == IFFrame.RECT){
|
387 |
selected.add(fframe); |
388 |
}else{
|
389 |
return contains;
|
390 |
} |
391 |
} |
392 |
} |
393 |
if (selected.size()>0){ |
394 |
return ((IFFrame)selected.get(0)).getContains(p); |
395 |
} |
396 |
return 0; |
397 |
} |
398 |
|
399 |
/**
|
400 |
* Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
401 |
* par?metro.
|
402 |
*
|
403 |
* @param g Graphics sobre el que dibujar.
|
404 |
*/
|
405 |
public void drawHandlersGroup(Graphics2D g) { |
406 |
int size = 8; |
407 |
g.setColor(Color.gray);
|
408 |
IFFrame[] fframes=getFFrames();
|
409 |
for (int i = 0; i < fframes.length; i++) { |
410 |
IFFrame fframe = fframes[i]; |
411 |
if (fframe.getSelected()!=IFFrame.NOSELECT){
|
412 |
Rectangle2D r = fframe.getBoundingBox(null); |
413 |
Point2D p = new Point2D.Double(); |
414 |
g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2), |
415 |
r.getY() + (r.getHeight() / 2));
|
416 |
|
417 |
AffineTransform atRotate = new AffineTransform(); |
418 |
atRotate.rotate(Math.toRadians(getRotation()),
|
419 |
r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
420 |
|
421 |
g.fillRect((int) r.getX() - size/2, (int) r.getY() - size/2, size, size); |
422 |
atRotate.transform(new Point2D.Double(r.getX() - size/2, r.getY() - size/2), |
423 |
p); |
424 |
no.setRect((int) p.getX(), (int) p.getY(), size, size); |
425 |
|
426 |
g.fillRect((int) r.getMaxX()- size/2, (int) r.getY() - size/2, size, size); |
427 |
atRotate.transform(new Point2D.Double(r.getMaxX()-size/2, r.getY() - size/2), p); |
428 |
ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
429 |
|
430 |
g.fillRect((int) r.getX() - size/2, (int) r.getMaxY()-size/2, size, size); |
431 |
atRotate.transform(new Point2D.Double(r.getX() - size/2, r.getMaxY()-size/2), p); |
432 |
so.setRect((int) p.getX(), (int) p.getY(), size, size); |
433 |
|
434 |
g.fillRect((int) r.getMaxX()-size/2, (int) r.getMaxY()-size/2, size, size); |
435 |
atRotate.transform(new Point2D.Double(r.getMaxX()-size/2, r.getMaxY()-size/2), p); |
436 |
se.setRect((int) p.getX(), (int) p.getY(), size, size); |
437 |
|
438 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size/2, |
439 |
size, size); |
440 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
441 |
r.getY() - size/2), p);
|
442 |
n.setRect((int) p.getX(), (int) p.getY(), size, size); |
443 |
|
444 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY()-size/2, size, |
445 |
size); |
446 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
447 |
r.getMaxY()-size/2), p);
|
448 |
s.setRect((int) p.getX(), (int) p.getY(), size, size); |
449 |
|
450 |
g.fillRect((int) r.getX() - size/2, (int) r.getCenterY() - (size / 2), |
451 |
size, size); |
452 |
atRotate.transform(new Point2D.Double(r.getX() - size/2, |
453 |
r.getCenterY() - (size / 2)), p);
|
454 |
o.setRect((int) p.getX(), (int) p.getY(), size, size); |
455 |
|
456 |
g.fillRect((int) r.getMaxX()-size/2, (int) r.getCenterY() - (size / 2), size, |
457 |
size); |
458 |
atRotate.transform(new Point2D.Double(r.getMaxX()-size/2, |
459 |
r.getCenterY() - (size / 2)), p);
|
460 |
e.setRect((int) p.getX()-size/2, (int) p.getY()-size/2, size, size); |
461 |
g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2), |
462 |
r.getY() + (r.getHeight() / 2));
|
463 |
} |
464 |
} |
465 |
|
466 |
} |
467 |
|
468 |
/* public void drawHandlersGroup(Graphics2D g) {
|
469 |
g.setColor(Color.gray);
|
470 |
IFFrame[] fframes=getFFrames();
|
471 |
for (int i = 0; i < fframes.length; i++) {
|
472 |
IFFrame fframe = fframes[i];
|
473 |
if (fframe.getSelected()!=IFFrame.NOSELECT){
|
474 |
fframe.drawHandlers(g);
|
475 |
}
|
476 |
}
|
477 |
}
|
478 |
*/
|
479 |
public boolean containsGroup(Point2D p) { |
480 |
IFFrame[] fframes=getFFrames();
|
481 |
for (int i = 0; i < fframes.length; i++) { |
482 |
IFFrame fframe = fframes[i]; |
483 |
if (fframe.contains(p)){
|
484 |
return true; |
485 |
} |
486 |
} |
487 |
return false; |
488 |
} |
489 |
|
490 |
public void setSelectedGroup(Point2D p, MouseEvent e) { |
491 |
IFFrame[] fframes = getFFrames();
|
492 |
if (!e.isShiftDown()) {
|
493 |
for (int j = 0; j < fframes.length; j++) { |
494 |
fframes[j].setSelected(false);
|
495 |
} |
496 |
for (int i = 0; i < fframes.length; i++) { |
497 |
IFFrame fframe = fframes[i]; |
498 |
//if ((fframe.getSelected() == IFFrame.NOSELECT)) {
|
499 |
fframe.setSelected(p, e); |
500 |
//}
|
501 |
} |
502 |
}else{
|
503 |
for (int i = 0; i < fframes.length; i++) { |
504 |
IFFrame fframe = fframes[i]; |
505 |
if (fframe.contains(p)) {
|
506 |
if ((fframe.getSelected() == IFFrame.NOSELECT)) {
|
507 |
fframe.setSelected(p, e); |
508 |
} else {
|
509 |
fframe.setSelected(false);
|
510 |
} |
511 |
} |
512 |
} |
513 |
} |
514 |
} |
515 |
|
516 |
public int getSelectedGroup() { |
517 |
return 0; |
518 |
} |
519 |
|
520 |
public Image getMapCursor(Point2D p) { |
521 |
if (!selectFFrameBasic)
|
522 |
return super.getMapCursor(p); |
523 |
return getMapCursorGroup(p);
|
524 |
} |
525 |
public Image getMapCursorGroup(Point2D p){ |
526 |
int select = getContains(p);
|
527 |
switch (select) {
|
528 |
case (RECT):
|
529 |
return iMove;
|
530 |
} |
531 |
return null; |
532 |
} |
533 |
|
534 |
public IFFrameDialog getPropertyDialog() {
|
535 |
return new FFrameBoxDialog(getLayout(),this); |
536 |
} |
537 |
|
538 |
} |