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 @ 1714
History | View | Annotate | Download (6.26 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 static java.awt.Event.CTRL_MASK; |
26 |
import java.awt.Graphics; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.Rectangle; |
29 |
import java.awt.event.MouseEvent; |
30 |
import java.awt.geom.Rectangle2D; |
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 |
private int modifiers; |
47 |
|
48 |
/**
|
49 |
* Crea un nuevo LayoutSelectBehavior.
|
50 |
*
|
51 |
* @param pli
|
52 |
* listener.
|
53 |
*/
|
54 |
public LayoutSelectBehavior(LayoutMoveListener lpl) {
|
55 |
listener = lpl; |
56 |
} |
57 |
|
58 |
/**
|
59 |
* @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
60 |
*/
|
61 |
@Override
|
62 |
public void paintComponent(Graphics g) { |
63 |
getLayoutControl().getLayoutDraw().drawRectangle((Graphics2D) g);
|
64 |
|
65 |
g.drawImage(getLayoutControl().getImage(), 0, 0, getLayoutControl() |
66 |
.getComponent()); |
67 |
|
68 |
if (getLayoutControl().isReSel()) {
|
69 |
Rectangle reSel = getLayoutControl().getReSel();
|
70 |
reSel = new Rectangle(); |
71 |
reSel.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), |
72 |
getLayoutControl().getLastPoint()); |
73 |
g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height); |
74 |
} |
75 |
IFFrame[] frames =
|
76 |
getLayoutControl().getLayoutContext().getSelectedFFrames(); |
77 |
for (IFFrame frame : frames) {
|
78 |
g.setColor(Color.black);
|
79 |
frame.drawHandlers((Graphics2D) g);
|
80 |
int difx =
|
81 |
(getLayoutControl().getLastPoint().x - getLayoutControl() |
82 |
.getFirstPoint().x); |
83 |
int dify =
|
84 |
(getLayoutControl().getLastPoint().y - getLayoutControl() |
85 |
.getFirstPoint().y); |
86 |
if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) { |
87 |
Rectangle2D rectangle = frame.getMovieRect(difx, dify, !((modifiers & CTRL_MASK) != 0)); |
88 |
if (rectangle == null) |
89 |
return;
|
90 |
((Graphics2D) g).rotate(Math.toRadians(frame.getRotation()), rectangle.getX() |
91 |
+ (rectangle.getWidth() / 2), rectangle.getY()
|
92 |
+ (rectangle.getHeight() / 2));
|
93 |
if (dragged && !getLayoutControl().isReSel()) {
|
94 |
g.drawRect((int) rectangle.getMinX(),
|
95 |
(int) rectangle.getMinY(), (int) rectangle.getWidth(), |
96 |
(int) rectangle.getHeight());
|
97 |
} |
98 |
((Graphics2D) g).rotate(Math.toRadians(-frame.getRotation()), rectangle.getX() |
99 |
+ (rectangle.getWidth() / 2), rectangle.getY()
|
100 |
+ (rectangle.getHeight() / 2));
|
101 |
} |
102 |
} |
103 |
|
104 |
g.drawImage(getLayoutControl().getImgRuler(), 0, 0, getLayoutControl() |
105 |
.getComponent()); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* @throws BehaviorException
|
110 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
111 |
*/
|
112 |
@Override
|
113 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
114 |
super.mousePressed(e);
|
115 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
116 |
listener.press(event); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Reimplementaci?n del m?todo mouseReleased de Behavior.
|
121 |
*
|
122 |
* @param e
|
123 |
* MouseEvent
|
124 |
*
|
125 |
* @throws BehaviorException
|
126 |
* Excepci?n lanzada cuando el Behavior.
|
127 |
*/
|
128 |
@Override
|
129 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
130 |
super.mouseReleased(e);
|
131 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
132 |
listener.release(event); |
133 |
dragged = false;
|
134 |
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Reimplementaci?n del m?todo mouseDragged de Behavior.
|
139 |
*
|
140 |
* @param e
|
141 |
* MouseEvent
|
142 |
* @throws BehaviorException
|
143 |
*/
|
144 |
@Override
|
145 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
146 |
super.mouseDragged(e);
|
147 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
148 |
listener.drag(event); |
149 |
dragged = true;
|
150 |
modifiers = e.getModifiers(); |
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 |
@Override
|
164 |
public LayoutToolListener getListener() {
|
165 |
return listener;
|
166 |
} |
167 |
|
168 |
@Override
|
169 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
170 |
super.mouseClicked(e);
|
171 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
172 |
listener.click(event); |
173 |
} |
174 |
|
175 |
@Override
|
176 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
177 |
super.mouseMoved(e);
|
178 |
PointEvent event = new PointEvent(e.getPoint(), e);
|
179 |
listener.move(event); |
180 |
} |
181 |
} |