svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / tools / behavior / LayoutSelectBehavior.java @ 236
History | View | Annotate | Download (6.14 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.tools.behavior; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.Graphics; |
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.Rectangle; |
28 |
import java.awt.event.MouseEvent; |
29 |
import java.awt.geom.Rectangle2D; |
30 |
|
31 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
32 |
import org.gvsig.app.project.documents.layout.tools.listener.LayoutMoveListener; |
33 |
import org.gvsig.app.project.documents.layout.tools.listener.LayoutToolListener; |
34 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
35 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
36 |
|
37 |
/**
|
38 |
* Behaviour que espera un listener de tipo LayoutMoveListener.
|
39 |
*
|
40 |
* @author Vicente Caballero Navarro
|
41 |
*/
|
42 |
public class LayoutSelectBehavior extends LayoutBehavior { |
43 |
|
44 |
private LayoutMoveListener listener;
|
45 |
private boolean dragged = false; |
46 |
|
47 |
/**
|
48 |
* Crea un nuevo LayoutSelectBehavior.
|
49 |
*
|
50 |
* @param pli
|
51 |
* listener.
|
52 |
*/
|
53 |
public LayoutSelectBehavior(LayoutMoveListener lpl) {
|
54 |
listener = lpl; |
55 |
} |
56 |
|
57 |
/**
|
58 |
* @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
59 |
*/
|
60 |
public void paintComponent(Graphics g) { |
61 |
getLayoutControl().getLayoutDraw().drawRectangle((Graphics2D) g);
|
62 |
|
63 |
g.drawImage(getLayoutControl().getImage(), 0, 0, getLayoutControl() |
64 |
.getComponent()); |
65 |
|
66 |
if (getLayoutControl().isReSel()) {
|
67 |
Rectangle reSel = getLayoutControl().getReSel();
|
68 |
reSel = new Rectangle(); |
69 |
reSel.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), |
70 |
getLayoutControl().getLastPoint()); |
71 |
g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height); |
72 |
} |
73 |
IFFrame[] frames =
|
74 |
getLayoutControl().getLayoutContext().getSelectedFFrames(); |
75 |
for (int i = 0; i < frames.length; i++) { |
76 |
g.setColor(Color.black);
|
77 |
frames[i].drawHandlers((Graphics2D) g);
|
78 |
int difx =
|
79 |
(getLayoutControl().getLastPoint().x - getLayoutControl() |
80 |
.getFirstPoint().x); |
81 |
int dify =
|
82 |
(getLayoutControl().getLastPoint().y - getLayoutControl() |
83 |
.getFirstPoint().y); |
84 |
if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) { |
85 |
Rectangle2D rectangle = frames[i].getMovieRect(difx, dify);
|
86 |
if (rectangle == null) |
87 |
return;
|
88 |
((Graphics2D) g).rotate(
|
89 |
Math.toRadians(frames[i].getRotation()), rectangle.getX()
|
90 |
+ (rectangle.getWidth() / 2), rectangle.getY()
|
91 |
+ (rectangle.getHeight() / 2));
|
92 |
|
93 |
if (rectangle != null && dragged |
94 |
&& !getLayoutControl().isReSel()) { |
95 |
g.drawRect((int) rectangle.getMinX(),
|
96 |
(int) rectangle.getMinY(), (int) rectangle.getWidth(), |
97 |
(int) rectangle.getHeight());
|
98 |
} |
99 |
|
100 |
((Graphics2D) g).rotate(
|
101 |
Math.toRadians(-frames[i].getRotation()), rectangle.getX()
|
102 |
+ (rectangle.getWidth() / 2), rectangle.getY()
|
103 |
+ (rectangle.getHeight() / 2));
|
104 |
|
105 |
} |
106 |
} |
107 |
|
108 |
g.drawImage(getLayoutControl().getImgRuler(), 0, 0, getLayoutControl() |
109 |
.getComponent()); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* @throws BehaviorException
|
114 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
115 |
*/
|
116 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
117 |
super.mousePressed(e);
|
118 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
119 |
listener.press(event); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Reimplementaci?n del m?todo mouseReleased de Behavior.
|
124 |
*
|
125 |
* @param e
|
126 |
* MouseEvent
|
127 |
*
|
128 |
* @throws BehaviorException
|
129 |
* Excepci?n lanzada cuando el Behavior.
|
130 |
*/
|
131 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
132 |
super.mouseReleased(e);
|
133 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
134 |
listener.release(event); |
135 |
dragged = false;
|
136 |
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Reimplementaci?n del m?todo mouseDragged de Behavior.
|
141 |
*
|
142 |
* @param e
|
143 |
* MouseEvent
|
144 |
* @throws BehaviorException
|
145 |
*/
|
146 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
147 |
super.mouseDragged(e);
|
148 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
149 |
listener.drag(event); |
150 |
dragged = true;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
155 |
*/
|
156 |
public void setListener(LayoutToolListener listener) { |
157 |
this.listener = (LayoutMoveListener) listener;
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#getListener()
|
162 |
*/
|
163 |
public LayoutToolListener getListener() {
|
164 |
return listener;
|
165 |
} |
166 |
|
167 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
168 |
super.mouseClicked(e);
|
169 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
170 |
listener.click(event); |
171 |
} |
172 |
|
173 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
174 |
super.mouseMoved(e);
|
175 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
176 |
listener.move(event); |
177 |
} |
178 |
} |