Statistics
| Revision:

svn-gvsig-desktop / 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 @ 36648

History | View | Annotate | Download (9.38 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
        /*
81
         * jaume; moved to ISymbol
82
         * FSymbol symbol=new FSymbol(FShape.POLYGON,Color.black);
83
         * symbol.setColor(new Color(255,255,255,0));
84
         * symbol.setOutlineColor(Color.black);
85
         */
86

    
87
        IFillSymbol symbol =
88
            (IFillSymbol) mapContextManager.getSymbolManager().createSymbol(
89
                IFillSymbol.SYMBOL_NAME);
90
        symbol.setFillColor(new Color(255, 255, 255, 0));
91
        ISimpleLineSymbol blackOutline =
92
            SymbologyLocator.getSymbologyManager().createSimpleLineSymbol();
93
        blackOutline.setLineColor(Color.BLACK);
94
        symbol.setOutline(blackOutline);
95
        graphics.setSymbol(symbol);
96
        graphics.setType(Geometry.TYPES.CURVE);
97
        setFframeGraphics(graphics);
98
    }
99

    
100
    public FFrameBasic() {
101

    
102
    }
103

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

    
126
    /**
127
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
128
     */
129
    public String getNameFFrame() {
130
        return PluginServices.getText(this, "base") + num;
131
    }
132

    
133
    /**
134
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
135
     *      java.awt.geom.AffineTransform)
136
     */
137
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
138
        PrintAttributes printingProperties) {
139
        // fframeGraphics.setPrintingProperties(printingProperties);
140
        fframeGraphics.print(g, at, geom, printingProperties);
141
        // fframeGraphics.setPrintingProperties(null);
142
        if (fframe != null) {
143
            fframe.print(g, at, geom, printingProperties);
144
        }
145
    }
146

    
147
    public IFFrame getFframe() {
148
        return fframe;
149
    }
150

    
151
    public void setFframe(IFFrame fframe) {
152
        this.fframe = fframe;
153
    }
154

    
155
    public FFrameGraphics getFframeGraphics() {
156
        return fframeGraphics;
157
    }
158

    
159
    public void setFframeGraphics(FFrameGraphics fframeGraphics) {
160
        this.fframeGraphics = fframeGraphics;
161
    }
162

    
163
    public void drawHandlers(Graphics2D g) {
164
        fframeGraphics.drawHandlers(g);
165
    }
166

    
167
    public IFFrame clone() throws CloneNotSupportedException {
168
        FFrameBasic basic = new FFrameBasic();
169
        basic.setFframeGraphics((FFrameGraphics) fframeGraphics.clone());
170
        if (fframe != null) {
171
            basic.setFframe((IFFrame) fframe.clone());
172
        }
173
        return basic;
174
    }
175

    
176
    public boolean contains(Double p) {
177
        return getFframeGraphics().contains(p);
178
    }
179

    
180
    public void drawDraft(Graphics2D g) {
181
        super.drawDraft(g);
182
    }
183

    
184
    public void drawEmpty(Graphics2D g) {
185
        super.drawEmpty(g);
186
    }
187

    
188
    public void drawSymbolTag(Graphics2D g) {
189
        super.drawSymbolTag(g);
190
    }
191

    
192
    public java.awt.geom.Rectangle2D.Double getBoundBox() {
193
        return getFframeGraphics().getBoundBox();
194
    }
195

    
196
    public java.awt.geom.Rectangle2D.Double getBoundingBox(AffineTransform at) {
197
        return getFframeGraphics().getBoundingBox(at);
198
    }
199

    
200
    public int getContains(Double p) {
201
        return getFframeGraphics().getContains(p);
202
    }
203

    
204
    public int getLevel() {
205
        return super.getLevel();
206
    }
207

    
208
    public Rectangle2D getMovieRect(int difx, int dify) {
209
        return fframeGraphics.getMovieRect(difx, dify);
210
    }
211

    
212
    public String getName() {
213
        return PERSISTENCE_DEFINITION_NAME;
214
    }
215

    
216
    public double getRotation() {
217
        return super.getRotation();
218
    }
219

    
220
    public int getSelected() {
221
        return fframeGraphics.getSelected();
222
    }
223

    
224
    public String getTag() {
225
        return super.getTag();
226
    }
227

    
228
    public boolean intersects(Rectangle2D rv, Rectangle2D r) {
229
        return super.intersects(rv, r);
230
    }
231

    
232
    public void setBoundBox(Rectangle2D r) {
233
        if (getFframeGraphics() != null) {
234
            getFframeGraphics().setBoundBox(r);
235
        }
236
        if (getFframe() != null) {
237
            getFframe().setBoundBox(r);
238
            // super.setBoundBox(r);
239
        }
240
    }
241

    
242
    public void setLevel(int l) {
243
        super.setLevel(l);
244
    }
245

    
246
    public void setNum(int i) {
247
        super.setNum(i);
248
    }
249

    
250
    public void setRotation(double rotation) {
251
        super.setRotation(rotation);
252
    }
253

    
254
    public void setSelected(boolean b) {
255
        fframeGraphics.setSelected(b);
256
    }
257

    
258
    public void setSelected(Point2D p, MouseEvent e) {
259
        fframeGraphics.setSelected(p, e);
260
    }
261

    
262
    public void setTag(String s) {
263
        super.setTag(s);
264
    }
265

    
266
    public void updateRect(Rectangle2D r, AffineTransform at) {
267
        getFframeGraphics().updateRect(r, at);
268
    }
269

    
270
    public static void registerPersistent() {
271
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
272
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
273
            DynStruct definition =
274
                manager.addDefinition(FFrameBasic.class,
275
                    PERSISTENCE_DEFINITION_NAME,
276
                    "FFrameBasic persistence definition", null, null);
277

    
278
            definition.extend(manager
279
                .getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME));
280

    
281
            definition.addDynFieldObject(FFRAMEGRAPHICS_FIELD)
282
                .setClassOfValue(FFrameGraphics.class).setMandatory(true);
283
            definition.addDynFieldDouble(FFRAME_FIELD);
284
        }
285
    }
286

    
287
    @Override
288
    public void loadFromState(PersistentState state)
289
        throws PersistenceException {
290
        super.loadFromState(state);
291
        fframeGraphics = (FFrameGraphics) state.get(FFRAMEGRAPHICS_FIELD);
292
        fframe = (IFFrame) state.get(FFRAME_FIELD);
293
    }
294

    
295
    @Override
296
    public void saveToState(PersistentState state) throws PersistenceException {
297
        super.saveToState(state);
298
        state.set(FFRAMEGRAPHICS_FIELD, fframeGraphics);
299
        state.set(FFRAME_FIELD, fframe);
300
    }
301
}