svn-gvsig-desktop / branches / v06 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutFunctions.java @ 4813
History | View | Annotate | Download (8.15 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.FFrameGraphics; |
55 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup; |
56 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend; |
57 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth; |
58 |
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture; |
59 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar; |
60 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText; |
61 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
62 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Funciones utilizadas desde la clase EventsHandler.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*/
|
70 |
public class FLayoutFunctions { |
71 |
private Layout layout = null; |
72 |
|
73 |
/**
|
74 |
* Crea un nuevo FLayoutFunctions.
|
75 |
*
|
76 |
* @param l Referencia al Layout.
|
77 |
*/
|
78 |
public FLayoutFunctions(Layout l) {
|
79 |
layout = l; |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Gestiona la herramienta de selecci?n sobre el Mapa.
|
84 |
*/
|
85 |
public void setSelect() { |
86 |
IFFrame fframe = null;
|
87 |
boolean isUpdate = false; |
88 |
|
89 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
90 |
fframe = (IFFrame) layout.getFFrames().get(i); |
91 |
|
92 |
int difx = (layout.getLastPoint().x - layout.getFirstPoint().x);
|
93 |
int dify = (layout.getLastPoint().y - layout.getFirstPoint().y);
|
94 |
|
95 |
if (((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) && |
96 |
(fframe.getSelected() != IFFrame.NOSELECT)) { |
97 |
Rectangle2D rectangle = fframe.getMovieRect(difx, dify);
|
98 |
|
99 |
if (layout.isCuadricula()) {
|
100 |
//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
|
101 |
FLayoutUtilities.setRectGrid(rectangle, |
102 |
layout.getAtributes().getUnitInPixelsX(), |
103 |
layout.getAtributes().getUnitInPixelsY(), layout.getAT()); |
104 |
} |
105 |
|
106 |
if (fframe instanceof FFrameGroup) { |
107 |
((FFrameGroup) fframe).setAt(layout.getAT()); |
108 |
} |
109 |
|
110 |
fframe.setBoundBox(FLayoutUtilities.toSheetRect(rectangle, |
111 |
layout.getAT())); |
112 |
isUpdate = true;
|
113 |
} |
114 |
Rectangle rect=null; |
115 |
if (layout.getReSel()==null){ |
116 |
rect=new Rectangle(); |
117 |
rect.setFrameFromDiagonal(layout.getFirstPoint(), layout.getLastPoint()); |
118 |
}else{
|
119 |
rect=layout.getReSel(); |
120 |
} |
121 |
if (layout.isReSel() &&
|
122 |
(rect.contains(fframe.getBoundingBox( |
123 |
layout.getAT())))) { |
124 |
fframe.setSelected(true);
|
125 |
} |
126 |
|
127 |
if (isUpdate) {
|
128 |
layout.setStatus(Layout.DESACTUALIZADO); |
129 |
} else {
|
130 |
layout.setStatus(Layout.ACTUALIZADO); |
131 |
} |
132 |
} |
133 |
|
134 |
layout.setIsReSel(true);
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* A?ade un fframe al Layout del tipo preseleccionado y abre el di?logo
|
139 |
* para configurar las caracter?sticas.
|
140 |
*/
|
141 |
public void setFFrame() { |
142 |
IFFrame fframe = null;
|
143 |
boolean isadd = false; |
144 |
|
145 |
if (layout.getTool() == Layout.RECTANGLEVIEW) {
|
146 |
fframe = new FFrameView();
|
147 |
((FFrameView)fframe).setLayout(layout); |
148 |
isadd = true;
|
149 |
} else if (layout.getTool() == Layout.RECTANGLEPICTURE) { |
150 |
fframe = new FFramePicture();
|
151 |
isadd = true;
|
152 |
} else if (layout.getTool() == Layout.RECTANGLESCALEBAR) { |
153 |
fframe = new FFrameScaleBar();
|
154 |
isadd = true;
|
155 |
} else if (layout.getTool() == Layout.RECTANGLELEGEND) { |
156 |
fframe = new FFrameLegend();
|
157 |
isadd = true;
|
158 |
} else if (layout.getTool() == Layout.RECTANGLETEXT) { |
159 |
fframe = new FFrameText();
|
160 |
isadd = true;
|
161 |
} else if (layout.getTool() == Layout.RECTANGLENORTH) { |
162 |
fframe = new FFrameNorth();
|
163 |
isadd = true;
|
164 |
} else if ((layout.getTool() == Layout.RECTANGLESIMPLE) || |
165 |
(layout.getTool() == Layout.LINE) || |
166 |
(layout.getTool() == Layout.POLYLINE) || |
167 |
(layout.getTool() == Layout.POLYGON) || |
168 |
(layout.getTool() == Layout.CIRCLE) || |
169 |
(layout.getTool() == Layout.POINT)) { |
170 |
////fframe = new FFrameGraphics(layout.getLine());
|
171 |
fframe = new FFrameGraphics();
|
172 |
isadd = true;
|
173 |
((FFrameGraphics) fframe).update(layout.getTool(), layout.getAT()); |
174 |
} |
175 |
|
176 |
if (isadd) {
|
177 |
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); |
178 |
int tolerance=20; |
179 |
if (isCorrectSize(tolerance,layout.getFirstPoint(),layout.getLastPoint())){
|
180 |
r.setFrameFromDiagonal(layout.getFirstPoint(), layout.getLastPoint()); |
181 |
}else{
|
182 |
Point2D p1=layout.getFirstPoint();
|
183 |
p1=new Point2D.Double(p1.getX()+tolerance,p1.getY()+tolerance); |
184 |
r.setFrameFromDiagonal(layout.getFirstPoint(),p1); |
185 |
} |
186 |
|
187 |
if (layout.isCuadricula()) {
|
188 |
//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
|
189 |
FLayoutUtilities.setRectGrid(r, |
190 |
layout.getAtributes().getUnitInPixelsX(), |
191 |
layout.getAtributes().getUnitInPixelsY(), layout.getAT()); |
192 |
} |
193 |
|
194 |
fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT())); |
195 |
|
196 |
if (layout.openFFrameDialog(fframe)) {
|
197 |
layout.addFFrame(fframe, true,true); |
198 |
} |
199 |
}else{
|
200 |
///fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT()));
|
201 |
} |
202 |
} |
203 |
|
204 |
/**
|
205 |
* Pan sobre la vista del FFrameView.
|
206 |
*
|
207 |
* @param p1 Punto inicial del desplazamiento.
|
208 |
* @param p2 Punto final del desplazamiento.
|
209 |
*/
|
210 |
public void setViewPan(Point p1, Point p2) { |
211 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
212 |
if (layout.getFFrames().get(i) instanceof FFrameView) { |
213 |
FFrameView fframe = (FFrameView) layout.getFFrames().get(i); |
214 |
|
215 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
216 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
217 |
Rectangle2D extent = fframe.getFMap().getViewPort()
|
218 |
.getExtent(); |
219 |
Point2D mp1 = toMapPoint(p1, fframe.getAt());
|
220 |
Point2D mp2 = toMapPoint(p2, fframe.getAt());
|
221 |
r.x = extent.getX() - (mp2.getX() - mp1.getX()); |
222 |
r.y = extent.getY() - (mp2.getY() - mp1.getY()); |
223 |
r.width = extent.getWidth(); |
224 |
r.height = extent.getHeight(); |
225 |
fframe.getFMap().getViewPort().setExtent(r); |
226 |
} |
227 |
} |
228 |
} |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Devuelve un punto real a partir de un punto en pixels sobre la vista.
|
233 |
*
|
234 |
* @param pScreen Punto en pixels.
|
235 |
* @param at1 Matriz de transformaci?n.
|
236 |
*
|
237 |
* @return Punto real.
|
238 |
*/
|
239 |
public Point2D.Double toMapPoint(Point2D pScreen, AffineTransform at1) { |
240 |
Point2D.Double pWorld = new Point2D.Double(); |
241 |
|
242 |
AffineTransform at;
|
243 |
|
244 |
try {
|
245 |
at = at1.createInverse(); |
246 |
at.transform(pScreen, pWorld); |
247 |
} catch (NoninvertibleTransformException e) { |
248 |
// throw new RuntimeException(e);
|
249 |
} |
250 |
|
251 |
return pWorld;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* Devuelve true si el rectangulo formado por los dos puntos que se pasan
|
256 |
* como par?metro es superior a la tolerancia.
|
257 |
*
|
258 |
* @param tolerance Tolerancia
|
259 |
* @param p1 Punto inicial del rect?ngulo.
|
260 |
* @param p2 Punto final del rect?ngulo.
|
261 |
*
|
262 |
* @return True si el tama?o es correcto.
|
263 |
*/
|
264 |
private boolean isCorrectSize(int tolerance, Point2D p1, Point2D p2) { |
265 |
if (Math.abs(p2.getX()) < (Math.abs(p1.getX()) + tolerance)) { |
266 |
return false; |
267 |
} else if (Math.abs(p2.getY()) < (Math.abs(p1.getY()) + tolerance)) { |
268 |
return false; |
269 |
} |
270 |
return true; |
271 |
} |
272 |
} |