Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameSymbol.java @ 2304

History | View | Annotate | Download (5.57 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 com.iver.cit.gvsig.gui.layout.fframes;
46

    
47
import com.iver.andami.PluginServices;
48

    
49
import com.iver.cit.gvsig.fmap.DriverException;
50
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
51
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
52
import com.iver.cit.gvsig.gui.layout.Layout;
53

    
54
import com.iver.utiles.XMLEntity;
55

    
56
import java.awt.Graphics2D;
57
import java.awt.Rectangle;
58
import java.awt.geom.AffineTransform;
59
import java.awt.geom.Rectangle2D;
60
import java.awt.image.BufferedImage;
61

    
62

    
63
/**
64
 * FFrame para introducir una S?mbolo en el Layout.
65
 *
66
 * @author Vicente Caballero Navarro
67
 */
68
public class FFrameSymbol extends FFrame {
69
        private FSymbol m_Symbol;
70
        private int m_type;
71

    
72
        /**
73
         * Crea un nuevo FFrameSymbol.
74
         */
75
        public FFrameSymbol() {
76
        }
77

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

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

    
102
                        //SymbolPreviewDrawer pSD = new SymbolPreviewDrawer(m_Symbol);
103
                        //pSD.draw(g, r, m_type);
104
                        FGraphicUtilities.DrawSymbol((Graphics2D) g, mT2, rec, m_Symbol);
105
                }
106
                g.rotate(Math.toRadians(-getRotation()),
107
                                re.x + (re.width / 2), re.y + (re.height / 2));
108
        }
109

    
110
        /**
111
         * Pone el FSymbol.
112
         *
113
         * @param symbol
114
         * @param type Tipo de s?mbolo.
115
         */
116
        public void setSymbol(FSymbol symbol, int type) {
117
                m_Symbol = symbol;
118
                m_type = type;
119
        }
120

    
121
        /**
122
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
123
         */
124
        public XMLEntity getXMLEntity() {
125
                XMLEntity xml = new XMLEntity();
126
                xml.putProperty("className", this.getClass().getName());
127
                xml.putProperty("m_name", m_name);
128
                xml.putProperty("x", getBoundBox().x);
129
                xml.putProperty("y", getBoundBox().y);
130
                xml.putProperty("w", getBoundBox().width);
131
                xml.putProperty("h", getBoundBox().height);
132
                xml.putProperty("m_Selected", m_Selected);
133
                xml.putProperty("type", Layout.RECTANGLESYMBOL);
134
                xml.putProperty("tag", getTag());
135
                xml.putProperty("m_rotation",getRotation());
136
                xml.addChild(m_Symbol.getXMLEntity());
137

    
138
                return xml;
139
        }
140

    
141
        /**
142
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
143
         *
144
         * @param xml XMLEntity
145
         * @param l DOCUMENT ME!
146
         */
147

    
148
        /*  public static FFrameSymbol createFFrameSymbol(XMLEntity xml) {
149
           FFrameSymbol fframe = new FFrameSymbol();
150
        
151
           if (xml.getIntProperty("m_Selected") != 0) {
152
               fframe.setSelected(true);
153
           } else {
154
               fframe.setSelected(false);
155
           }
156
           fframe.m_Symbol = FSymbol.createFSymbol(xml.getChild(0));
157
           return fframe;
158
           }
159
         */
160

    
161
        /**
162
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
163
         *                 com.iver.cit.gvsig.project.Project)
164
         */
165
        public void setXMLEntity03(XMLEntity xml, Layout l) {
166
                if (xml.getIntProperty("m_Selected") != 0) {
167
                        this.setSelected(true);
168
                } else {
169
                        this.setSelected(false);
170
                }
171

    
172
                this.m_Symbol = FSymbol.createFromXML03(xml.getChild(0));
173
        }
174

    
175
        /**
176
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
177
         *                 com.iver.cit.gvsig.project.Project)
178
         */
179
        public void setXMLEntity(XMLEntity xml, Layout l) {
180
                if (xml.getIntProperty("m_Selected") != 0) {
181
                        this.setSelected(true);
182
                } else {
183
                        this.setSelected(false);
184
                }
185
                setRotation(xml.getDoubleProperty("m_rotation"));
186
                this.m_Symbol = FSymbol.createFromXML(xml.getChild(0));
187
        }
188

    
189
        /**
190
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
191
         */
192
        public String getNameFFrame() {
193
                return PluginServices.getText(this, "simbolo");
194
        }
195

    
196
        /**
197
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
198
         *                 java.awt.geom.AffineTransform)
199
         */
200
        public void print(Graphics2D g, AffineTransform at)
201
                throws DriverException {
202
                draw(g, at, null, null);
203
        }
204
}