root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / tools / behavior / LayoutRectangleBehavior.java @ 9392
History | View | Annotate | Download (5.03 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.Point; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.event.MouseEvent; |
48 |
import java.awt.geom.AffineTransform; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
import java.awt.image.BufferedImage; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
54 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
55 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities; |
56 |
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutRectangleListener; |
57 |
import com.iver.cit.gvsig.project.documents.layout.tools.listener.LayoutToolListener; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Behaviour que espera un listener de tipo LayoutRectangleListener.
|
62 |
*
|
63 |
* @author Vicente Caballero Navarro
|
64 |
*/
|
65 |
public class LayoutRectangleBehavior extends LayoutBehavior { |
66 |
private LayoutRectangleListener listener;
|
67 |
private boolean dragged=false; |
68 |
|
69 |
/**
|
70 |
* Crea un nuevo RectangleBehavior.
|
71 |
*
|
72 |
* @param zili listener.
|
73 |
*/
|
74 |
public LayoutRectangleBehavior(LayoutRectangleListener lrl) {
|
75 |
listener = lrl; |
76 |
} |
77 |
|
78 |
/**
|
79 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
80 |
*/
|
81 |
public void paintComponent(Graphics g) { |
82 |
BufferedImage img = getLayoutControl().getImage();
|
83 |
BufferedImage imgRuler=getLayoutControl().getImgRuler();
|
84 |
g.drawImage(img, 0, 0, getLayoutControl()); |
85 |
g.drawImage(imgRuler, 0, 0, getLayoutControl()); |
86 |
g.setColor(Color.black);
|
87 |
g.setXORMode(Color.white);
|
88 |
|
89 |
// Borramos el anterior
|
90 |
Rectangle r = new Rectangle(); |
91 |
|
92 |
// Dibujamos el actual
|
93 |
if (dragged && (getLayoutControl().getFirstPoint() != null) && (getLayoutControl().getLastPoint() != null)) { |
94 |
r.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), getLayoutControl().getLastPoint()); |
95 |
g.drawRect(r.x, r.y, r.width, r.height); |
96 |
} |
97 |
g.setPaintMode(); |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Reimplementaci?n del m?todo mousePressed de Behavior.
|
102 |
*
|
103 |
* @param e MouseEvent
|
104 |
* @throws BehaviorException
|
105 |
*/
|
106 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
107 |
super.mousePressed(e);
|
108 |
if (listener.cancelDrawing()) {
|
109 |
//getLayout().cancelDrawing();
|
110 |
} |
111 |
getLayoutControl().repaint(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Reimplementaci?n del m?todo mouseReleased de Behavior.
|
116 |
*
|
117 |
* @param e MouseEvent
|
118 |
*
|
119 |
* @throws BehaviorException Excepci?n lanzada cuando el Behavior.
|
120 |
*/
|
121 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
122 |
super.mouseReleased(e);
|
123 |
dragged=false;
|
124 |
if (getLayoutControl().getFirstPoint() == null) return; |
125 |
Point2D p1;
|
126 |
Point2D p2;
|
127 |
Point pScreen = getLayoutControl().getLastPoint();
|
128 |
|
129 |
AffineTransform at = getLayoutControl().getAT();
|
130 |
|
131 |
p1 = FLayoutUtilities.toSheetPoint(getLayoutControl().getFirstPoint(), at); |
132 |
p2 = FLayoutUtilities.toSheetPoint(pScreen, at); |
133 |
|
134 |
if (e.getButton() == MouseEvent.BUTTON1) { |
135 |
// Fijamos el nuevo extent
|
136 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
137 |
r.setFrameFromDiagonal(p1, p2); |
138 |
|
139 |
Rectangle2D rectPixel = new Rectangle(); |
140 |
rectPixel.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), pScreen); |
141 |
|
142 |
RectangleEvent event = new RectangleEvent(r, e, rectPixel);
|
143 |
listener.rectangle(event); |
144 |
} |
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 |
dragged=true;
|
157 |
getLayoutControl().repaint(); |
158 |
} |
159 |
|
160 |
/**
|
161 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
162 |
*/
|
163 |
public void setListener(LayoutToolListener listener) { |
164 |
this.listener = (LayoutRectangleListener) listener;
|
165 |
} |
166 |
|
167 |
/**
|
168 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
169 |
*/
|
170 |
public LayoutToolListener getListener() {
|
171 |
return listener;
|
172 |
} |
173 |
|
174 |
public boolean isAdjustable() { |
175 |
return true; |
176 |
} |
177 |
} |