Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrameSymbol.java @ 1744

History | View | Annotate | Download (6.81 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.Graphics2D;
25
import java.awt.Rectangle;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.Rectangle2D;
28
import java.awt.image.BufferedImage;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.app.project.documents.layout.geometryadapters.GeometryAdapter;
31
import org.gvsig.compat.print.PrintAttributes;
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.mapcontext.MapContextLocator;
34
import org.gvsig.fmap.mapcontext.MapContextManager;
35
import org.gvsig.fmap.mapcontext.ViewPort;
36
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
37
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
38
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.persistence.PersistenceManager;
42
import org.gvsig.tools.persistence.PersistentState;
43
import org.gvsig.tools.persistence.exception.PersistenceException;
44

    
45
/**
46
 * FFrame para introducir una S?mbolo en el Layout.
47
 * 
48
 * @author Vicente Caballero Navarro
49
 */
50
public class FFrameSymbol extends FFrameGraphics {
51

    
52
    public static final String PERSISTENCE_DEFINITION_NAME = "FFrameSymbol";
53
    private static final String VIEWPORT_FIELD = "viewport";
54

    
55
    private PrintAttributes properties;
56
    private ViewPort viewPort;
57

    
58
    private final MapContextManager mapContextManager = MapContextLocator
59
        .getMapContextManager();
60

    
61
    /**
62
     * Crea un nuevo FFrameSymbol.
63
     */
64
    public FFrameSymbol() {
65
        super();
66
    }
67

    
68
    /**
69
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
70
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
71
     * de dibujar.
72
     * 
73
     * @param g
74
     *            Graphics
75
     * @param at
76
     *            Transformada afin.
77
     * @param rv
78
     *            rect?ngulo sobre el que hacer un clip.
79
     * @param imgBase
80
     *            Imagen para acelerar el dibujado.
81
     */
82
    @Override
83
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
84
        BufferedImage imgBase) {
85
        Rectangle2D.Double re = getBoundingBox(at);
86
        g.rotate(Math.toRadians(getRotation()), re.x + (re.width / 2), re.y
87
            + (re.height / 2));
88

    
89
        if (intersects(rv, re)) {
90
            AffineTransform mT2 = new AffineTransform();
91
            mT2.setToIdentity();
92

    
93
            Rectangle rec =
94
                new Rectangle((int) re.x, (int) re.y, (int) (re.width),
95
                    (int) (re.height));
96

    
97
            try {
98
                ISymbol sym = getFSymbol();
99
                if(sym instanceof CartographicSupport){
100
                    ((CartographicSupport)sym).setCartographicContext(viewPort, properties, null);
101
                }
102

    
103
                sym.drawInsideRectangle(g, mT2, rec); //, properties);
104
            } catch (SymbolDrawingException ex) {
105
                if (ex.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
106
                    try {
107
                        mapContextManager
108
                            .getSymbolManager()
109
                            .getWarningSymbol(
110
                                SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
111
                                getFSymbol().getDescription(),
112
                                SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS)
113
                            .drawInsideRectangle(g, null, rec);
114
                    } catch (SymbolDrawingException e1) {
115
                        // IMPOSSIBLE TO REACH THIS
116
                    }
117
                } else {
118
                    // should be unreachable code
119
                    throw new Error(PluginServices.getText(this,
120
                        "symbol_shapetype_mismatch"));
121
                }
122
            }
123
        }
124

    
125
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2), re.y
126
            + (re.height / 2));
127
    }
128

    
129
    /**
130
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
131
     */
132
    @Override
133
    public String getNameFFrame() {
134
        return PluginServices.getText(this, "simbolo") + num;
135
    }
136

    
137
    @Override
138
    public String getName() {
139
        return PERSISTENCE_DEFINITION_NAME;
140
    }
141

    
142
    /**
143
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
144
     *      java.awt.geom.AffineTransform)
145
     */
146
    @Override
147
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
148
        PrintAttributes printingProperties) {
149
        this.properties = printingProperties;
150
        draw(g, at, null, null);
151
        this.properties = null;
152
    }
153

    
154
    @Override
155
    public void initialize() {
156

    
157
    }
158

    
159
    @Override
160
    public void setBoundBox(Rectangle2D r) {
161
        m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
162
    }
163

    
164
    public void setShapeType(int shapeType) {
165
        setType(shapeType);
166
    }
167

    
168
    public static void registerPersistent() {
169
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
170
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
171
            DynStruct definition =
172
                manager.addDefinition(FFrameSymbol.class,
173
                    PERSISTENCE_DEFINITION_NAME,
174
                    "FFrameSymbol persistence definition", null, null);
175

    
176
            definition.extend(manager
177
                .getDefinition(FFrameGraphics.PERSISTENCE_DEFINITION_NAME));
178
        }
179

    
180
        GeometryAdapter.registerPersistent();
181
    }
182

    
183
    @Override
184
    public void loadFromState(PersistentState state)
185
        throws PersistenceException {
186
        super.loadFromState(state);
187
        this.viewPort = (ViewPort) state.get(VIEWPORT_FIELD);
188
    }
189

    
190
    @Override
191
    public void saveToState(PersistentState state) throws PersistenceException {
192
        super.saveToState(state);
193
        state.set(VIEWPORT_FIELD, this.viewPort);
194
    }
195

    
196
    public void setViewPort(ViewPort viewPort) {
197
        this.viewPort = viewPort;
198
    }
199

    
200
}