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