Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / PictureMarkerSymbol.java @ 11877

History | View | Annotate | Download (5.85 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: PictureMarkerSymbol.java 11877 2007-05-29 15:47:06Z jaume $
45
* $Log$
46
* Revision 1.6  2007-05-29 15:46:37  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.5  2007/05/08 08:47:40  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.4  2007/03/21 17:36:22  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.3  2007/03/09 11:20:57  jaume
56
* Advanced symbology (start committing)
57
*
58
* Revision 1.1.2.4  2007/02/21 07:34:09  jaume
59
* labeling starts working
60
*
61
* Revision 1.1.2.3  2007/02/16 10:54:12  jaume
62
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
63
*
64
* Revision 1.1.2.2  2007/02/15 16:23:44  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1.2.1  2007/02/09 07:47:05  jaume
68
* Isymbol moved
69
*
70
* Revision 1.1  2007/01/24 17:58:22  jaume
71
* new features and architecture error fixes
72
*
73
*
74
*/
75
package com.iver.cit.gvsig.fmap.core.symbols;
76

    
77
import java.awt.Color;
78
import java.awt.Graphics2D;
79
import java.awt.Rectangle;
80
import java.awt.Shape;
81
import java.awt.geom.AffineTransform;
82
import java.awt.image.BufferedImage;
83
import java.io.File;
84
import java.io.IOException;
85
import java.net.URL;
86

    
87
import javax.imageio.ImageIO;
88

    
89
import org.apache.log4j.Logger;
90

    
91
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
92
import com.iver.cit.gvsig.fmap.Messages;
93
import com.iver.cit.gvsig.fmap.core.FPoint2D;
94
import com.iver.cit.gvsig.fmap.core.FShape;
95
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
96
import com.iver.utiles.XMLEntity;
97

    
98
/**
99
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
100
 */
101
public class PictureMarkerSymbol extends CartographicMarkerSymbol {
102
        private static final float SELECTION_OPACITY_FACTOR = .3F;
103
        transient private BufferedImage img;
104
        private String imagePath;
105
//        private MultiLayerSymbol selectionSymbol;
106

    
107
        public PictureMarkerSymbol() {
108
                super();
109
        }
110

    
111
        public PictureMarkerSymbol(File imageFile) throws IOException {
112
                setImage(imageFile);
113
        }
114

    
115
        public PictureMarkerSymbol(URL imageURL) throws IOException {
116
                this(new File(imageURL.getFile()));
117
        }
118

    
119
        public void setImage(File imageFile) throws IOException{
120
                img = ImageIO.read(imageFile);
121
                imagePath = imageFile.getAbsolutePath();
122
        }
123

    
124
        private BufferedImage getImg() throws IOException {
125
                if (img == null) {
126
                        img = ImageIO.read(new File(imagePath));
127
                }
128
                return img;
129
        }
130

    
131
        public ISymbol getSymbolForSelection() {
132
                throw new Error("not yet implemented");
133
//                if (selectionSymbol == null) {
134
//                        selectionSymbol = new MultiLayerMarkerSymbol();
135
//                        selectionSymbol.setMultiLayerSymbolType(getSymbolType());
136
//                        Color selColor = FSymbol.getSelectionColor();
137
//                        selColor = new Color(
138
//                                        selColor.getRed(),     // R
139
//                                        selColor.getGreen(),   // G
140
//                                        selColor.getBlue(),           // B
141
//                                        (int)(255*SELECTION_OPACITY_FACTOR) // Alpha
142
//                                        );
143
//                        SimpleFillSymbol overSymbol = new SimpleFillSymbol();
144
//                        overSymbol.setFillColor(selColor);
145
//
146
//                        selectionSymbol.addLayer(this);
147
//                        selectionSymbol.addLayer(overSymbol);
148
//                }
149
//                return selectionSymbol;
150
        }
151

    
152
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
153
                FPoint2D p = (FPoint2D) shp;
154
                int xOffset = (int) getOffset().getX(); // TODO Cartographic support
155
                int yOffset = (int) getOffset().getY(); // TODO Cartographic support
156
                g.translate(p.getX(), p.getY());
157
                try{
158
                        g.drawImage(getImg(), null, xOffset, yOffset);
159
                } catch (IOException e) {
160
                        Logger.getLogger(this.getClass()).error(Messages.getString("failed_to_read_image_file"), e);
161
                }
162
                g.translate(-p.getX(), -p.getY());
163
        }
164

    
165
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
166
                        Shape shp) {
167
                // TODO Implement it
168
                throw new Error("Not yet implemented!");
169

    
170
        }
171

    
172
        public XMLEntity getXMLEntity() {
173
                // TODO Implement it
174
                XMLEntity xml = new XMLEntity();
175
                xml.putProperty("className", getClassName());
176
                xml.putProperty("isShapeVisible", isShapeVisible());
177
                xml.putProperty("desc", getDescription());
178
                xml.putProperty("imagePath", imagePath);
179
                // measure unit
180
                xml.putProperty("unit", getUnit());
181
                return xml;
182
        }
183

    
184
        public int getSymbolType() {
185
                return FShape.POINT;
186
        }
187

    
188
        public void drawInsideRectangle(Graphics2D g,
189
                        AffineTransform scaleInstance, Rectangle r) {
190
                g.setClip(r);
191
                draw(g, scaleInstance, new FPoint2D(r.getCenterX(), r.getCenterY()));
192
        }
193

    
194
        public String getClassName() {
195
                return getClass().getName();
196
        }
197

    
198
        public void setXMLEntity(XMLEntity xml) {
199
                setDescription(xml.getStringProperty("desc"));
200
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
201
                imagePath = xml.getStringProperty("imagePath");
202
                setUnit(xml.getIntProperty("unit"));
203

    
204
        }
205

    
206
        public void print(Graphics2D g, AffineTransform at, FShape shape)
207
                        throws ReadDriverException {
208
                // TODO Implement it
209
                throw new Error("Not yet implemented!");
210

    
211
        }
212

    
213
        public String getImagePath() {
214
                return imagePath;
215
        }
216

    
217
}