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