root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / tools / behavior / LayoutSelectBehavior.java @ 9392
History | View | Annotate | Download (6.04 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 |
package com.iver.cit.gvsig.project.documents.layout.tools.behavior; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Graphics; |
45 |
import java.awt.Graphics2D; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.event.MouseEvent; |
48 |
import java.awt.geom.Rectangle2D; |
49 |
|
50 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
51 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
52 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
53 |
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutMoveListener; |
54 |
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutToolListener; |
55 |
|
56 |
|
57 |
/**
|
58 |
* Behaviour que espera un listener de tipo LayoutMoveListener.
|
59 |
*
|
60 |
* @author Vicente Caballero Navarro
|
61 |
*/
|
62 |
public class LayoutSelectBehavior extends LayoutBehavior { |
63 |
private LayoutMoveListener listener;
|
64 |
private boolean dragged=false; |
65 |
|
66 |
/**
|
67 |
* Crea un nuevo LayoutSelectBehavior.
|
68 |
*
|
69 |
* @param pli listener.
|
70 |
*/
|
71 |
public LayoutSelectBehavior(LayoutMoveListener lpl) {
|
72 |
listener = lpl; |
73 |
} |
74 |
|
75 |
/**
|
76 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
77 |
*/
|
78 |
public void paintComponent(Graphics g) { |
79 |
getLayoutControl().getLayoutDraw().drawRectangle((Graphics2D) g);
|
80 |
|
81 |
g.drawImage(getLayoutControl().getImage(), 0, 0, getLayoutControl()); |
82 |
|
83 |
//getLayout().getLayoutDraw().drawHandlers((Graphics2D) g, Color.black);
|
84 |
if (getLayoutControl().isReSel()) {
|
85 |
Rectangle reSel=getLayoutControl().getReSel();
|
86 |
reSel=new Rectangle(); |
87 |
reSel.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), getLayoutControl().getLastPoint()); |
88 |
g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height); |
89 |
} |
90 |
IFFrame[] frames = getLayoutControl().getLayoutContext().getFFrameSelected();
|
91 |
for (int i = 0; i < frames.length; i++) { |
92 |
g.setColor(Color.black);
|
93 |
frames[i].drawHandlers((Graphics2D) g);
|
94 |
int difx = (getLayoutControl().getLastPoint().x - getLayoutControl().getFirstPoint().x);
|
95 |
int dify = (getLayoutControl().getLastPoint().y - getLayoutControl().getFirstPoint().y);
|
96 |
if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) { |
97 |
Rectangle2D rectangle = frames[i].getMovieRect(difx, dify);
|
98 |
if (rectangle == null) |
99 |
return;
|
100 |
((Graphics2D) g).rotate(Math.toRadians(frames[i] |
101 |
.getRotation()), rectangle.getX() |
102 |
+ (rectangle.getWidth() / 2), rectangle.getY()
|
103 |
+ (rectangle.getHeight() / 2));
|
104 |
|
105 |
if (rectangle != null && dragged && !getLayoutControl().isReSel()) { |
106 |
g.drawRect((int) rectangle.getMinX(), (int) rectangle |
107 |
.getMinY(), (int) rectangle.getWidth(),
|
108 |
(int) rectangle.getHeight());
|
109 |
} |
110 |
|
111 |
((Graphics2D) g).rotate(Math.toRadians(-frames[i] |
112 |
.getRotation()), rectangle.getX() |
113 |
+ (rectangle.getWidth() / 2), rectangle.getY()
|
114 |
+ (rectangle.getHeight() / 2));
|
115 |
|
116 |
} |
117 |
} |
118 |
|
119 |
//g.setClip(rClip);
|
120 |
g.drawImage(getLayoutControl().getImgRuler(), 0, 0, getLayoutControl()); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* @throws BehaviorException
|
125 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
126 |
*/
|
127 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
128 |
super.mousePressed(e);
|
129 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
130 |
listener.press(event); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Reimplementaci?n del m?todo mouseReleased de Behavior.
|
135 |
*
|
136 |
* @param e MouseEvent
|
137 |
*
|
138 |
* @throws BehaviorException Excepci?n lanzada cuando el Behavior.
|
139 |
*/
|
140 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
141 |
super.mouseReleased(e);
|
142 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
143 |
listener.release(event); |
144 |
dragged=false;
|
145 |
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Reimplementaci?n del m?todo mouseDragged de Behavior.
|
150 |
*
|
151 |
* @param e MouseEvent
|
152 |
* @throws BehaviorException
|
153 |
*/
|
154 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
155 |
super.mouseDragged(e);
|
156 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
157 |
listener.drag(event); |
158 |
dragged=true;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
163 |
*/
|
164 |
public void setListener(LayoutToolListener listener) { |
165 |
this.listener = (LayoutMoveListener) listener;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
170 |
*/
|
171 |
public LayoutToolListener getListener() {
|
172 |
return listener;
|
173 |
} |
174 |
|
175 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
176 |
super.mouseClicked(e);
|
177 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
178 |
listener.click(event); |
179 |
} |
180 |
|
181 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
182 |
super.mouseMoved(e);
|
183 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
184 |
listener.move(event); |
185 |
} |
186 |
} |