root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / FLayoutFunctions.java @ 12136
History | View | Annotate | Download (10.6 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.project.documents.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.Layout; |
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.FFrameOverView; |
60 |
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture; |
61 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar; |
62 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameTable; |
63 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText; |
64 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
65 |
import com.iver.cit.gvsig.project.documents.layout.commands.EditableFeatureSource; |
66 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
67 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence; |
68 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap; |
69 |
|
70 |
|
71 |
/**
|
72 |
* Funciones utilizadas desde la clase EventsHandler.
|
73 |
*
|
74 |
* @author Vicente Caballero Navarro
|
75 |
*/
|
76 |
public class FLayoutFunctions { |
77 |
private Layout layout = null; |
78 |
|
79 |
/**
|
80 |
* Crea un nuevo FLayoutFunctions.
|
81 |
*
|
82 |
* @param l Referencia al Layout.
|
83 |
*/
|
84 |
public FLayoutFunctions(Layout l) {
|
85 |
layout = l; |
86 |
} |
87 |
|
88 |
/**
|
89 |
* Gestiona la herramienta de selecci?n sobre el Mapa.
|
90 |
*/
|
91 |
public void setSelect() { |
92 |
IFFrame fframe = null;
|
93 |
boolean isUpdate = false; |
94 |
layout.updateFFrames(); |
95 |
IFFrame[] fframes=layout.getFFrames();
|
96 |
EditableFeatureSource efs=layout.getEFS(); |
97 |
efs.startComplexCommand(); |
98 |
for (int i = 0; i < fframes.length; i++) { |
99 |
fframe = fframes[i]; |
100 |
|
101 |
int difx = (layout.getLastPoint().x - layout.getFirstPoint().x);
|
102 |
int dify = (layout.getLastPoint().y - layout.getFirstPoint().y);
|
103 |
|
104 |
if (((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) && |
105 |
(fframe.getSelected() != IFFrame.NOSELECT)) { |
106 |
Rectangle2D rectangle = fframe.getLastMoveRect();
|
107 |
if (rectangle==null) |
108 |
return;
|
109 |
if (layout.isAdjustingToGrid()) {
|
110 |
//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
|
111 |
FLayoutUtilities.setRectGrid(rectangle, |
112 |
layout.getAtributes().getUnitInPixelsX(), |
113 |
layout.getAtributes().getUnitInPixelsY(), layout.getAT()); |
114 |
} |
115 |
|
116 |
if (fframe instanceof FFrameGroup) { |
117 |
((FFrameGroup) fframe).setAt(layout.getAT()); |
118 |
} |
119 |
|
120 |
IFFrame fframeAux=fframe.cloneFFrame(layout); |
121 |
fframeAux.setBoundBox(FLayoutUtilities.toSheetRect(rectangle, |
122 |
layout.getAT())); |
123 |
if (fframeAux instanceof IFFrameUseFMap) |
124 |
((IFFrameUseFMap)fframeAux).refresh(); |
125 |
efs.modifyFFrame(fframe,fframeAux); |
126 |
fframeAux.getBoundingBox(layout.getAT()); |
127 |
|
128 |
isUpdate = true;
|
129 |
} |
130 |
Rectangle rect=null; |
131 |
if (layout.getReSel()==null){ |
132 |
rect=new Rectangle(); |
133 |
rect.setFrameFromDiagonal(layout.getFirstPoint(), layout.getLastPoint()); |
134 |
}else{
|
135 |
rect=layout.getReSel(); |
136 |
} |
137 |
if (layout.isReSel() &&
|
138 |
(rect.contains(fframe.getBoundingBox( |
139 |
layout.getAT())))) { |
140 |
fframe.setSelected(true);
|
141 |
} |
142 |
|
143 |
if (isUpdate) {
|
144 |
layout.setStatus(Layout.DESACTUALIZADO); |
145 |
|
146 |
} else {
|
147 |
layout.setStatus(Layout.ACTUALIZADO); |
148 |
} |
149 |
} |
150 |
efs.endComplexCommand("move");
|
151 |
layout.updateFFrames(); |
152 |
layout.setIsReSel(true);
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* A?ade un fframe al Layout del tipo preseleccionado y abre el di?logo
|
157 |
* para configurar las caracter?sticas.
|
158 |
* @return TODO
|
159 |
*/
|
160 |
public IFFrame addFFrame() {
|
161 |
IFFrame fframe = null;
|
162 |
boolean isadd = false; |
163 |
|
164 |
if (layout.getTool() == Layout.RECTANGLEVIEW) {
|
165 |
fframe = new FFrameView();
|
166 |
((IFFrameLayoutDependence)fframe).setLayout(layout); |
167 |
isadd = true;
|
168 |
} else if (layout.getTool() == Layout.RECTANGLEOVERVIEW) { |
169 |
fframe = new FFrameOverView();
|
170 |
((IFFrameLayoutDependence)fframe).setLayout(layout); |
171 |
isadd = true;
|
172 |
} else if (layout.getTool() == Layout.RECTANGLEPICTURE) { |
173 |
fframe = new FFramePicture();
|
174 |
isadd = true;
|
175 |
} else if (layout.getTool() == Layout.RECTANGLESCALEBAR) { |
176 |
fframe = new FFrameScaleBar();
|
177 |
isadd = true;
|
178 |
} else if (layout.getTool() == Layout.RECTANGLELEGEND) { |
179 |
fframe = new FFrameLegend();
|
180 |
isadd = true;
|
181 |
} else if (layout.getTool() == Layout.RECTANGLETEXT) { |
182 |
fframe = new FFrameText();
|
183 |
isadd = true;
|
184 |
} else if (layout.getTool() == Layout.RECTANGLENORTH) { |
185 |
fframe = new FFrameNorth();
|
186 |
isadd = true;
|
187 |
} else if (layout.getTool() == Layout.RECTANGLEBOX) { |
188 |
fframe = new FFrameTable();
|
189 |
isadd = true;
|
190 |
} else if ((layout.getTool() == Layout.LINE) || |
191 |
(layout.getTool() == Layout.POLYLINE) || |
192 |
(layout.getTool() == Layout.POLYGON) || |
193 |
(layout.getTool() == Layout.CIRCLE) || |
194 |
(layout.getTool() == Layout.RECTANGLESIMPLE) || |
195 |
(layout.getTool() == Layout.POINT)) { |
196 |
fframe = new FFrameGraphics();
|
197 |
((FFrameGraphics)fframe).setGeometryAdapter(layout.getGeometryAdapter()); |
198 |
isadd = false;
|
199 |
((FFrameGraphics) fframe).update(layout.getTool(), layout.getAT()); |
200 |
} /*else if ((layout.getTool() == Layout.POINT)){
|
201 |
fframe = new FFrameGraphics();
|
202 |
isadd = true;
|
203 |
((FFrameGraphics) fframe).update(layout.getTool(), layout.getAT());
|
204 |
}*/
|
205 |
if (isadd) {
|
206 |
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); |
207 |
int tolerance=20; |
208 |
r=getRectangle(tolerance); |
209 |
|
210 |
if (layout.isAdjustingToGrid()) {
|
211 |
//cuadrar con la cuadr?cula dibujada y despu?s en el mouseReleased guardar ese rect?ngulo de la misma forma.
|
212 |
FLayoutUtilities.setRectGrid(r, |
213 |
layout.getAtributes().getUnitInPixelsX(), |
214 |
layout.getAtributes().getUnitInPixelsY(), layout.getAT()); |
215 |
} |
216 |
|
217 |
fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT())); |
218 |
IFFrame newFrame=layout.openFFrameDialog(fframe); |
219 |
if (newFrame!=null) { |
220 |
if (!layout.isEditGroup()){
|
221 |
layout.addFFrame(newFrame, true,true); |
222 |
} |
223 |
} |
224 |
}else{
|
225 |
if (layout.getTool() == Layout.POINT){
|
226 |
Rectangle2D r=layout.getGeometryAdapter().getBounds2D();
|
227 |
double d=0.5;//FLayoutUtilities.toSheetDistance(50,layout.getAT()); |
228 |
r=new Rectangle2D.Double(r.getX()-(d/2),r.getY()-d,d*2,d*2); |
229 |
fframe.setBoundBox(r); |
230 |
}else{
|
231 |
fframe.setBoundBox(layout.getGeometryAdapter().getBounds2D()); |
232 |
} |
233 |
layout.addFFrame(fframe, true,true); |
234 |
///fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layout.getAT()));
|
235 |
} |
236 |
return fframe;
|
237 |
} |
238 |
|
239 |
private Rectangle2D getRectangle(int tolerance) { |
240 |
Rectangle2D r=new Rectangle2D.Double(); |
241 |
if (isCorrectSize(tolerance,layout.getFirstPoint(),layout.getLastPoint())){
|
242 |
Point2D fp=layout.getFirstPoint();
|
243 |
Point2D lp=layout.getLastPoint();
|
244 |
if (fp.getX()<lp.getX()){
|
245 |
if (fp.getY()<lp.getY()){
|
246 |
r.setRect(fp.getX(),fp.getY(),lp.getX()-fp.getX(),lp.getY()-fp.getY()); |
247 |
}else{
|
248 |
r.setRect(fp.getX(),lp.getY(),lp.getX()-fp.getX(),fp.getY()-lp.getY()); |
249 |
} |
250 |
}else{
|
251 |
if (fp.getY()>lp.getY()){
|
252 |
r.setRect(lp.getX(),lp.getY(),fp.getX()-lp.getX(),fp.getY()-lp.getY()); |
253 |
}else{
|
254 |
r.setRect(lp.getX(),fp.getY(),lp.getX()-fp.getX(),lp.getY()-fp.getY()); |
255 |
} |
256 |
} |
257 |
}else{
|
258 |
Point2D p1=layout.getFirstPoint();
|
259 |
p1=new Point2D.Double(p1.getX()+tolerance,p1.getY()+tolerance); |
260 |
r.setFrameFromDiagonal(layout.getFirstPoint(),p1); |
261 |
} |
262 |
return r;
|
263 |
} |
264 |
|
265 |
/**
|
266 |
* Pan sobre la vista del FFrameView.
|
267 |
*
|
268 |
* @param p1 Punto inicial del desplazamiento.
|
269 |
* @param p2 Punto final del desplazamiento.
|
270 |
*/
|
271 |
public void setViewPan(Point p1, Point p2) { |
272 |
IFFrame[] fframes=layout.getFFrames();
|
273 |
for (int i = 0; i < fframes.length; i++) { |
274 |
if (fframes[i] instanceof IFFrameUseFMap) { |
275 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
276 |
|
277 |
if (((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) {
|
278 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
279 |
Rectangle2D extent = fframe.getMapContext().getViewPort()
|
280 |
.getExtent(); |
281 |
if (extent!=null){ |
282 |
Point2D mp1 = toMapPoint(p1, fframe.getATMap());
|
283 |
Point2D mp2 = toMapPoint(p2, fframe.getATMap());
|
284 |
r.x = extent.getX() - (mp2.getX() - mp1.getX()); |
285 |
r.y = extent.getY() - (mp2.getY() - mp1.getY()); |
286 |
r.width = extent.getWidth(); |
287 |
r.height = extent.getHeight(); |
288 |
fframe.getMapContext().getViewPort().setExtent(r); |
289 |
} |
290 |
} |
291 |
} |
292 |
} |
293 |
} |
294 |
|
295 |
/**
|
296 |
* Devuelve un punto real a partir de un punto en pixels sobre la vista.
|
297 |
*
|
298 |
* @param pScreen Punto en pixels.
|
299 |
* @param at1 Matriz de transformaci?n.
|
300 |
*
|
301 |
* @return Punto real.
|
302 |
*/
|
303 |
public static Point2D.Double toMapPoint(Point2D pScreen, AffineTransform at1) { |
304 |
Point2D.Double pWorld = new Point2D.Double(); |
305 |
|
306 |
AffineTransform at;
|
307 |
|
308 |
try {
|
309 |
at = at1.createInverse(); |
310 |
at.transform(pScreen, pWorld); |
311 |
} catch (NoninvertibleTransformException e) { |
312 |
// throw new RuntimeException(e);
|
313 |
} |
314 |
|
315 |
return pWorld;
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* Devuelve true si el rectangulo formado por los dos puntos que se pasan
|
320 |
* como par?metro es superior a la tolerancia.
|
321 |
*
|
322 |
* @param tolerance Tolerancia
|
323 |
* @param p1 Punto inicial del rect?ngulo.
|
324 |
* @param p2 Punto final del rect?ngulo.
|
325 |
*
|
326 |
* @return True si el tama?o es correcto.
|
327 |
*/
|
328 |
private boolean isCorrectSize(int tolerance, Point2D p1, Point2D p2) { |
329 |
if (Math.abs(p2.getX()-p1.getX())<tolerance) { |
330 |
return false; |
331 |
} else if (Math.abs(p2.getY()-p1.getY())<tolerance) { |
332 |
return false; |
333 |
} |
334 |
return true; |
335 |
} |
336 |
} |