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