Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / symbology3d / marker / impl / PictureMarker3DSymbol.java @ 385

History | View | Annotate | Download (4.68 KB)

1
/* gvSIG 3D extension for gvSIG
2
 *
3
 * Copyright (C) 2012 Prodevelop.
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
 *   Prodevelop, S.L.
22
 *   Pza. Don Juan de Villarrasa, 14 - 5
23
 *   46001 Valencia
24
 *   Spain
25
 *
26
 *   +34 963 510 612
27
 *   +34 963 510 968
28
 *   prode@prodevelop.es
29
 *   http://www.prodevelop.es
30
 */
31
/*
32
 * AUTHORS:
33
 * 2012 AI2 - Instituto Universitario de Automatica e Informatica Industrial.
34
 * Universitat Politecnica de Valencia (UPV)
35
 * http://www.ai2.upv.es
36
 */
37

    
38

    
39
package org.gvsig.gvsig3d.impl.symbology3d.marker.impl;
40

    
41
import java.awt.Graphics2D;
42
import java.awt.Image;
43
import java.awt.Rectangle;
44
import java.awt.geom.AffineTransform;
45

    
46
import javax.swing.ImageIcon;
47

    
48
import org.gvsig.compat.print.PrintAttributes;
49
import org.gvsig.fmap.dal.feature.Feature;
50
import org.gvsig.fmap.geom.Geometry;
51
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
52
import org.gvsig.osgvp.exceptions.node.NodeException;
53
import org.gvsig.osgvp.symbology.marker.NodeMarker;
54
import org.gvsig.osgvp.symbology.marker.PictureMarker;
55
import org.gvsig.osgvp.symbology.marker.SimpleMarker;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.PictureMarkerSymbol;
59
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
60
import org.gvsig.tools.ToolsLocator;
61
import org.gvsig.tools.dynobject.DynStruct;
62
import org.gvsig.tools.persistence.PersistenceManager;
63
import org.gvsig.tools.persistence.PersistentState;
64
import org.gvsig.tools.persistence.exception.PersistenceException;
65
import org.gvsig.tools.task.Cancellable;
66
import org.gvsig.tools.util.Callable;
67
import org.gvsig.tools.util.Caller;
68
import org.gvsig.tools.util.impl.DefaultCaller;
69
/**
70
 * @author Jesus Zarzoso- jzarzoso@ai2.upv.es
71
 * @version $Id$
72
 * 
73
 */
74
public class PictureMarker3DSymbol extends SimpleMarker3DSymbol {
75
        String _pictureFileName = "";
76
        public static final String FILENAME = "pictureFileName";
77

    
78
        public PictureMarker3DSymbol() {
79
                try {
80
                        sm = new PictureMarker();
81
                } catch (NodeException e) {
82
                        // TODO Auto-generated catch block
83
                        e.printStackTrace();
84
                }
85
        }
86

    
87
        public void setPictureFileURL(String fileURL) {
88
                _pictureFileName = fileURL;
89
                ((PictureMarker) (sm)).setPictureFile(fileURL);
90
        }
91

    
92
        public String getPictureFileURL() {
93
                return _pictureFileName;
94
        }
95

    
96
        public void drawInsideRectangle(Graphics2D g,
97
                        AffineTransform scaleInstance, Rectangle r,
98
                        PrintAttributes properties) throws SymbolDrawingException {
99

    
100
                ImageIcon icon = new javax.swing.ImageIcon(_pictureFileName);
101
                Image img = icon.getImage();
102
                Image newimg = img.getScaledInstance(18, 18,
103
                                java.awt.Image.SCALE_SMOOTH);
104
                icon = new ImageIcon(newimg);
105
                g.drawImage(icon.getImage(), 0, 0, null);
106
        }
107

    
108
        public void loadFromState(PersistentState state)
109
                        throws PersistenceException {
110
                // Set parent fill symbol properties
111
                super.loadFromState(state);
112

    
113
                _pictureFileName = state.getString(FILENAME);
114
                setPictureFileURL(_pictureFileName);
115

    
116
        }
117

    
118
        public void saveToState(PersistentState state) throws PersistenceException {
119
                // Save parent fill symbol properties
120
                super.saveToState(state);
121

    
122
                state.set(FILENAME, _pictureFileName);
123
        }
124

    
125
        public static class RegisterPersistence implements Callable {
126

    
127
                public Object call() throws Exception {
128
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
129

    
130
                        if (manager.getDefinition("SimpleMarker3DSymbol") == null) {
131

    
132
                                Caller caller = new DefaultCaller();
133
                                caller.add(new SimpleMarker3DSymbol.RegisterPersistence());
134
                                caller.call();
135

    
136
                        }
137

    
138
                        DynStruct definition = manager.addDefinition(
139
                                        PictureMarker3DSymbol.class, "PictureMarker3DSymbol",
140
                                        "PictureMarker3DSymbol Persistence definition", null, null);
141
                        
142
                        definition.addDynFieldString(FILENAME).setMandatory(true);                        
143
                        definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE,
144
                                        "SimpleMarker3DSymbol");
145

    
146
                        return Boolean.TRUE;
147
                }
148
        }
149

    
150
}