svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutFunctions.java @ 4203
History | View | Annotate | Download (9.84 KB)
1 |
/*
|
---|---|
2 |
* Created on 16-sep-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout; |
46 |
|
47 |
import java.awt.Point; |
48 |
import java.awt.Rectangle; |
49 |
import java.awt.geom.AffineTransform; |
50 |
import java.awt.geom.NoninvertibleTransformException; |
51 |
import java.awt.geom.Point2D; |
52 |
import java.awt.geom.Rectangle2D; |
53 |
|
54 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameBox; |
55 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics; |
56 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup; |
57 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend; |
58 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth; |
59 |
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture; |
60 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar; |
61 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText; |
62 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
63 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
64 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameLayoutDependence; |
65 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameUseFMap; |
66 |
|
67 |
|
68 |
/**
|
69 |
* Funciones utilizadas desde la clase EventsHandler.
|
70 |
*
|
71 |
* @author Vicente Caballero Navarro
|
72 |
*/
|
73 |
public class FLayoutFunctions { |
74 |
private Layout layout = null; |
75 |
|
76 |
/**
|
77 |
* Crea un nuevo FLayoutFunctions.
|
78 |
*
|
79 |
* @param l Referencia al Layout.
|
80 |
*/
|
81 |
public FLayoutFunctions(Layout l) {
|
82 |
layout = l; |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Gestiona la herramienta de selecci?n sobre el Mapa.
|
87 |
*/
|
88 |
public void setSelect() { |
89 |
IFFrame fframe = null;
|
90 |
boolean isUpdate = false; |
91 |
|
92 |
for (int i = 0; i < layout.getFFrames().length; i++) { |
93 |
fframe = (IFFrame) layout.getFFrame(i); |
94 |
|
95 |
int difx = (layout.getLastPoint().x - layout.getFirstPoint().x);
|
96 |
int dify = (layout.getLastPoint().y - layout.getFirstPoint().y);
|
97 |
|
98 |
if (((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) && |
99 |
(fframe.getSelected() != IFFrame.NOSELECT)) { |
100 |
Rectangle2D rectangle = fframe.getMovieRect(difx, dify);
|
101 |
|
102 |
if (layout.isCuadricula()) {
|
103 |
//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
|
104 |
FLayoutUtilities.setRectGrid(rectangle, |
105 |
layout.getAtributes().getUnitInPixelsX(), |
106 |
layout.getAtributes().getUnitInPixelsY(), layout.getAT()); |
107 |
} |
108 |
|
109 |
if (fframe instanceof FFrameGroup) { |
110 |
((FFrameGroup) fframe).setAt(layout.getAT()); |
111 |
} |
112 |
IFFrame fframeAux=fframe.cloneFFrame(layout); |
113 |
fframeAux.setBoundBox(FLayoutUtilities.toSheetRect(rectangle, |
114 |
layout.getAT())); |
115 |
layout.getEFS().modifyFFrame(fframe,fframeAux); |
116 |
fframeAux.getBoundingBox(layout.getAT()); |
117 |
isUpdate = true;
|
118 |
} |
119 |
Rectangle rect=null; |
120 |
if (layout.getReSel()==null){ |
121 |
rect=new Rectangle(); |
122 |
rect.setFrameFromDiagonal(layout.getFirstPoint(), layout.getLastPoint()); |
123 |
}else{
|
124 |
rect=layout.getReSel(); |
125 |
} |
126 |
if (layout.isReSel() &&
|
127 |
(rect.contains(fframe.getBoundingBox( |
128 |
layout.getAT())))) { |
129 |
fframe.setSelected(true);
|
130 |
} |
131 |
|
132 |
if (isUpdate) {
|
133 |
layout.setStatus(Layout.DESACTUALIZADO); |
134 |
|
135 |
} else {
|
136 |
layout.setStatus(Layout.ACTUALIZADO); |
137 |
} |
138 |
} |
139 |
|
140 |
layout.updateFFrames(); |
141 |
layout.setIsReSel(true);
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* A?ade un fframe al Layout del tipo preseleccionado y abre el di?logo
|
146 |
* para configurar las caracter?sticas.
|
147 |
*/
|
148 |
public void setFFrame() { |
149 |
IFFrame fframe = null;
|
150 |
boolean isadd = false; |
151 |
|
152 |
if (layout.getTool() == Layout.RECTANGLEVIEW) {
|
153 |
fframe = new FFrameView();
|
154 |
((IFFrameLayoutDependence)fframe).setLayout(layout); |
155 |
isadd = true;
|
156 |
} else if (layout.getTool() == Layout.RECTANGLEPICTURE) { |
157 |
fframe = new FFramePicture();
|
158 |
isadd = true;
|
159 |
} else if (layout.getTool() == Layout.RECTANGLESCALEBAR) { |
160 |
fframe = new FFrameScaleBar();
|
161 |
isadd = true;
|
162 |
} else if (layout.getTool() == Layout.RECTANGLELEGEND) { |
163 |
fframe = new FFrameLegend();
|
164 |
isadd = true;
|
165 |
} else if (layout.getTool() == Layout.RECTANGLETEXT) { |
166 |
fframe = new FFrameText();
|
167 |
isadd = true;
|
168 |
} else if (layout.getTool() == Layout.RECTANGLENORTH) { |
169 |
fframe = new FFrameNorth();
|
170 |
isadd = true;
|
171 |
} else if (layout.getTool() == Layout.RECTANGLEBOX) { |
172 |
fframe = new FFrameBox();
|
173 |
isadd = true;
|
174 |
} else if ((layout.getTool() == Layout.LINE) || |
175 |
(layout.getTool() == Layout.POLYLINE) || |
176 |
(layout.getTool() == Layout.POLYGON) || |
177 |
(layout.getTool() == Layout.CIRCLE) || |
178 |
(layout.getTool() == Layout.RECTANGLESIMPLE) || |
179 |
(layout.getTool() == Layout.POINT)) { |
180 |
fframe = new FFrameGraphics();
|
181 |
((FFrameGraphics)fframe).setGeometryAdapter(layout.getGeometryAdapter()); |
182 |
isadd = false;
|
183 |
((FFrameGraphics) fframe).update(layout.getTool(), layout.getAT()); |
184 |
} /*else if ((layout.getTool() == Layout.POINT)){
|
185 |
fframe = new FFrameGraphics();
|
186 |
isadd = true;
|
187 |
((FFrameGraphics) fframe).update(layout.getTool(), layout.getAT());
|
188 |
}*/
|
189 |
if (isadd) {
|
190 |
Rectangle2D r = new Rectangle2D.Double(); //rectOrigin.x+m_PointAnt.x,rectOrigin.y+m_PointAnt.y,m_LastPoint.x-m_PointAnt.x,m_LastPoint.y-m_PointAnt.y); |
191 |
int tolerance=20; |
192 |
r=getRectangle(tolerance,layout.getFirstPoint(),layout.getLastPoint()); |
193 |
|
194 |
if (layout.isCuadricula()) {
|
195 |
//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
|
196 |
FLayoutUtilities.setRectGrid(r, |
197 |
layout.getAtributes().getUnitInPixelsX(), |
198 |
layout.getAtributes().getUnitInPixelsY(), layout.getAT()); |
199 |
} |
200 |
|
201 |
fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT())); |
202 |
|
203 |
if (layout.openFFrameDialog(fframe)) {
|
204 |
layout.addFFrame(fframe, true,true); |
205 |
} |
206 |
}else{
|
207 |
if (layout.getTool() == Layout.POINT){
|
208 |
Rectangle2D r=layout.getGeometryAdapter().getBounds2D();
|
209 |
double d=0.5;//FLayoutUtilities.toSheetDistance(50,layout.getAT()); |
210 |
r=new Rectangle2D.Double(r.getX()-d,r.getY()-d,d*2,d*2); |
211 |
fframe.setBoundBox(r); |
212 |
}else{
|
213 |
fframe.setBoundBox(layout.getGeometryAdapter().getBounds2D()); |
214 |
} |
215 |
layout.addFFrame(fframe, true,true); |
216 |
///fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT()));
|
217 |
} |
218 |
} |
219 |
|
220 |
private Rectangle2D getRectangle(int tolerance,Point2D first,Point2D last) { |
221 |
Rectangle2D r=new Rectangle2D.Double(); |
222 |
if (isCorrectSize(tolerance,layout.getFirstPoint(),layout.getLastPoint())){
|
223 |
Point2D fp=layout.getFirstPoint();
|
224 |
Point2D lp=layout.getLastPoint();
|
225 |
if (fp.getX()<lp.getX()){
|
226 |
if (fp.getY()<lp.getY()){
|
227 |
r.setRect(fp.getX(),fp.getY(),lp.getX()-fp.getX(),lp.getY()-fp.getY()); |
228 |
}else{
|
229 |
r.setRect(fp.getX(),lp.getY(),lp.getX()-fp.getX(),fp.getY()-lp.getY()); |
230 |
} |
231 |
}else{
|
232 |
if (fp.getY()>lp.getY()){
|
233 |
r.setRect(lp.getX(),lp.getY(),fp.getX()-lp.getX(),fp.getY()-lp.getY()); |
234 |
}else{
|
235 |
r.setRect(lp.getX(),fp.getY(),lp.getX()-fp.getX(),lp.getY()-fp.getY()); |
236 |
} |
237 |
} |
238 |
}else{
|
239 |
Point2D p1=layout.getFirstPoint();
|
240 |
p1=new Point2D.Double(p1.getX()+tolerance,p1.getY()+tolerance); |
241 |
r.setFrameFromDiagonal(layout.getFirstPoint(),p1); |
242 |
} |
243 |
return r;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* Pan sobre la vista del FFrameView.
|
248 |
*
|
249 |
* @param p1 Punto inicial del desplazamiento.
|
250 |
* @param p2 Punto final del desplazamiento.
|
251 |
*/
|
252 |
public void setViewPan(Point p1, Point p2) { |
253 |
for (int i = 0; i < layout.getFFrames().length; i++) { |
254 |
if (layout.getFFrame(i) instanceof IFFrameUseFMap) { |
255 |
IFFrameUseFMap fframe = (IFFrameUseFMap) layout.getFFrame(i); |
256 |
|
257 |
if (((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) {
|
258 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
259 |
Rectangle2D extent = fframe.getFMap().getViewPort()
|
260 |
.getExtent(); |
261 |
Point2D mp1 = toMapPoint(p1, fframe.getATMap());
|
262 |
Point2D mp2 = toMapPoint(p2, fframe.getATMap());
|
263 |
r.x = extent.getX() - (mp2.getX() - mp1.getX()); |
264 |
r.y = extent.getY() - (mp2.getY() - mp1.getY()); |
265 |
r.width = extent.getWidth(); |
266 |
r.height = extent.getHeight(); |
267 |
fframe.getFMap().getViewPort().setExtent(r); |
268 |
} |
269 |
} |
270 |
} |
271 |
} |
272 |
|
273 |
/**
|
274 |
* Devuelve un punto real a partir de un punto en pixels sobre la vista.
|
275 |
*
|
276 |
* @param pScreen Punto en pixels.
|
277 |
* @param at1 Matriz de transformaci?n.
|
278 |
*
|
279 |
* @return Punto real.
|
280 |
*/
|
281 |
public static Point2D.Double toMapPoint(Point2D pScreen, AffineTransform at1) { |
282 |
Point2D.Double pWorld = new Point2D.Double(); |
283 |
|
284 |
AffineTransform at;
|
285 |
|
286 |
try {
|
287 |
at = at1.createInverse(); |
288 |
at.transform(pScreen, pWorld); |
289 |
} catch (NoninvertibleTransformException e) { |
290 |
// throw new RuntimeException(e);
|
291 |
} |
292 |
|
293 |
return pWorld;
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* Devuelve true si el rectangulo formado por los dos puntos que se pasan
|
298 |
* como par?metro es superior a la tolerancia.
|
299 |
*
|
300 |
* @param tolerance Tolerancia
|
301 |
* @param p1 Punto inicial del rect?ngulo.
|
302 |
* @param p2 Punto final del rect?ngulo.
|
303 |
*
|
304 |
* @return True si el tama?o es correcto.
|
305 |
*/
|
306 |
private boolean isCorrectSize(int tolerance, Point2D p1, Point2D p2) { |
307 |
if (Math.abs(p2.getX()-p1.getX())<tolerance) { |
308 |
return false; |
309 |
} else if (Math.abs(p2.getY()-p1.getY())<tolerance) { |
310 |
return false; |
311 |
} |
312 |
return true; |
313 |
} |
314 |
} |