root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / tools / behavior / LayoutRectangleBehavior.java @ 29598
History | View | Annotate | Download (6.12 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 org.gvsig.app.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.Point; |
47 |
import java.awt.Rectangle; |
48 |
import java.awt.event.MouseEvent; |
49 |
import java.awt.geom.AffineTransform; |
50 |
import java.awt.geom.Point2D; |
51 |
import java.awt.geom.Rectangle2D; |
52 |
import java.awt.image.BufferedImage; |
53 |
|
54 |
import org.gvsig.app.gui.styling.SymbolSelector; |
55 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
56 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
57 |
import org.gvsig.app.project.documents.layout.tools.listener.LayoutRectangleListener; |
58 |
import org.gvsig.app.project.documents.layout.tools.listener.LayoutToolListener; |
59 |
import org.gvsig.fmap.geom.GeometryLocator; |
60 |
import org.gvsig.fmap.geom.GeometryManager; |
61 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
62 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
63 |
import org.gvsig.fmap.geom.primitive.Envelope; |
64 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
65 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
66 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
67 |
import org.slf4j.Logger; |
68 |
import org.slf4j.LoggerFactory; |
69 |
|
70 |
|
71 |
|
72 |
/**
|
73 |
* Behaviour que espera un listener de tipo LayoutRectangleListener.
|
74 |
*
|
75 |
* @author Vicente Caballero Navarro
|
76 |
*/
|
77 |
public class LayoutRectangleBehavior extends LayoutBehavior { |
78 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
79 |
private static final Logger logger = LoggerFactory.getLogger(LayoutRectangleBehavior.class); |
80 |
private LayoutRectangleListener listener;
|
81 |
private boolean dragged=false; |
82 |
|
83 |
/**
|
84 |
* Crea un nuevo RectangleBehavior.
|
85 |
*
|
86 |
* @param zili listener.
|
87 |
*/
|
88 |
public LayoutRectangleBehavior(LayoutRectangleListener lrl) {
|
89 |
listener = lrl; |
90 |
} |
91 |
|
92 |
/**
|
93 |
* @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#paintComponent(java.awt.Graphics)
|
94 |
*/
|
95 |
public void paintComponent(Graphics g) { |
96 |
BufferedImage img = getLayoutControl().getImage();
|
97 |
BufferedImage imgRuler=getLayoutControl().getImgRuler();
|
98 |
g.drawImage(img, 0, 0, getLayoutControl()); |
99 |
g.drawImage(imgRuler, 0, 0, getLayoutControl()); |
100 |
g.setColor(Color.black);
|
101 |
g.setXORMode(Color.white);
|
102 |
|
103 |
// Borramos el anterior
|
104 |
Rectangle r = new Rectangle(); |
105 |
|
106 |
// Dibujamos el actual
|
107 |
if (dragged && (getLayoutControl().getFirstPoint() != null) && (getLayoutControl().getLastPoint() != null)) { |
108 |
r.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), getLayoutControl().getLastPoint()); |
109 |
g.drawRect(r.x, r.y, r.width, r.height); |
110 |
} |
111 |
IFFrame[] frames = getLayoutControl().getLayoutContext().getFFrameSelected();
|
112 |
for (int i = 0; i < frames.length; i++) { |
113 |
g.setColor(Color.black);
|
114 |
frames[i].drawHandlers((Graphics2D) g);
|
115 |
} |
116 |
g.setPaintMode(); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Reimplementaci?n del m?todo mousePressed de Behavior.
|
121 |
*
|
122 |
* @param e MouseEvent
|
123 |
* @throws BehaviorException
|
124 |
*/
|
125 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
126 |
super.mousePressed(e);
|
127 |
if (listener.cancelDrawing()) {
|
128 |
//getLayout().cancelDrawing();
|
129 |
} |
130 |
getLayoutControl().repaint(); |
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 |
dragged=false;
|
143 |
if (getLayoutControl().getFirstPoint() == null) return; |
144 |
Point2D p1;
|
145 |
Point2D p2;
|
146 |
Point pScreen = getLayoutControl().getLastPoint();
|
147 |
|
148 |
AffineTransform at = getLayoutControl().getAT();
|
149 |
|
150 |
p1 = FLayoutUtilities.toSheetPoint(getLayoutControl().getFirstPoint(), at); |
151 |
p2 = FLayoutUtilities.toSheetPoint(pScreen, at); |
152 |
|
153 |
if (e.getButton() == MouseEvent.BUTTON1) { |
154 |
// Fijamos el nuevo extent
|
155 |
// Rectangle2D.Double r = new Rectangle2D.Double();
|
156 |
// r.setFrameFromDiagonal(p1, p2);
|
157 |
Envelope r; |
158 |
try {
|
159 |
r = geomManager.createEnvelope(p1.getX(),p1.getY(),p2.getX(),p2.getY(), SUBTYPES.GEOM2D); |
160 |
Rectangle2D rectPixel = new Rectangle(); |
161 |
rectPixel.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), pScreen); |
162 |
|
163 |
EnvelopeEvent event = new EnvelopeEvent(r, e, rectPixel);
|
164 |
listener.rectangle(event); |
165 |
} catch (CreateEnvelopeException e1) {
|
166 |
logger.error("Error creating the envelope", e);
|
167 |
} |
168 |
} |
169 |
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Reimplementaci?n del m?todo mouseDragged de Behavior.
|
174 |
*
|
175 |
* @param e MouseEvent
|
176 |
* @throws BehaviorException
|
177 |
*/
|
178 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
179 |
super.mouseDragged(e);
|
180 |
dragged=true;
|
181 |
getLayoutControl().repaint(); |
182 |
} |
183 |
|
184 |
/**
|
185 |
* @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener)
|
186 |
*/
|
187 |
public void setListener(LayoutToolListener listener) { |
188 |
this.listener = (LayoutRectangleListener) listener;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* @see org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior#getListener()
|
193 |
*/
|
194 |
public LayoutToolListener getListener() {
|
195 |
return listener;
|
196 |
} |
197 |
|
198 |
public boolean isAdjustable() { |
199 |
return true; |
200 |
} |
201 |
} |