Revision 38699

View differences:

tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4
		 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5

  
6
	<modelVersion>4.0.0</modelVersion>
7
	<artifactId>org.gvsig.symbology.lib</artifactId>
8
	<packaging>pom</packaging>
9
	<name>org.gvsig.symbology.lib</name>
10
	<parent>
11
		<groupId>org.gvsig</groupId>
12
		<artifactId>org.gvsig.symbology</artifactId>
13
		<version>2.0.0-SNAPSHOT</version>
14
	</parent>
15

  
16
	<modules>
17
		<module>org.gvsig.symbology.lib.api</module>
18
		<module>org.gvsig.symbology.lib.impl</module>
19
	</modules>
20
</project>
0 21

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/impl/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.symbology package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>Symbology library API default implementation.</p>
11

  
12
</body>
13
</html>
0 14

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/impl/SymbologyDefaultImplLibrary.java
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

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {gvSIG}  {{Task}}
26
 */
27
package org.gvsig.symbology.impl;
28

  
29
import org.gvsig.symbology.SymbologyLibrary;
30
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
31
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractIntervalLegend;
32
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractLegend;
33
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
34
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.FInterval;
35
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.SingleSymbolLegend;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialIntervalLegend;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.DefaultLabelingMethod;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.LabelClass;
41
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.ZoomConstraintsImpl;
42
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol;
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MarkerFillSymbol;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
47
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
48
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
49
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.AbstractLineSymbol;
50
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.MultiLayerLineSymbol;
51
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.PictureLineSymbol;
52
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
53
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.AbstractMarkerSymbol;
54
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.ArrowMarkerSymbol;
55
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.MultiLayerMarkerSymbol;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.PictureMarkerSymbol;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.AbstractStyle;
59
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle;
60
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.BackgroundFileStyle;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.DefaultMask;
62
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ImageStyle;
63
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.RemoteFileStyle;
64
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SVGStyle;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleLineStyle;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleMarkerFillPropertiesStyle;
67
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
68
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.warning.impl.WarningSymbol;
69
import org.gvsig.tools.library.AbstractLibrary;
70
import org.gvsig.tools.library.LibraryException;
71
import org.gvsig.tools.util.Caller;
72
import org.gvsig.tools.util.impl.DefaultCaller;
73

  
74
/**
75
 * Library for the Basic Symbology implementation.
76
 * 
77
 * @author gvSIG team
78
 */
79
public class SymbologyDefaultImplLibrary extends AbstractLibrary {
80
	
81
    @Override
82
    public void doRegistration() {
83
        registerAsImplementationOf(SymbologyLibrary.class);
84
    }
85

  
86
	protected void doInitialize() throws LibraryException {
87
		Caller caller = new DefaultCaller();
88
		caller.add(new DefaultSymbologyManager.RegisterSymbologyManager());
89
		if (!caller.call()) {
90
			throw new LibraryException(SymbologyDefaultImplLibrary.class,
91
					caller.getExceptions());
92
		}
93
	}
94

  
95
    protected void doPostInitialize() throws LibraryException {
96
        Caller caller = new DefaultCaller();
97

  
98
        /*
99
         * Add registry of symbols 
100
         */
101
        caller.add( new SimpleFillSymbol.RegisterSymbol() );
102
        caller.add( new MultiLayerFillSymbol.RegisterSymbol() );
103
        caller.add( new SimpleLineSymbol.RegisterSymbol() );
104
        caller.add( new MultiLayerLineSymbol.RegisterSymbol() );
105
        caller.add( new SimpleMarkerSymbol.RegisterSymbol() );
106
        caller.add( new MultiLayerMarkerSymbol.RegisterSymbol() );
107
        caller.add( new SimpleTextSymbol.RegisterSymbol() );
108
        caller.add( new MultiShapeSymbol.RegisterSymbol() );
109
        caller.add( new WarningSymbol.RegisterSymbol() );
110

  
111
        caller.add( new PictureFillSymbol.RegisterSymbol() );
112
        caller.add( new PictureLineSymbol.RegisterSymbol() );
113
        caller.add( new PictureMarkerSymbol.RegisterSymbol() );
114

  
115
//        caller.add( new MarkerFillSymbol.RegisterSymbol() );
116

  
117
        /*
118
         * Add registry of legends
119
         */
120
        caller.add( new VectorialUniqueValueLegend.RegisterLegend() );
121
        caller.add( new VectorialIntervalLegend.RegisterLegend() );
122
        caller.add( new SingleSymbolLegend.RegisterLegend() );
123
        
124
        /*
125
         * Add registry of persistent styles
126
         */
127
        caller.add( new AbstractStyle.RegisterPersistence() );
128
        caller.add( new ArrowDecoratorStyle.RegisterPersistence() );
129
        caller.add( new DefaultMask.RegisterPersistence() );
130
        caller.add( new SimpleLineStyle.RegisterPersistence() );
131

  
132
        caller.add( new BackgroundFileStyle.RegisterPersistence() );
133
        caller.add( new ImageStyle.RegisterPersistence() );
134
        caller.add( new RemoteFileStyle.RegisterPersistence() );
135
        caller.add( new SVGStyle.RegisterPersistence() );
136

  
137
        /*
138
         * Add registry of persistent symbols
139
         */
140
        caller.add( new AbstractSymbol.RegisterPersistence() );
141
        caller.add( new AbstractFillSymbol.RegisterPersistence() );
142
        caller.add( new SimpleFillSymbol.RegisterPersistence() );
143
        caller.add( new MultiLayerFillSymbol.RegisterPersistence() );
144
        caller.add( new AbstractLineSymbol.RegisterPersistence() );
145
        caller.add( new SimpleLineSymbol.RegisterPersistence() );
146
        caller.add( new MultiLayerLineSymbol.RegisterPersistence() );
147
        caller.add( new AbstractMarkerSymbol.RegisterPersistence() );
148
        caller.add( new SimpleMarkerSymbol.RegisterPersistence() );
149
        caller.add( new ArrowMarkerSymbol.RegisterPersistence() );
150
        caller.add( new MultiLayerMarkerSymbol.RegisterPersistence() );
151
        caller.add( new SimpleTextSymbol.RegisterPersistence() );
152
        caller.add( new MultiShapeSymbol.RegisterPersistence() );
153
        caller.add( new WarningSymbol.RegisterPersistence() );
154
                
155
        caller.add( new PictureFillSymbol.RegisterPersistence() );
156
        caller.add( new PictureLineSymbol.RegisterPersistence() );
157
        caller.add( new PictureMarkerSymbol.RegisterPersistence() );
158
        caller.add( new MarkerFillSymbol.RegisterPersistence() );
159
        caller.add( new SimpleMarkerFillPropertiesStyle.RegisterPersistence() );
160

  
161

  
162
        /*
163
         * Add registry of persistent legends
164
         */
165
        caller.add(new AbstractLegend.RegisterPersistence());
166
        caller.add(new AbstractVectorialLegend.RegisterPersistence());
167
        caller.add(new AbstractClassifiedVectorLegend.RegisterPersistence());
168
        caller.add(new FInterval.RegisterPersistence());
169
        caller.add(new AbstractIntervalLegend.RegisterPersistence());
170
        caller.add(new VectorialIntervalLegend.RegisterPersistence());
171
        caller.add(new VectorialUniqueValueLegend.RegisterPersistence());
172
        caller.add(new SingleSymbolLegend.RegisterPersistence());
173

  
174
        /*
175
         * Add registry of labeling classes
176
         */
177
        caller.add(new ZoomConstraintsImpl.RegisterPersistence());
178
        caller.add(new LabelClass.RegisterPersistence());
179
        caller.add(new DefaultLabelingMethod.RegisterPersistence());
180
        caller.add(new AttrInTableLabelingStrategy.RegisterPersistence());
181
                 
182
        /*
183
         * Do register of all
184
         */
185
        if( !caller.call() ) {
186
        	throw new LibraryException(SymbologyDefaultImplLibrary.class, caller.getExceptions());
187
        }
188

  
189
    }
190

  
191
}
0 192

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/impl/DefaultSymbologyManager.java
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

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {}  {{Task}}
26
*/
27
package org.gvsig.symbology.impl;
28

  
29
import java.io.IOException;
30
import java.net.URL;
31

  
32
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval;
33
import org.gvsig.symbology.SymbologyLocator;
34
import org.gvsig.symbology.SymbologyManager;
35
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.FInterval;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.IMultiShapeSymbol;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMarkerFillSymbol;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IPictureFillSymbol;
41
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol;
42
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MarkerFillSymbol;
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IPictureLineSymbol;
47
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ISimpleLineSymbol;
48
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.PictureLineSymbol;
49
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
50
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol;
51
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol;
52
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.PictureMarkerSymbol;
53
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
54
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle;
55
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.DefaultMask;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IArrowDecoratorStyle;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask;
59
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ISimpleLineStyle;
60
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleLineStyle;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleMarkerFillPropertiesStyle;
62
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol;
63
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
64
import org.gvsig.tools.util.Callable;
65

  
66
/**
67
 * Default {@link SymbologyManager} implementation.
68
 * 
69
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
70
 */
71
public class DefaultSymbologyManager implements SymbologyManager {
72

  
73
	public IInterval createInterval(double min, double max) {
74
		return new FInterval(min, max);
75
	}
76

  
77
	public static class RegisterSymbologyManager implements Callable {
78

  
79
		public Object call() throws Exception {
80

  
81
			SymbologyLocator.registerSymbologyManager(DefaultSymbologyManager.class);
82
	        
83
			return Boolean.TRUE;
84
		}
85
		
86
	}
87

  
88
	public IArrowDecoratorStyle createArrowDecoratorStyle() {
89
		return new ArrowDecoratorStyle();
90
	}
91
	
92
//	public IMarkerSymbol createMarkerSymbol(){
93
//		return new SimpleMarkerSymbol();
94
//	}
95

  
96
	public ISimpleMarkerSymbol createSimpleMarkerSymbol() {
97
		return new SimpleMarkerSymbol();
98
	}
99

  
100
	public IMask createMask() {
101
		return new DefaultMask();
102
	}
103

  
104
	public IMultiShapeSymbol createMultiShapeSymbol() {
105
		return new MultiShapeSymbol();
106
	}
107

  
108
	public ISimpleFillSymbol createSimpleFillSymbol() {
109
		return new SimpleFillSymbol();
110
	}
111

  
112
	public ISimpleLineSymbol createSimpleLineSymbol() {
113
		return new SimpleLineSymbol();
114
	}
115

  
116
	public ISimpleLineStyle createSimpleLineStyle() {
117
		return new SimpleLineStyle();
118
	}
119

  
120
	public ISimpleTextSymbol createSimpleTextSymbol() {
121
		return new SimpleTextSymbol();
122
	}
123

  
124
	public IMarkerFillPropertiesStyle createSimpleMarkerFillPropertiesStyle() {
125
		return new SimpleMarkerFillPropertiesStyle();
126
	}
127

  
128
	public IPictureFillSymbol createPictureFillSymbol(URL imageURL,
129
			URL selImageURL) throws IOException {
130
		return new PictureFillSymbol(imageURL, selImageURL);
131
	}
132

  
133
	public IPictureLineSymbol createPictureLineSymbol(URL imageURL,
134
			URL selImageURL) throws IOException {
135
		return new PictureLineSymbol(imageURL, selImageURL);
136
	}
137

  
138
	public IPictureMarkerSymbol createPictureMarkerSymbol(URL imageURL,
139
			URL selImageURL) throws IOException {
140
		return new PictureMarkerSymbol(imageURL, selImageURL);
141

  
142
	}
143

  
144
	public IMarkerFillSymbol createMarkerFillSymbol() {
145
		return new MarkerFillSymbol();
146
	}
147

  
148
	public IAttrInTableLabelingStrategy createAttrInTableLabelingStrategy() {
149
		return new AttrInTableLabelingStrategy();
150
	}
151

  
152

  
153
}
0 154

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/RemoteFileStyle.java
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
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style;
42

  
43
import java.awt.Graphics2D;
44
import java.awt.Rectangle;
45
import java.io.File;
46
import java.io.IOException;
47
import java.net.URL;
48

  
49
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
50
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
51
import org.gvsig.remoteclient.utils.Utilities;
52
import org.gvsig.tools.ToolsLocator;
53
import org.gvsig.tools.dynobject.DynStruct;
54
import org.gvsig.tools.persistence.PersistenceManager;
55
import org.gvsig.tools.persistence.PersistentState;
56
import org.gvsig.tools.persistence.exception.PersistenceException;
57
import org.gvsig.tools.util.Callable;
58

  
59
/**
60
 * 
61
 * RemoteFileStyle.java
62
 *
63
 * 
64
 * @author jaume dominguez faus - jaume.dominguez@iver.es Feb 13, 2008
65
 *
66
 */
67
public class RemoteFileStyle extends BackgroundFileStyle {
68
    public static final String REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME = "RemoteFileStyle";
69
    private static final String SOURCE = "source";
70

  
71
    private BackgroundFileStyle bgStyle;
72
	
73
	@Override
74
	public Rectangle getBounds() {
75
		return bgStyle.getBounds();
76
	}
77

  
78
	@Override
79
	public void setSource(URL url) throws IOException {
80
		File f = Utilities.downloadFile(url, "remote_picture_symbol_style", null);
81
		source = url;
82
		bgStyle = BackgroundFileStyle.createStyleByURL(f.toURI().toURL());
83
	}
84

  
85
	public void drawInsideRectangle(Graphics2D g, Rectangle r, boolean keepAspectRatio) throws SymbolDrawingException {
86
		bgStyle.drawInsideRectangle(g, r, keepAspectRatio);
87
	}
88

  
89
	public void drawOutline(Graphics2D g, Rectangle r) throws SymbolDrawingException {
90
		bgStyle.drawOutline(g, r);
91
	}
92

  
93
	public boolean isSuitableFor(ISymbol symbol) {
94
		return bgStyle.isSuitableFor(symbol);
95
	}
96

  
97
	public String getClassName() {
98
		return getClass().getName();
99
	}
100

  
101
	   public void loadFromState(PersistentState state)
102
	    throws PersistenceException {
103
	        try {
104
	            setSource(state.getURL(SOURCE));
105
	        } catch (Exception e) {
106
	            throw new PersistenceCantSetSourceException(e);
107
	        }
108
	    }
109

  
110
	    public void saveToState(PersistentState state) throws PersistenceException {
111
	        state.set(SOURCE, source);
112
	    }
113
	    
114
	    public static class RegisterPersistence implements Callable {
115

  
116
	        public Object call() throws Exception {
117
	            PersistenceManager manager = ToolsLocator.getPersistenceManager();
118
	            if( manager.getDefinition(REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME)==null ) {
119
	            	DynStruct definition = manager.addDefinition(
120
	            			RemoteFileStyle.class,
121
	            			REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME,
122
	            			REMOTE_FILE_STYLE_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
123
	            			null, 
124
	            			null
125
	            	);
126

  
127
	                // Extend the Style base definition
128
	                definition.extend(manager.getDefinition(BACKGROUND_FILE_STYLE_PERSISTENCE_DEFINITION_NAME));
129

  
130
	                definition.addDynFieldURL(SOURCE);
131
	            }
132
	            return Boolean.TRUE;
133
	        }
134
	    }
135
}
0 136

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/ArrowDecoratorStyle.java
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.symbology.fmap.mapcontext.rendering.symbol.style;
23

  
24
import java.awt.Graphics2D;
25
import java.awt.Rectangle;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.Point2D;
28

  
29
import org.apache.batik.ext.awt.geom.PathLength;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
33
import org.gvsig.fmap.geom.GeometryLocator;
34
import org.gvsig.fmap.geom.GeometryManager;
35
import org.gvsig.fmap.geom.exception.CreateGeometryException;
36
import org.gvsig.fmap.geom.primitive.Point;
37
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IArrowMarkerSymbol;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
41
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.ArrowMarkerSymbol;
42
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.dynobject.DynStruct;
44
import org.gvsig.tools.persistence.PersistenceManager;
45
import org.gvsig.tools.persistence.PersistentState;
46
import org.gvsig.tools.persistence.exception.PersistenceException;
47
import org.gvsig.tools.util.Callable;
48

  
49
/**
50
 * Class ArrowDecoratorStyle. It is used to store the information about the
51
 * different options to draw an arrow in a line (and draw it too). This
52
 * information is taken from the panel.
53
 *
54
 * @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
55
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
56
 */
57
public class ArrowDecoratorStyle extends AbstractStyle implements IArrowDecoratorStyle  {
58
	public static final String ARROR_DECORATOR_STYLE_PERSISTENCE_DEFINITION_NAME = "ArrowDecoratorStyle";
59

  
60
	private static final String FIELD_FLIP_ALL = "flipAll";
61
	private static final String FIELD_FLIP_FIRST = "flipFirst";
62
	private static final String FIELD_ARROW_MARKER_COUNT = "arrowMarkerCount";
63
	private static final String FIELD_FOLLOW_LINE_ANGLE = "followLineAngle";
64
	private static final String FIELD_MARKER = "marker";
65

  
66
	private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
67
	private boolean flipAll = false;
68
	private boolean flipFirst = false;
69
	private int arrowMarkerCount = 2;
70
	private boolean followLineAngle = true;
71
	private IMarkerSymbol marker = getDefaultMarker();
72

  
73
	public ArrowDecoratorStyle() {
74
		marker.setSize(10);
75
		((IArrowMarkerSymbol) marker).setSharpness(30);
76
	}
77

  
78
	private IMarkerSymbol getDefaultMarker() {
79
		return new ArrowMarkerSymbol();
80
	}
81
	
82
	/**
83
	 * Obtains the number of arrows that the user wants to draw in the same line.
84
	 * @return
85
	 */
86
	public int getArrowMarkerCount() {
87
		return arrowMarkerCount;
88
	}
89

  
90
	/**
91
	 * Defines the number of arrows that the user wants to draw in the same line.
92
	 * @return
93
	 */
94
	public void setArrowMarkerCount(int arrowMarkerCount) {
95
		this.arrowMarkerCount = arrowMarkerCount;
96
	}
97

  
98
	/**
99
	 * Defines the flipAll attribute.If the value of this attribute is true all the
100
	 * arrows that we had drawn in the same line will be flipped.
101
	 * @return
102
	 */
103
	public boolean isFlipAll() {
104
		return flipAll;
105
	}
106

  
107
	/**
108
	 * Obtains the flipAll attribute.If the value of this attribute is true all the
109
	 * arrows that we had drawn in the same line will be flipped.
110
	 * @return
111
	 */
112
	public void setFlipAll(boolean flipAll) {
113
		this.flipAll = flipAll;
114
	}
115

  
116
	/**
117
	 * Obtains the flipFirst attribute.If it is true only the first arrow of the line
118
	 * will be flipped.The rest will keep the same orientation.
119
	 * @return
120
	 */
121
	public boolean isFlipFirst() {
122
		return flipFirst;
123
	}
124

  
125
	/**
126
	 * Sets the flipFirst attribute.If it is true only the first arrow of the line
127
	 * will be flipped.The rest will keep the same orientation.
128
	 * @return
129
	 */
130
	public void setFlipFirst(boolean flipFirst) {
131
		this.flipFirst = flipFirst;
132
	}
133

  
134
	/**
135
	 * Gets the followLineAngle attribute.This attribute allows the arrow that we are
136
	 * going to draw to be more or less aligned with the line where it will be included (depending on the angle) .
137
	 * @return
138
	 */
139
	public boolean isFollowLineAngle() {
140
		return followLineAngle;
141
	}
142

  
143
	/**
144
	 * Sets the followLineAngle attribute.This attribute allows the arrow that we are
145
	 * going to draw to be more or less aligned with the line where it will be included.
146
	 * (depending on the angle).
147
	 * @param followingLineAngle
148
	 * @return
149
	 */
150
	public void setFollowLineAngle(boolean followLineAngle) {
151
		this.followLineAngle = followLineAngle;
152
	}
153
	/**
154
	 * Draws an arrow(or other symbol that substitutes an arrow selected by the user)
155
	 * in a line.When the line is drawn, the symbol is added and takes care of the different
156
	 * options of the user(for example if he wants to flip the first symbol or all and
157
	 * the number of symbols per line to be drawn)
158
	 * @param g
159
	 * @param affineTransform
160
	 * @param feature 
161
	 * @param shp
162
	 * @throws CreateGeometryException 
163
	 */
164
	public void draw(Graphics2D g, AffineTransform affineTransform,
165
			Geometry geom, Feature feature) throws CreateGeometryException {
166
		if (arrowMarkerCount <= 0) return;
167

  
168
		Geometry geomToDraw = geom.cloneGeometry();
169
		geomToDraw.transform(affineTransform);
170
		PathLength pl = new PathLength(geomToDraw.getShape());
171
		float size = (float) marker.getSize();
172
		marker.setRotation(0.0);
173
		float myLineLength = pl.lengthOfPath();
174
		if (size > myLineLength){
175
			return;
176
		}
177
		float step = arrowMarkerCount>2 ? myLineLength/(arrowMarkerCount-1) : pl.lengthOfPath();
178
		float rotation1 = 0; // rotation at the arrow's vertex
179
		float rotation2 = 0; // rotation at the arrow's back;
180

  
181
		Point startP = null;
182

  
183
		// the first arrow at the end of the line
184
		float theLength = pl.lengthOfPath();
185
		{
186

  
187
			if ((flipFirst || flipAll) && (flipFirst != flipAll) && followLineAngle) { // logical XOR
188
				Point2D p = pl.pointAtLength(theLength-size);
189
				if (p!=null){
190
					startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
191
					if(followLineAngle){
192
						rotation1 = pl.angleAtLength(theLength-size);
193
						rotation2 = pl.angleAtLength(theLength);
194
						marker.setRotation(rotation1);
195
					}
196
					marker.draw(g, new AffineTransform(), startP, feature, null);
197
				}
198
			} else {
199
				Point2D p = pl.pointAtLength(theLength);
200
				if (p!=null){
201
					startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
202
					if(followLineAngle){
203
						rotation1 = pl.angleAtLength(theLength-size)+(float) Math.PI;
204
						rotation2 = pl.angleAtLength(theLength)+(float) Math.PI;
205
						marker.setRotation(rotation2);
206
					}
207
					marker.draw(g, new AffineTransform(), startP, feature, null);
208
				}
209
			}
210
		}
211
		// the other arrows but the first and the last
212
		float aLength;
213
		for (int i = 1; i < arrowMarkerCount-1; i++) {
214
			aLength = (float) (step*i);
215

  
216
			if (flipAll && followLineAngle) {
217
				Point2D p = pl.pointAtLength(aLength);
218
				if (p==null){
219
					p = pl.pointAtLength(theLength);
220
				}
221
				startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
222
				if(followLineAngle){
223
					rotation1 = (float) pl.angleAtLength(aLength);
224
					rotation2 = (float) pl.angleAtLength((float)(aLength+size));
225
					marker.setRotation(rotation1);
226
				}
227
					marker.draw(g, new AffineTransform(), startP, feature, null);
228
			} else {
229
				Point2D p = pl.pointAtLength(aLength+size);
230
				if (p==null){
231
					p = pl.pointAtLength(theLength);
232
				}
233

  
234
				startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
235
				if(followLineAngle){
236
					rotation1 = (float) (pl.angleAtLength(aLength) + Math.PI);
237
					rotation2 = (float) (pl.angleAtLength((float)(aLength+size)) + Math.PI);
238
					marker.setRotation(rotation2);
239
				}
240
				marker.draw(g, new AffineTransform(), startP, feature, null);
241
			}
242
		}
243

  
244
		startP = null;
245
		// and the last arrow at the begining of the line
246
		if (arrowMarkerCount>1) {
247
			if (flipAll) {
248
				Point2D p = null;
249
				p = pl.pointAtLength(0);
250
				if (p!=null){
251
					startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
252
					if(followLineAngle){
253
						rotation1 = (float) pl.angleAtLength(size);
254
						rotation2 = (float) pl.angleAtLength(0);
255
						marker.setRotation(rotation2);
256
					}
257
					marker.draw(g, new AffineTransform(), startP, feature, null);
258
				}				
259
			} else {
260
				Point2D p = null;
261
				if(followLineAngle){
262
					p = pl.pointAtLength(size);
263
				} else {
264
					p = pl.pointAtLength(0);
265
				}
266
				if (p!=null){
267
					startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
268
					if(followLineAngle){
269
						rotation1 = (float) (pl.angleAtLength(size) + Math.PI);
270
						rotation2 = (float) (pl.angleAtLength(0) + Math.PI);
271
						marker.setRotation(rotation1);
272
					}
273
					marker.draw(g, new AffineTransform(), startP, feature, null);
274
				}
275
			}
276
		}
277
	}
278

  
279
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
280
		// TODO Auto-generated method stub
281
		throw new Error("Not yet implemented!");
282
	}
283

  
284
	public void drawOutline(Graphics2D g, Rectangle r) {
285
		// TODO Auto-generated method stub
286
		throw new Error("Not yet implemented!");
287
	}
288

  
289
	public boolean isSuitableFor(ISymbol symbol) {
290
		return symbol instanceof ILineSymbol;
291
	}
292

  
293
	public String getClassName() {
294
		return getClass().getName();
295
	}
296

  
297
	public IMarkerSymbol getMarker() {
298
		if(marker == null){
299
			marker = getDefaultMarker();
300
		}
301
		return marker;
302
	}
303

  
304
	public void setMarker(IMarkerSymbol marker) {
305
		this.marker = marker;
306
	}
307
	
308
	public Object clone() throws CloneNotSupportedException {
309
		ArrowDecoratorStyle copy  = (ArrowDecoratorStyle) super.clone();
310
		if (marker != null) {
311
			copy.marker = (IMarkerSymbol) marker.clone();
312
		}
313
		return copy;
314
	}
315

  
316
	public void loadFromState(PersistentState state)
317
			throws PersistenceException {
318
		// Set parent style properties
319
		super.loadFromState(state);
320

  
321
		// Set own properties
322
		setArrowMarkerCount(state.getInt(FIELD_ARROW_MARKER_COUNT));
323
		setFlipAll(state.getBoolean(FIELD_FLIP_ALL));
324
		setFlipFirst(state.getBoolean(FIELD_FLIP_FIRST));
325
		setFollowLineAngle(state.getBoolean(FIELD_FOLLOW_LINE_ANGLE));
326
		setMarker((IMarkerSymbol) state.get(FIELD_MARKER));
327
	}
328

  
329
	public void saveToState(PersistentState state) throws PersistenceException {
330
		// Save parent fill symbol properties
331
		super.saveToState(state);
332

  
333
		// Save own properties
334
		state.set(FIELD_ARROW_MARKER_COUNT, getArrowMarkerCount());
335
		state.set(FIELD_FLIP_ALL, isFlipAll());
336
		state.set(FIELD_FLIP_FIRST, isFlipFirst());
337
		state.set(FIELD_FOLLOW_LINE_ANGLE, isFollowLineAngle());
338
		state.set(FIELD_MARKER, getMarker());
339
	}
340
	
341
	public static class RegisterPersistence implements Callable {
342

  
343
		public Object call() throws Exception {
344
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
345
			if( manager.getDefinition(ARROR_DECORATOR_STYLE_PERSISTENCE_DEFINITION_NAME)==null ) {
346
				DynStruct definition = manager.addDefinition(
347
						ArrowDecoratorStyle.class,
348
						ARROR_DECORATOR_STYLE_PERSISTENCE_DEFINITION_NAME,
349
						ARROR_DECORATOR_STYLE_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
350
						null, 
351
						null
352
				);
353
				
354
				// Extend the Style base definition
355
				definition.extend(manager.getDefinition(STYLE_PERSISTENCE_DEFINITION_NAME));
356

  
357
				// Arrow marker count
358
				definition.addDynFieldInt(FIELD_ARROW_MARKER_COUNT).setMandatory(true);
359
				// Flip all
360
				definition.addDynFieldBoolean(FIELD_FLIP_ALL).setMandatory(true);
361
				// flip first
362
				definition.addDynFieldBoolean(FIELD_FLIP_FIRST).setMandatory(true);
363
				// Follow line angles
364
				definition.addDynFieldBoolean(FIELD_FOLLOW_LINE_ANGLE).setMandatory(true);
365
				// Marker
366
				definition.addDynFieldObject(FIELD_MARKER)
367
					.setClassOfValue(IMarkerSymbol.class)
368
					.setMandatory(true);
369

  
370
			}
371
			return Boolean.TRUE;
372
		}
373
		
374
	}
375

  
376
}
0 377

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/BackgroundFileStyle.java
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
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style;
42

  
43
import java.awt.Component;
44
import java.awt.Graphics2D;
45
import java.awt.Rectangle;
46
import java.io.File;
47
import java.io.IOException;
48
import java.net.MalformedURLException;
49
import java.net.URL;
50

  
51
import org.gvsig.fmap.mapcontext.MapContextLocator;
52
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
53
import org.gvsig.tools.ToolsLocator;
54
import org.gvsig.tools.dynobject.DynStruct;
55
import org.gvsig.tools.persistence.PersistenceManager;
56
import org.gvsig.tools.persistence.exception.PersistenceException;
57
import org.gvsig.tools.util.Callable;
58

  
59
/**
60
 * Defines methods that allows the user to create an style based in a
61
 * background file.For this reason, BackgroundFileStyle will
62
 * have a parameter that will be an string in order to specify this source file.
63
 *
64
 * @author jaume dominguez faus - jaume.dominguez@iver.es
65
 */
66
public abstract class BackgroundFileStyle extends AbstractStyle {
67

  
68
    public static final String BACKGROUND_FILE_STYLE_PERSISTENCE_DEFINITION_NAME = "BackgroundFileStyle";
69
    protected static final String SOURCE_SYMBOL_IN_LIBRARY = "sourceSymbolInLibrary";
70

  
71
    public static BackgroundFileStyle createStyleByURL(URL url) throws IOException {
72
        BackgroundFileStyle bgImage;
73
        String l = url.toString().toLowerCase();
74
        if (l.startsWith("http://") ||
75
            l.startsWith("https://"))  {
76
            bgImage = new RemoteFileStyle();
77
        } else if (l.toLowerCase().endsWith(".svg")) {
78
            bgImage = new SVGStyle();
79
        } else {
80
            bgImage = new ImageStyle();
81
        }
82
        bgImage.setSource(url);
83
        return bgImage;
84
    }
85
    protected URL source;
86
    /**
87
     * Sets the file that is used as a source to create the Background
88
     * @param f, File
89
     * @throws IOException
90
     */
91
    public abstract void setSource(URL url) throws IOException;
92
    /**
93
     * Gets the bounding <code>Rectangle</code> of this <code>Rectangle</code>.
94
     * <p>
95
     * This method is included for completeness, to parallel the
96
     * <code>getBounds</code> method of
97
     * {@link Component}.
98
     * @return    a new <code>Rectangle</code>, equal to the
99
     * bounding <code>Rectangle</code> for this <code>Rectangle</code>.
100
     * @see       java.awt.Component#getBounds
101
     * @see       #setBounds(Rectangle)
102
     * @see       #setBounds(int, int, int, int)
103
     * @since     JDK1.1
104
     */
105
    public abstract Rectangle getBounds();
106

  
107
    /**
108
     * Obtains the source of the file which is used to create the background
109
     * @return
110
     */
111
    public final URL getSource() {
112
        return source;
113
    }
114

  
115
    public final void drawInsideRectangle(Graphics2D g, Rectangle r) throws SymbolDrawingException {
116
        drawInsideRectangle(g, r, true);
117
    }
118

  
119
    public abstract void drawInsideRectangle(Graphics2D g, Rectangle r, boolean keepAspectRatio) throws SymbolDrawingException ;
120

  
121
    public Object clone() throws CloneNotSupportedException {
122
        return super.clone();
123
    }
124

  
125
    protected boolean isLibrarySymbol() {
126
    	return source.toString().startsWith(getSymbolLibraryURL().toString());
127
    }
128
    
129
    protected URL getSymbolLibraryURL(){
130
    	String symbolLibraryPath = MapContextLocator.getSymbolManager().getSymbolPreferences().getSymbolLibraryPath();
131
    	URL symbolLibraryURL = null;
132
    	try {
133
			symbolLibraryURL = new File(symbolLibraryPath).toURI().toURL();
134
		} catch (MalformedURLException e) {
135
			new RuntimeException(e);
136
		}
137
    	return symbolLibraryURL;
138
    }
139
    
140
    /**
141
     * Return the final substring of the URL symbol in the library
142
     * 
143
     * @return
144
     */
145
    protected String getSourceSymbolInLibrary(){
146
    	return source.toString().substring(getSymbolLibraryURL().toString().length());
147
    }
148

  
149
    public static class RegisterPersistence implements Callable {
150

  
151
        public Object call() throws Exception {
152
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
153
            if( manager.getDefinition(BACKGROUND_FILE_STYLE_PERSISTENCE_DEFINITION_NAME)==null ) {
154
                DynStruct definition = manager.addDefinition(
155
                    BackgroundFileStyle.class,
156
                    BACKGROUND_FILE_STYLE_PERSISTENCE_DEFINITION_NAME,
157
                    BACKGROUND_FILE_STYLE_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
158
                    null, 
159
                    null
160
                );
161

  
162
                // Extend the Style base definition
163
                definition.extend(manager.getDefinition(STYLE_PERSISTENCE_DEFINITION_NAME));
164
            }
165
            return Boolean.TRUE;
166
        }
167

  
168
    }
169

  
170
    public class PersistenceCantSetSourceException extends PersistenceException{
171

  
172
        /**
173
         * 
174
         */
175
        private static final long serialVersionUID = -3783412193739147977L;
176
        /**
177
         * 
178
         */
179
        private final static String MESSAGE_FORMAT = "Can't set source file.";
180
        private final static String MESSAGE_KEY = "_PersistenceCantSetSourceException";
181

  
182
        public PersistenceCantSetSourceException() {
183
            super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
184
        }
185
        
186
        public PersistenceCantSetSourceException(Throwable cause) {
187
            super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
188
        }
189

  
190
    }
191
}
0 192

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/DefaultMask.java
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.symbology.fmap.mapcontext.rendering.symbol.style;
23

  
24
import java.awt.BasicStroke;
25
import java.awt.Graphics2D;
26
import java.awt.Rectangle;
27
import java.awt.Shape;
28

  
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
31
import org.gvsig.fmap.geom.GeometryLocator;
32
import org.gvsig.fmap.geom.GeometryManager;
33
import org.gvsig.fmap.geom.exception.CreateGeometryException;
34
import org.gvsig.fmap.geom.primitive.GeneralPathX;
35
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.dynobject.DynStruct;
39
import org.gvsig.tools.persistence.PersistenceManager;
40
import org.gvsig.tools.persistence.PersistentState;
41
import org.gvsig.tools.persistence.exception.PersistenceException;
42
import org.gvsig.tools.util.Callable;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

  
46
/**
47
 * @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
48
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
49
 */
50
public class DefaultMask extends AbstractStyle implements IMask {
51
	private static final Logger LOG = LoggerFactory.getLogger(DefaultMask.class);
52

  
53
	public static final String DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME = "DefaultMask";
54

  
55
	private static final String FIELD_SIZE = "size";
56
	private static final String FIELD_FILL_SYMBOL = "fillSymbol";
57

  
58
	private static final GeometryManager geomManager = GeometryLocator
59
			.getGeometryManager();
60
	private double size;
61
	private IFillSymbol fill;
62

  
63
	public double getSize() {
64
		return size;
65
	}
66

  
67
	public void setSize(double size) {
68
		this.size = size;
69
	}
70

  
71
	public IFillSymbol getFillSymbol() {
72
		return fill;
73

  
74
	}
75

  
76
	public void setFillSymbol(IFillSymbol fill) {
77
		this.fill = fill;
78
	}
79

  
80
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
81
		// TODO Implement it
82
		LOG.error("TODO: Not yet implemented");
83
		throw new Error("Not yet implemented!");
84

  
85
	}
86

  
87
	public Geometry getHaloShape(Shape shp) {
88
		BasicStroke stroke = new BasicStroke(
89
				(int) /* falta CartographicSupport */getSize());
90
		Shape myShp = stroke.createStrokedShape(shp);
91
		Geometry haloShape = null;
92
		;
93
		try {
94
			haloShape = geomManager.createSurface(new GeneralPathX(myShp
95
					.getBounds2D().getPathIterator(null)), SUBTYPES.GEOM2D);
96
		} catch (CreateGeometryException e) {
97
			LOG.error("Error creating a surface", e);
98
		}
99

  
100
		return haloShape;
101
	}
102

  
103
	public boolean isSuitableFor(ISymbol symbol) {
104
		// TODO Implement it
105
		LOG.error("TODO: Not yet implemented");
106
		throw new Error("Not yet implemented!");
107

  
108
	}
109

  
110
	public void drawOutline(Graphics2D g, Rectangle r) {
111
		// TODO Implement it
112
		LOG.error("TODO: Not yet implemented");
113
		throw new Error("Not yet implemented!");
114

  
115
	}
116

  
117
	public Object clone() throws CloneNotSupportedException {
118
		DefaultMask copy = (DefaultMask) super.clone();
119
		if (fill != null) {
120
			copy.fill = (IFillSymbol) fill.clone();
121
		}
122
		return copy;
123
	}
124

  
125
	public void loadFromState(PersistentState state)
126
			throws PersistenceException {
127
		// Set parent style properties
128
		super.loadFromState(state);
129

  
130
		// Set own properties
131
		setFillSymbol((IFillSymbol) state.get(FIELD_FILL_SYMBOL));
132
		setSize(state.getDouble(FIELD_SIZE));
133
	}
134

  
135
	public void saveToState(PersistentState state) throws PersistenceException {
136
		// Save parent fill symbol properties
137
		super.saveToState(state);
138

  
139
		// Save own properties
140
		if (getFillSymbol() != null) {
141
			state.set(FIELD_FILL_SYMBOL, getFillSymbol());
142
		}
143
		state.set(FIELD_SIZE, getSize());
144
	}
145

  
146
	public static class RegisterPersistence implements Callable {
147

  
148
		public Object call() throws Exception {
149
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
150
			if( manager.getDefinition(DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME)==null ) {
151
				DynStruct definition = manager.addDefinition(
152
						DefaultMask.class,
153
						DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME,
154
						DEFAULT_MASK_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
155
						null, 
156
						null
157
				);
158
				
159
				// Extend the Style base definition
160
				definition.extend(manager.getDefinition(STYLE_PERSISTENCE_DEFINITION_NAME));
161

  
162
				// Fill symbol
163
				definition.addDynFieldObject(FIELD_FILL_SYMBOL)
164
					.setClassOfValue(IFillSymbol.class);
165
				// size
166
				definition.addDynFieldDouble(FIELD_SIZE).setMandatory(true);
167
			}
168
			return Boolean.TRUE;
169
		}
170
		
171
	}
172
}
0 173

  
tags/v2_0_0_Build_2050/libraries/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/SVGStyle.java
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
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style;
42

  
43
import java.awt.Graphics2D;
44
import java.awt.Rectangle;
45
import java.awt.RenderingHints;
46
import java.awt.geom.AffineTransform;
47
import java.awt.geom.Rectangle2D;
48
import java.io.IOException;
49
import java.net.URISyntaxException;
50
import java.net.URL;
51

  
52
import org.apache.batik.bridge.BridgeContext;
53
import org.apache.batik.bridge.DocumentLoader;
54
import org.apache.batik.bridge.GVTBuilder;
55
import org.apache.batik.bridge.UserAgentAdapter;
56
import org.apache.batik.bridge.ViewBox;
57
import org.apache.batik.dom.svg.SVGOMDocument;
58
import org.apache.batik.gvt.GraphicsNode;
59
import org.apache.batik.gvt.renderer.StaticRenderer;
60
import org.w3c.dom.Document;
61
import org.w3c.dom.Element;
62

  
63
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
64
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
65
import org.gvsig.tools.ToolsLocator;
66
import org.gvsig.tools.dynobject.DynStruct;
67
import org.gvsig.tools.persistence.PersistenceManager;
68
import org.gvsig.tools.persistence.PersistentState;
69
import org.gvsig.tools.persistence.exception.PersistenceException;
70
import org.gvsig.tools.util.Callable;
71

  
72
/**
73
 * Style for a SVG files.This is a XML specification and file format for
74
 * describing two-dimensional vector graphics, both static and animated.
75
 * SVG can be purely declarative or may include scripting. Images can contain
76
 * hyperlinks using outbound simple XLinks.It is an open standard created
77
 * by the World Wide Web Consortium..
78
 * 
79
 * @author jaume dominguez faus - jaume.dominguez@iver.es
80
 * 
81
 */
82
public class SVGStyle extends BackgroundFileStyle {
83

  
84
    public static final String SVG_STYLE_PERSISTENCE_DEFINITION_NAME =
85
        "SVGStyle";
86
    private static final String SOURCE = "source";
87
    private GVTBuilder gvtBuilder = new GVTBuilder();
88
    private UserAgentAdapter userAgent;
89
    private DocumentLoader loader;
90
    private StaticRenderer renderer = new StaticRenderer();
91
    private GraphicsNode gvtRoot;
92
    private BridgeContext ctx;
93
    private Element elt;
94

  
95
    protected static RenderingHints defaultRenderingHints;
96
    static {
97
        defaultRenderingHints = new RenderingHints(null);
98
        defaultRenderingHints.put(RenderingHints.KEY_ANTIALIASING,
99
            RenderingHints.VALUE_ANTIALIAS_ON);
100

  
101
        defaultRenderingHints.put(RenderingHints.KEY_INTERPOLATION,
102
            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
103
    }
104

  
105
    /**
106
     * Constructor method
107
     * 
108
     */
109
    public SVGStyle() {
110
        userAgent = new UserAgentAdapter();
111
        loader = new DocumentLoader(userAgent);
112
        ctx = new BridgeContext(userAgent, loader);
113
        renderer.setDoubleBuffered(true);
114
    }
115

  
116
    public void drawInsideRectangle(Graphics2D g,
117
        Rectangle rect,
118
        boolean keepAspectRatio) throws SymbolDrawingException {
119
        if (keepAspectRatio) {
120
            AffineTransform ataux;
121
            if (elt.hasAttribute("viewBox")) {
122

  
123
                try {
124
                    ataux =
125
                        ViewBox.getViewTransform(null,
126
                            elt,
127
                            (float) rect.getWidth(),
128
                            (float) rect.getHeight(),
129
                            ctx);
130
                } catch (NullPointerException e) {
131
                    throw new SymbolDrawingException(SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
132
                }
133
            } else {
134
                Rectangle2D bounds = gvtRoot.getBounds();
135
                
136
                ataux = getNoRotationTransform(
137
                    bounds,
138
                    new Rectangle2D.Double(
139
                        rect.x,
140
                        rect.y,
141
                        rect.width,
142
                        rect.height),
143
                    true);
144
            }
145
            RenderingHints renderingHints = new RenderingHints(null);
146
            renderingHints.putAll(defaultRenderingHints);
147
            g.setRenderingHints(renderingHints);
148
            gvtRoot.setTransform(ataux);
149
            gvtRoot.paint(g);
150

  
151
        } else {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff