Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / fframes / FFrameSymbol.java @ 29596

History | View | Annotate | Download (4.69 KB)

1
/*
2
 * Created on 09-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 org.gvsig.app.project.documents.layout.fframes;
46

    
47
import java.awt.Graphics2D;
48
import java.awt.Rectangle;
49
import java.awt.geom.AffineTransform;
50
import java.awt.geom.Rectangle2D;
51
import java.awt.image.BufferedImage;
52

    
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.compat.print.PrintAttributes;
55
import org.gvsig.fmap.geom.Geometry;
56
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
57
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
58

    
59

    
60

    
61
/**
62
 * FFrame para introducir una S?mbolo en el Layout.
63
 *
64
 * @author Vicente Caballero Navarro
65
 */
66
public class FFrameSymbol extends FFrameGraphics {
67

    
68
    private PrintAttributes properties;
69

    
70
        /**
71
     * Crea un nuevo FFrameSymbol.
72
     */
73
    public FFrameSymbol() {
74
            super();
75
    }
76

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

    
93
        if (intersects(rv, re)) {
94
            AffineTransform mT2 = new AffineTransform();
95
            mT2.setToIdentity();
96

    
97
            Rectangle rec = new Rectangle((int) re.x, (int) re.y,
98
                    (int) (re.width), (int) (re.height));
99

    
100
            try {
101
                                getFSymbol().drawInsideRectangle(g, mT2, rec, properties);
102
                        } catch (SymbolDrawingException e) {
103
                                if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
104
                                        try {
105
                                                SymbologyFactory.getWarningSymbol(
106
                                                                SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
107
                                                                getFSymbol().getDescription(),
108
                                                                SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS).drawInsideRectangle(g, null, rec,null);
109
                                        } catch (SymbolDrawingException e1) {
110
                                                // IMPOSSIBLE TO REACH THIS
111
                                        }
112
                                } else {
113
                                        // should be unreachable code
114
                                        throw new Error(PluginServices.getText(this, "symbol_shapetype_mismatch"));
115
                                }
116
                        }
117
        }
118

    
119
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2),
120
            re.y + (re.height / 2));
121
    }
122

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

    
130
    /**
131
     * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
132
     *      java.awt.geom.AffineTransform)
133
     */
134
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
135
                        PrintAttributes printingProperties) {
136
        this.properties=printingProperties;
137
            draw(g, at, null, null);
138
            this.properties=null;
139
    }
140

    
141
    public void initialize() {
142

    
143
        }
144
    public void setBoundBox(Rectangle2D r) {
145
        m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
146
    }
147

    
148
        public void setShapeType(int shapeType) {
149
                switch (shapeType) {
150
        case (Geometry.TYPES.POINT):
151
                m_type = POINT;
152
            break;
153

    
154
        case (Geometry.TYPES.SURFACE):
155
                m_type = POLYGON;
156
            break;
157

    
158
        case (Geometry.TYPES.CURVE):
159
                m_type = LINE;
160
            break;
161
        }
162
        }
163
}