Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGroup.java @ 1822

History | View | Annotate | Download (7.74 KB)

1
/*
2
 * Created on 15-jul-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.fframes;
46

    
47
import java.awt.Graphics2D;
48
import java.awt.geom.AffineTransform;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51
import java.awt.image.BufferedImage;
52
import java.util.ArrayList;
53

    
54
import com.iver.andami.PluginServices;
55
import com.iver.andami.messages.NotificationManager;
56
import com.iver.cit.gvsig.fmap.DriverException;
57
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
58
import com.iver.cit.gvsig.gui.layout.Layout;
59
import com.iver.utiles.XMLEntity;
60

    
61

    
62
/**
63
 * FFrame que contiene a su vez un ArrayList de FFrames de cualquier tipo
64
 * incluso de si mismo.
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class FFrameGroup extends FFrame {
69
        private ArrayList m_fframes = new ArrayList();
70
        private Rectangle2D.Double rg = null;
71
        private AffineTransform m_at;
72
        private Rectangle2D.Double ra = null;
73

    
74
        /**
75
         * Crea un nuevo FFrameGroup.
76
         */
77
        public FFrameGroup() {
78
        }
79

    
80
        /**
81
         * A?ade al Arraylist un nuevo FFrame para formar parte del grupo.
82
         *
83
         * @param fframe FFrame a a?adir.
84
         */
85
        public void addFFrame(IFFrame fframe) {
86
                m_fframes.add(fframe);
87
        }
88

    
89
        /**
90
         * Devuelve una ArrayList que contiene todos los FFrames que forman parte
91
         * del grupo.
92
         *
93
         * @return Arraylist con los fframes.
94
         */
95
        public ArrayList getFFrames() {
96
                return m_fframes;
97
        }
98

    
99
        /**
100
         * Devuelve el rect?ngulo que contiene a todos los fframes seleccionados.
101
         *
102
         * @param at Matriz de transformaci?n
103
         *
104
         * @return Rect?ngulo.
105
         */
106
        public Rectangle2D.Double getRectangle(AffineTransform at) {
107
                double minX = 0;
108
                double minY = 0;
109
                double maxX = 0;
110
                double maxY = 0;
111
                boolean first = true;
112
                Rectangle2D.Double rec = new Rectangle2D.Double();
113

    
114
                for (int i = 0; i < m_fframes.size(); i++) {
115
                        Rectangle2D.Double rs = ((IFFrame) m_fframes.get(i)).getBoundingBox(at);
116

    
117
                        if (first) {
118
                                rec.setRect(rs);
119
                                first = false;
120
                        }
121

    
122
                        rec.add(rs);
123
                }
124

    
125
                rg = new Rectangle2D.Double();
126
                rg.setRect(FLayoutUtilities.toSheetRect(rec, m_at));
127

    
128
                return rec;
129
        }
130

    
131
        /**
132
         * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
133
         * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
134
         * de dibujar.
135
         *
136
         * @param g Graphics
137
         * @param at Transformada afin.
138
         * @param rv rect?ngulo sobre el que hacer un clip.
139
         * @param imgBase Imagen utilizada para acelerar el dibujado.
140
         *
141
         * @throws DriverException
142
         */
143
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
144
                BufferedImage imgBase) throws DriverException {
145
                Rectangle2D.Double r = getBoundingBox(at);
146
                m_at = at;
147

    
148
                for (int i = 0; i < m_fframes.size(); i++) {
149
                        ((IFFrame) m_fframes.get(i)).draw(g, at, rv, imgBase);
150
                }
151
        }
152

    
153
        /**
154
         * Rellena la transformada que se esta utilizando en el Layout.
155
         *
156
         * @param at Matriz de transformaci?n.
157
         */
158
        public void setAt(AffineTransform at) {
159
                m_at = at;
160
        }
161

    
162
        /**
163
         * Reimplementaci?n del m?todo para poder modificar los BoundBox  de cada
164
         * uno de los FFrames que contiene dentro este FFrameGroup.
165
         *
166
         * @param r Rect?ngulo.
167
         */
168
        public void setBoundBox(Rectangle2D.Double r) {
169
                getBoundBox().setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
170

    
171
                Rectangle2D.Double raux1 = new Rectangle2D.Double(rg.x, rg.y, rg.width,
172
                                rg.height);
173
                double dx = r.x - raux1.x;
174
                double dy = r.y - raux1.y;
175
                double dw = r.width / raux1.width;
176
                double dh = r.height / raux1.height;
177

    
178
                for (int i = 0; i < getFFrames().size(); i++) {
179
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
180
                        Rectangle2D.Double raux = new Rectangle2D.Double();
181
                        raux.setRect(fframe.getBoundBox());
182

    
183
                        AffineTransform escalado = new AffineTransform();
184
                        double scalex = r.width / raux1.width;
185
                        double scaley = r.height / raux1.height;
186

    
187
                        escalado.setToScale(dw, dh);
188
                        escalado.translate(dx - r.x, dy - r.y);
189

    
190
                        Point2D.Double pd = new Point2D.Double();
191
                        escalado.transform(new Point2D.Double(raux.x, raux.y), pd);
192

    
193
                        raux.x = pd.x + r.x;
194
                        raux.y = pd.y + r.y;
195
                        raux.width = raux.width * dw;
196
                        raux.height = raux.height * dh;
197

    
198
                        fframe.setBoundBox(raux);
199
                }
200

    
201
                rg.setRect(r);
202
        }
203

    
204
        /**
205
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
206
         */
207
        public XMLEntity getXMLEntity() {
208
                XMLEntity xml = new XMLEntity();
209
                xml.putProperty("className", this.getClass().getName());
210
                xml.putProperty("m_name", m_name);
211
                xml.putProperty("x", getBoundBox().x);
212
                xml.putProperty("y", getBoundBox().y);
213
                xml.putProperty("w", getBoundBox().width);
214
                xml.putProperty("h", getBoundBox().height);
215
                xml.putProperty("m_Selected", m_Selected);
216
                xml.putProperty("type", Layout.RECTANGLEGROUP);
217
                xml.putProperty("tag", getTag());
218

    
219
                for (int i = 0; i < getFFrames().size(); i++) {
220
                        xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity());
221
                }
222

    
223
                return xml;
224
        }
225

    
226
        /**
227
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity)
228
         */
229
        public void setXMLEntity(XMLEntity xml, Layout l) {
230
                if (xml.getIntProperty("m_Selected") != 0) {
231
                        this.setSelected(true);
232
                } else {
233
                        this.setSelected(false);
234
                }
235

    
236
                IFFrame fframechild = null;
237

    
238
                for (int i = 0; i < xml.getNumChild(); i++) {
239
                        try {
240
                                Class clase = Class.forName(xml.getStringProperty("className"));
241
                                fframechild = (IFFrame) clase.newInstance();
242
                        } catch (Exception e) {
243
                                NotificationManager.addError("Clase de Frame sobre el Layout no reconocida",
244
                                        e);
245
                        }
246

    
247
                        fframechild.setXMLEntity(xml.getChild(i), l);
248
                        this.addFFrame(fframechild);
249
                }
250
        }
251

    
252
        /**
253
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
254
         */
255
        public String getNameFFrame() {
256
                return PluginServices.getText(this, "grupo");
257
        }
258

    
259
        /**
260
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
261
         *                 java.awt.geom.AffineTransform)
262
         */
263
        public void print(Graphics2D g, AffineTransform at)
264
                throws DriverException {
265
                for (int i = 0; i < m_fframes.size(); i++) {
266
                        ((IFFrame) m_fframes.get(i)).print(g, at);
267
                }
268
        }
269

    
270
        /**
271
         * Clonado de este FFrame.
272
         *
273
         * @param l Referencia al Layout.
274
         *
275
         * @return FFrame clonado.
276
         */
277
        public IFFrame cloneFFrame(Layout l) {
278
                IFFrame frame=null;
279
                try {
280
                        //TODO esto esta por implementar, y hay varias opciones o se implementa el m?todo getXMLEntity y setXMLEntity en las fframes que estan agrupadas o se implementa un clone adecuado.
281
                        frame = (IFFrame)this.clone();//new IFFrame[m_fframes.size()];
282
                        /*for (int i = 0; i < m_fframes.size(); i++) {
283
                                frames[i] = ((IFFrame) m_fframes.get(i)).cloneFFrame(l);
284
                        }
285
                        return createFFrame(this.getXMLEntity(), l,
286
                                ((ProjectMap) l.getViewModel()).getProject());
287
*/
288
                } catch (CloneNotSupportedException e) {
289
                        e.printStackTrace();
290
                }
291
                return frame;
292
        }
293
}