svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameTable.java @ 4779
History | View | Annotate | Download (15.1 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$
|
44 |
* $Log$
|
45 |
* Revision 1.1 2006-04-10 06:37:07 caballero
|
46 |
* FFrameTable
|
47 |
*
|
48 |
* Revision 1.1 2006/01/12 12:32:04 caballero
|
49 |
* box
|
50 |
*
|
51 |
*
|
52 |
*/
|
53 |
package com.iver.cit.gvsig.gui.layout.fframes; |
54 |
|
55 |
import java.awt.Color; |
56 |
import java.awt.Cursor; |
57 |
import java.awt.Graphics2D; |
58 |
import java.awt.event.MouseEvent; |
59 |
import java.awt.geom.AffineTransform; |
60 |
import java.awt.geom.Point2D; |
61 |
import java.awt.geom.Rectangle2D; |
62 |
import java.awt.geom.Point2D.Double; |
63 |
import java.awt.image.BufferedImage; |
64 |
import java.util.ArrayList; |
65 |
import java.util.BitSet; |
66 |
|
67 |
import com.iver.andami.PluginServices; |
68 |
import com.iver.cit.gvsig.fmap.DriverException; |
69 |
import com.iver.cit.gvsig.gui.layout.Layout; |
70 |
import com.iver.cit.gvsig.gui.project.SaveException; |
71 |
import com.iver.utiles.XMLEntity; |
72 |
|
73 |
|
74 |
/**
|
75 |
* DOCUMENT ME!
|
76 |
*
|
77 |
* @author Vicente Caballero Navarro
|
78 |
*/
|
79 |
public class FFrameTable extends FFrameGroup implements IFFrameGroupSelectable{ |
80 |
private int numColumns = 2; |
81 |
private int numRows = 2; |
82 |
private boolean selectFFrameBasic=false; |
83 |
|
84 |
/**
|
85 |
* DOCUMENT ME!
|
86 |
*
|
87 |
* @param g DOCUMENT ME!
|
88 |
* @param at DOCUMENT ME!
|
89 |
* @param rv DOCUMENT ME!
|
90 |
* @param imgBase DOCUMENT ME!
|
91 |
*
|
92 |
* @throws DriverException DOCUMENT ME!
|
93 |
*/
|
94 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
95 |
BufferedImage imgBase) throws DriverException { |
96 |
Rectangle2D.Double r = getBoundingBox(at);
|
97 |
g.setColor(Color.black);
|
98 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
99 |
r.y + (r.height / 2));
|
100 |
drawRectangles(g,at,rv,imgBase); |
101 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
102 |
r.y + (r.height / 2));
|
103 |
super.draw(g,at,rv,imgBase);
|
104 |
} |
105 |
|
106 |
private void drawRectangles(Graphics2D g, AffineTransform at,Rectangle2D rv,BufferedImage imgBase) { |
107 |
IFFrame[] fframes=getFFrames();
|
108 |
for (int i =0;i<fframes.length;i++){ |
109 |
FFrameBasic basic=(FFrameBasic)fframes[i]; |
110 |
try {
|
111 |
basic.draw(g,at,rv,imgBase); |
112 |
} catch (DriverException e) {
|
113 |
e.printStackTrace(); |
114 |
} |
115 |
} |
116 |
} |
117 |
|
118 |
/**
|
119 |
* DOCUMENT ME!
|
120 |
*
|
121 |
* @param r DOCUMENT ME!
|
122 |
* @param g DOCUMENT ME!
|
123 |
*/
|
124 |
public void drawBox(Rectangle2D r, Graphics2D g) { |
125 |
calculateTable(r); |
126 |
IFFrame[] fframes=getFFrames();
|
127 |
for (int i =0;i<fframes.length;i++){ |
128 |
FFrameBasic basic=(FFrameBasic)fframes[i]; |
129 |
try {
|
130 |
basic.draw(g,new AffineTransform(),null,null); |
131 |
} catch (DriverException e) {
|
132 |
e.printStackTrace(); |
133 |
} |
134 |
} |
135 |
} |
136 |
|
137 |
/**
|
138 |
* DOCUMENT ME!
|
139 |
*
|
140 |
* @param g DOCUMENT ME!
|
141 |
* @param at DOCUMENT ME!
|
142 |
*
|
143 |
* @throws DriverException DOCUMENT ME!
|
144 |
*/
|
145 |
public void print(Graphics2D g, AffineTransform at) |
146 |
throws DriverException {
|
147 |
draw(g, at, null, null); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* DOCUMENT ME!
|
152 |
*
|
153 |
* @return DOCUMENT ME!
|
154 |
*
|
155 |
* @throws SaveException DOCUMENT ME!
|
156 |
*/
|
157 |
public XMLEntity getXMLEntity() throws SaveException { |
158 |
XMLEntity xml = super.getXMLEntity();
|
159 |
xml.putProperty("numColumns",numColumns);
|
160 |
xml.putProperty("numRows",numRows);
|
161 |
return xml;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* DOCUMENT ME!
|
166 |
*
|
167 |
* @param xml DOCUMENT ME!
|
168 |
*/
|
169 |
public void setXMLEntity(XMLEntity xml) { |
170 |
super.setXMLEntity(xml);
|
171 |
numColumns=xml.getIntProperty("numColumns");
|
172 |
numRows=xml.getIntProperty("numRows");
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* DOCUMENT ME!
|
177 |
*
|
178 |
* @param xml DOCUMENT ME!
|
179 |
* @param l DOCUMENT ME!
|
180 |
*/
|
181 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
182 |
// TODO Auto-generated method stub
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* DOCUMENT ME!
|
187 |
*
|
188 |
* @return DOCUMENT ME!
|
189 |
*/
|
190 |
public String getNameFFrame() { |
191 |
return PluginServices.getText(this, "box") + num; |
192 |
} |
193 |
|
194 |
/**
|
195 |
* DOCUMENT ME!
|
196 |
*
|
197 |
* @return DOCUMENT ME!
|
198 |
*/
|
199 |
public int getNumColumns() { |
200 |
return numColumns;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* DOCUMENT ME!
|
205 |
*
|
206 |
* @param numColumns DOCUMENT ME!
|
207 |
*/
|
208 |
public void setNumColumns(int numColumns) { |
209 |
this.numColumns = numColumns;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* DOCUMENT ME!
|
214 |
*
|
215 |
* @return DOCUMENT ME!
|
216 |
*/
|
217 |
public int getNumRows() { |
218 |
return numRows;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* DOCUMENT ME!
|
223 |
*
|
224 |
* @param numRows DOCUMENT ME!
|
225 |
*/
|
226 |
public void setNumRows(int numRows) { |
227 |
this.numRows = numRows;
|
228 |
} |
229 |
|
230 |
public void calculateTable(Rectangle2D r) { |
231 |
double wC = r.getWidth() / numColumns;
|
232 |
double hR = r.getHeight() / numRows;
|
233 |
int rows = numRows;
|
234 |
clearFFrames(); |
235 |
for (int i = 0; i < numColumns; i++) { |
236 |
for (int j = 0; j < rows; j++) { |
237 |
double x=r.getX() + (wC * i);
|
238 |
double y=r.getY() + (hR * j);
|
239 |
double w=wC;
|
240 |
double h=hR;
|
241 |
Rectangle2D rBasic=new Rectangle2D.Double(x,y,w,h); |
242 |
FFrameBasic basic=new FFrameBasic(rBasic);
|
243 |
addFFrame(basic); |
244 |
} |
245 |
} |
246 |
} |
247 |
|
248 |
public void selectFFrame(boolean b) { |
249 |
selectFFrameBasic=b; |
250 |
} |
251 |
|
252 |
public IFFrame joinFFrame() {
|
253 |
IFFrame[] fframes=this.getFFrames(); |
254 |
Rectangle2D r=null; |
255 |
|
256 |
for (int i=fframes.length-1;i>=0;i--){ |
257 |
if (fframes[i].getSelected()!=IFFrame.NOSELECT){
|
258 |
if (r==null){ |
259 |
r=(Rectangle2D)fframes[i].getBoundBox().clone();
|
260 |
}else{
|
261 |
r.add(fframes[i].getBoundBox()); |
262 |
} |
263 |
this.removeFFrame(i);
|
264 |
} |
265 |
|
266 |
//removeFFrame(fframes[i]);
|
267 |
} |
268 |
if (r!=null){ |
269 |
//Layout layout=(Layout)PluginServices.getMDIManager().getActiveView();
|
270 |
IFFrame fframe=new FFrameBasic(r);
|
271 |
this.addFFrame(fframe);
|
272 |
return this; |
273 |
} |
274 |
|
275 |
return null; |
276 |
} |
277 |
|
278 |
/*
|
279 |
public int getSelected() {
|
280 |
// if (!selectFFrameBasic)
|
281 |
return super.getSelected();
|
282 |
// IFFrame[] fframes=getFFrames();
|
283 |
// for (int i = 0;i<fframes.length;i++){
|
284 |
// int selection=fframes[i].getSelected();
|
285 |
// if (selection>0){
|
286 |
// return selection;
|
287 |
// }
|
288 |
// }
|
289 |
// return 0;
|
290 |
|
291 |
}
|
292 |
*/
|
293 |
public void setSelected(Double p,MouseEvent e) { |
294 |
if (!selectFFrameBasic)
|
295 |
super.setSelected(p,e);
|
296 |
else{
|
297 |
setSelectedGroup(p,e); |
298 |
} |
299 |
} |
300 |
|
301 |
public boolean contains(Double p) { |
302 |
if (!selectFFrameBasic)
|
303 |
return super.contains(p); |
304 |
else{
|
305 |
return contains(p);
|
306 |
} |
307 |
|
308 |
} |
309 |
|
310 |
public void drawHandlers(Graphics2D g) { |
311 |
if (!selectFFrameBasic)
|
312 |
super.drawHandlers(g);
|
313 |
else{
|
314 |
drawHandlersGroup(g); |
315 |
|
316 |
} |
317 |
} |
318 |
|
319 |
public int getContains(Double p) { |
320 |
if (!selectFFrameBasic)
|
321 |
return super.getContains(p); |
322 |
else {
|
323 |
return getContainsGroup(p);
|
324 |
} |
325 |
} |
326 |
|
327 |
public Rectangle2D getMovieRect(int difx, int dify) { |
328 |
//TODO Esto de momento lo dejo que no se pueda mover
|
329 |
//cuando se tiene seleccionada la herramienta de selecci?n de un FFrameBasic.
|
330 |
Rectangle2D r= super.getMovieRect(difx,dify); |
331 |
if (!selectFFrameBasic)
|
332 |
return r;
|
333 |
else {
|
334 |
r= super.getMovieRect(0,0); |
335 |
//r=getMovieRectGroup(difx,dify);
|
336 |
} |
337 |
|
338 |
return r;
|
339 |
} |
340 |
|
341 |
public Rectangle2D getMovieRectGroup(int difX, int difY) { |
342 |
Rectangle2D r=null; |
343 |
IFFrame[] fframes = getFFrames();
|
344 |
ArrayList selected=new ArrayList(); |
345 |
for (int i = 0; i < fframes.length; i++) { |
346 |
IFFrame fframe = fframes[i]; |
347 |
if (fframe.getSelected()!=IFFrame.NOSELECT){
|
348 |
selected.add(fframe); |
349 |
} |
350 |
} |
351 |
|
352 |
for (int i = 0; i < selected.size(); i++) { |
353 |
|
354 |
if (i==0){ |
355 |
r=((IFFrame)selected.get(i)).getMovieRect(difX,difY); |
356 |
}else
|
357 |
r.add(((IFFrame)selected.get(i)).getMovieRect(difX,difY)); |
358 |
} |
359 |
return r;
|
360 |
} |
361 |
|
362 |
public int getContainsGroup(Double p) { |
363 |
ArrayList selected=new ArrayList(); |
364 |
IFFrame[] fframes = getFFrames();
|
365 |
for (int i = 0; i < fframes.length; i++) { |
366 |
IFFrame fframe = fframes[i]; |
367 |
int contains=fframe.getContains(p);
|
368 |
if (contains != IFFrame.NOSELECT) {
|
369 |
if (contains == IFFrame.RECT){
|
370 |
selected.add(fframe); |
371 |
}else{
|
372 |
return contains;
|
373 |
} |
374 |
} |
375 |
} |
376 |
if (selected.size()>0){ |
377 |
return ((IFFrame)selected.get(0)).getContains(p); |
378 |
} |
379 |
return 0; |
380 |
} |
381 |
|
382 |
/**
|
383 |
* Dibuja los handlers sobre el boundingBox en el graphics que se pasa como
|
384 |
* par?metro.
|
385 |
*
|
386 |
* @param g Graphics sobre el que dibujar.
|
387 |
*/
|
388 |
public void drawHandlersGroup(Graphics2D g) { |
389 |
int size = 8; |
390 |
g.setColor(Color.gray);
|
391 |
IFFrame[] fframes=getFFrames();
|
392 |
for (int i = 0; i < fframes.length; i++) { |
393 |
IFFrame fframe = fframes[i]; |
394 |
if (fframe.getSelected()!=IFFrame.NOSELECT){
|
395 |
Rectangle2D r = fframe.getBoundingBox(null); |
396 |
Point2D p = new Point2D.Double(); |
397 |
g.rotate(Math.toRadians(getRotation()), r.getX() + (r.getWidth() / 2), |
398 |
r.getY() + (r.getHeight() / 2));
|
399 |
|
400 |
AffineTransform atRotate = new AffineTransform(); |
401 |
atRotate.rotate(Math.toRadians(getRotation()),
|
402 |
r.getX() + (r.getWidth() / 2), r.getY() + (r.getHeight() / 2)); |
403 |
|
404 |
g.fillRect((int) r.getX() - size/2, (int) r.getY() - size/2, size, size); |
405 |
atRotate.transform(new Point2D.Double(r.getX() - size/2, r.getY() - size/2), |
406 |
p); |
407 |
no.setRect((int) p.getX(), (int) p.getY(), size, size); |
408 |
|
409 |
g.fillRect((int) r.getMaxX()- size/2, (int) r.getY() - size/2, size, size); |
410 |
atRotate.transform(new Point2D.Double(r.getMaxX()-size/2, r.getY() - size/2), p); |
411 |
ne.setRect((int) p.getX(), (int) p.getY(), size, size); |
412 |
|
413 |
g.fillRect((int) r.getX() - size/2, (int) r.getMaxY()-size/2, size, size); |
414 |
atRotate.transform(new Point2D.Double(r.getX() - size/2, r.getMaxY()-size/2), p); |
415 |
so.setRect((int) p.getX(), (int) p.getY(), size, size); |
416 |
|
417 |
g.fillRect((int) r.getMaxX()-size/2, (int) r.getMaxY()-size/2, size, size); |
418 |
atRotate.transform(new Point2D.Double(r.getMaxX()-size/2, r.getMaxY()-size/2), p); |
419 |
se.setRect((int) p.getX(), (int) p.getY(), size, size); |
420 |
|
421 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getY() - size/2, |
422 |
size, size); |
423 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
424 |
r.getY() - size/2), p);
|
425 |
n.setRect((int) p.getX(), (int) p.getY(), size, size); |
426 |
|
427 |
g.fillRect((int) r.getCenterX() - (size / 2), (int) r.getMaxY()-size/2, size, |
428 |
size); |
429 |
atRotate.transform(new Point2D.Double(r.getCenterX() - (size / 2), |
430 |
r.getMaxY()-size/2), p);
|
431 |
s.setRect((int) p.getX(), (int) p.getY(), size, size); |
432 |
|
433 |
g.fillRect((int) r.getX() - size/2, (int) r.getCenterY() - (size / 2), |
434 |
size, size); |
435 |
atRotate.transform(new Point2D.Double(r.getX() - size/2, |
436 |
r.getCenterY() - (size / 2)), p);
|
437 |
o.setRect((int) p.getX(), (int) p.getY(), size, size); |
438 |
|
439 |
g.fillRect((int) r.getMaxX()-size/2, (int) r.getCenterY() - (size / 2), size, |
440 |
size); |
441 |
atRotate.transform(new Point2D.Double(r.getMaxX()-size/2, |
442 |
r.getCenterY() - (size / 2)), p);
|
443 |
e.setRect((int) p.getX()-size/2, (int) p.getY()-size/2, size, size); |
444 |
g.rotate(Math.toRadians(-getRotation()), r.getX() + (r.getWidth() / 2), |
445 |
r.getY() + (r.getHeight() / 2));
|
446 |
} |
447 |
} |
448 |
|
449 |
} |
450 |
|
451 |
/* public void drawHandlersGroup(Graphics2D g) {
|
452 |
g.setColor(Color.gray);
|
453 |
IFFrame[] fframes=getFFrames();
|
454 |
for (int i = 0; i < fframes.length; i++) {
|
455 |
IFFrame fframe = fframes[i];
|
456 |
if (fframe.getSelected()!=IFFrame.NOSELECT){
|
457 |
fframe.drawHandlers(g);
|
458 |
}
|
459 |
}
|
460 |
}
|
461 |
*/
|
462 |
public boolean containsGroup(Double p) { |
463 |
IFFrame[] fframes=getFFrames();
|
464 |
for (int i = 0; i < fframes.length; i++) { |
465 |
IFFrame fframe = fframes[i]; |
466 |
if (fframe.contains(p)){
|
467 |
return true; |
468 |
} |
469 |
} |
470 |
return false; |
471 |
} |
472 |
|
473 |
public void setSelectedGroup(Double p, MouseEvent e) { |
474 |
IFFrame[] fframes = getFFrames();
|
475 |
if (!e.isShiftDown()) {
|
476 |
for (int j = 0; j < fframes.length; j++) { |
477 |
fframes[j].setSelected(false);
|
478 |
} |
479 |
for (int i = 0; i < fframes.length; i++) { |
480 |
IFFrame fframe = fframes[i]; |
481 |
//if ((fframe.getSelected() == IFFrame.NOSELECT)) {
|
482 |
fframe.setSelected(p, e); |
483 |
//}
|
484 |
} |
485 |
}else{
|
486 |
for (int i = 0; i < fframes.length; i++) { |
487 |
IFFrame fframe = fframes[i]; |
488 |
if (fframe.contains(p)) {
|
489 |
if ((fframe.getSelected() == IFFrame.NOSELECT)) {
|
490 |
fframe.setSelected(p, e); |
491 |
} else {
|
492 |
fframe.setSelected(false);
|
493 |
} |
494 |
} |
495 |
} |
496 |
} |
497 |
} |
498 |
|
499 |
public int getSelectedGroup() { |
500 |
return 0; |
501 |
} |
502 |
|
503 |
public Cursor getMapCursor(Double p) { |
504 |
if (!selectFFrameBasic)
|
505 |
return super.getMapCursor(p); |
506 |
else {
|
507 |
return getMapCursorGroup(p);
|
508 |
} |
509 |
|
510 |
} |
511 |
public Cursor getMapCursorGroup(Double p){ |
512 |
int select = getContains(p);
|
513 |
switch (select) {
|
514 |
case (RECT):
|
515 |
return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); |
516 |
} |
517 |
return null; |
518 |
} |
519 |
|
520 |
} |