Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutFunctions.java @ 1846

History | View | Annotate | Download (7.64 KB)

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