Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrameBasic.java @ 37196

History | View | Annotate | Download (9 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.fframes;
23

    
24
import java.awt.Color;
25
import java.awt.Graphics2D;
26
import java.awt.event.MouseEvent;
27
import java.awt.geom.AffineTransform;
28
import java.awt.geom.Point2D;
29
import java.awt.geom.Point2D.Double;
30
import java.awt.geom.Rectangle2D;
31
import java.awt.image.BufferedImage;
32

    
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.app.project.documents.layout.geometryadapters.PolygonAdapter;
35
import org.gvsig.compat.print.PrintAttributes;
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.mapcontext.MapContextLocator;
38
import org.gvsig.fmap.mapcontext.MapContextManager;
39
import org.gvsig.symbology.SymbologyLocator;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
41
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ISimpleLineSymbol;
42
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.dynobject.DynStruct;
44
import org.gvsig.tools.persistence.PersistenceManager;
45
import org.gvsig.tools.persistence.PersistentState;
46
import org.gvsig.tools.persistence.exception.PersistenceException;
47

    
48
/**
49
 * FFrame b?sica que contiene una FFrame de cualquier tipo.
50
 * 
51
 * @author Vicente Caballero Navarro
52
 */
53
public class FFrameBasic extends FFrame {
54

    
55
    public static final String PERSISTENCE_DEFINITION_NAME = "FFrameBasic";
56

    
57
    private static final String FFRAMEGRAPHICS_FIELD = "fframeGraphics";
58
    private static final String FFRAME_FIELD = "fframe";
59

    
60
    private FFrameGraphics fframeGraphics;
61
    private IFFrame fframe;
62

    
63
    private MapContextManager mapContextManager = MapContextLocator
64
        .getMapContextManager();
65

    
66
    public void setRectangle(Rectangle2D r) {
67
        FFrameGraphics graphics =
68
            (FFrameGraphics) layoutManager
69
                .createFrame(FFrameGraphics.PERSISTENCE_DEFINITION_NAME);
70
        PolygonAdapter pa = new PolygonAdapter();
71
        pa.addPoint(new Point2D.Double(r.getX(), r.getY()));
72
        pa.addPoint(new Point2D.Double(r.getMaxX(), r.getY()));
73
        pa.addPoint(new Point2D.Double(r.getMaxX(), r.getMaxY()));
74
        pa.addPoint(new Point2D.Double(r.getX(), r.getMaxY()));
75
        pa.addPoint(new Point2D.Double(r.getX(), r.getY()));
76
        pa.end();
77
        graphics.setGeometryAdapter(pa);
78
        graphics.setBoundBox(r);
79

    
80
        IFillSymbol symbol =
81
            (IFillSymbol) mapContextManager.getSymbolManager().createSymbol(
82
                IFillSymbol.SYMBOL_NAME);
83
        symbol.setFillColor(new Color(255, 255, 255, 0));
84
        ISimpleLineSymbol blackOutline =
85
            SymbologyLocator.getSymbologyManager().createSimpleLineSymbol();
86
        blackOutline.setLineColor(Color.BLACK);
87
        symbol.setOutline(blackOutline);
88
        graphics.setSymbol(symbol);
89
        graphics.setType(Geometry.TYPES.CURVE);
90
        setFframeGraphics(graphics);
91
    }
92

    
93
    public FFrameBasic() {
94

    
95
    }
96

    
97
    /**
98
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
99
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
100
     * de dibujar.
101
     * 
102
     * @param g
103
     *            Graphics
104
     * @param at
105
     *            Transformada afin.
106
     * @param rv
107
     *            rect?ngulo sobre el que hacer un clip.
108
     * @param imgBase
109
     *            Imagen para acelerar el dibujado.
110
     */
111
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
112
        BufferedImage imgBase) {
113
        fframeGraphics.draw(g, at, rv, imgBase);
114
        if (fframe != null) {
115
            fframe.draw(g, at, rv, imgBase);
116
        }
117
    }
118

    
119
    /**
120
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
121
     */
122
    public String getNameFFrame() {
123
        return PluginServices.getText(this, "base") + num;
124
    }
125

    
126
    /**
127
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
128
     *      java.awt.geom.AffineTransform)
129
     */
130
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
131
        PrintAttributes printingProperties) {
132
        fframeGraphics.print(g, at, geom, printingProperties);
133
        if (fframe != null) {
134
            fframe.print(g, at, geom, printingProperties);
135
        }
136
    }
137

    
138
    public IFFrame getFframe() {
139
        return fframe;
140
    }
141

    
142
    public void setFframe(IFFrame fframe) {
143
        this.fframe = fframe;
144
    }
145

    
146
    public FFrameGraphics getFframeGraphics() {
147
        return fframeGraphics;
148
    }
149

    
150
    public void setFframeGraphics(FFrameGraphics fframeGraphics) {
151
        this.fframeGraphics = fframeGraphics;
152
    }
153

    
154
    public void drawHandlers(Graphics2D g) {
155
        fframeGraphics.drawHandlers(g);
156
    }
157

    
158
    public IFFrame clone() throws CloneNotSupportedException {
159
        FFrameBasic basic = new FFrameBasic();
160
        basic.setFframeGraphics((FFrameGraphics) fframeGraphics.clone());
161
        if (fframe != null) {
162
            basic.setFframe((IFFrame) fframe.clone());
163
        }
164
        return basic;
165
    }
166

    
167
    public boolean contains(Double p) {
168
        return getFframeGraphics().contains(p);
169
    }
170

    
171
    public void drawDraft(Graphics2D g) {
172
        super.drawDraft(g);
173
    }
174

    
175
    public void drawEmpty(Graphics2D g) {
176
        super.drawEmpty(g);
177
    }
178

    
179
    public void drawSymbolTag(Graphics2D g) {
180
        super.drawSymbolTag(g);
181
    }
182

    
183
    public java.awt.geom.Rectangle2D.Double getBoundBox() {
184
        return getFframeGraphics().getBoundBox();
185
    }
186

    
187
    public java.awt.geom.Rectangle2D.Double getBoundingBox(AffineTransform at) {
188
        return getFframeGraphics().getBoundingBox(at);
189
    }
190

    
191
    public int getContains(Double p) {
192
        return getFframeGraphics().getContains(p);
193
    }
194

    
195
    public int getLevel() {
196
        return super.getLevel();
197
    }
198

    
199
    public Rectangle2D getMovieRect(int difx, int dify) {
200
        return fframeGraphics.getMovieRect(difx, dify);
201
    }
202

    
203
    public String getName() {
204
        return PERSISTENCE_DEFINITION_NAME;
205
    }
206

    
207
    public double getRotation() {
208
        return super.getRotation();
209
    }
210

    
211
    public int getSelected() {
212
        return fframeGraphics.getSelected();
213
    }
214

    
215
    public String getTag() {
216
        return super.getTag();
217
    }
218

    
219
    public boolean intersects(Rectangle2D rv, Rectangle2D r) {
220
        return super.intersects(rv, r);
221
    }
222

    
223
    public void setBoundBox(Rectangle2D r) {
224
        if (getFframeGraphics() != null) {
225
            getFframeGraphics().setBoundBox(r);
226
        }
227
        if (getFframe() != null) {
228
            getFframe().setBoundBox(r);
229
        }
230
    }
231

    
232
    public void setLevel(int l) {
233
        super.setLevel(l);
234
    }
235

    
236
    public void setNum(int i) {
237
        super.setNum(i);
238
    }
239

    
240
    public void setRotation(double rotation) {
241
        super.setRotation(rotation);
242
    }
243

    
244
    public void setSelected(boolean b) {
245
        fframeGraphics.setSelected(b);
246
    }
247

    
248
    public void setSelected(Point2D p, MouseEvent e) {
249
        fframeGraphics.setSelected(p, e);
250
    }
251

    
252
    public void setTag(String s) {
253
        super.setTag(s);
254
    }
255

    
256
    public void updateRect(Rectangle2D r, AffineTransform at) {
257
        getFframeGraphics().updateRect(r, at);
258
    }
259

    
260
    public static void registerPersistent() {
261
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
262
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
263
            DynStruct definition =
264
                manager.addDefinition(FFrameBasic.class,
265
                    PERSISTENCE_DEFINITION_NAME,
266
                    "FFrameBasic persistence definition", null, null);
267

    
268
            definition.extend(manager
269
                .getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME));
270

    
271
            definition.addDynFieldObject(FFRAMEGRAPHICS_FIELD)
272
                .setClassOfValue(FFrameGraphics.class).setMandatory(true);
273
            definition.addDynFieldDouble(FFRAME_FIELD);
274
        }
275
    }
276

    
277
    @Override
278
    public void loadFromState(PersistentState state)
279
        throws PersistenceException {
280
        super.loadFromState(state);
281
        fframeGraphics = (FFrameGraphics) state.get(FFRAMEGRAPHICS_FIELD);
282
        fframe = (IFFrame) state.get(FFRAME_FIELD);
283
    }
284

    
285
    @Override
286
    public void saveToState(PersistentState state) throws PersistenceException {
287
        super.saveToState(state);
288
        state.set(FFRAMEGRAPHICS_FIELD, fframeGraphics);
289
        state.set(FFRAME_FIELD, fframe);
290
    }
291
}