Revision 18755

View differences:

trunk/extSymbology/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="src" path="src-test"/>
5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6
	<classpathentry combineaccessrules="false" kind="src" path="/libFMap"/>
7
	<classpathentry kind="lib" path="/_fwAndami/lib/iver-utiles.jar" sourcepath="/libIverUtiles"/>
8
	<classpathentry combineaccessrules="false" kind="src" path="/appgvSIG"/>
9
	<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.ui.jar" sourcepath="/libUIComponent/src"/>
10
	<classpathentry combineaccessrules="false" kind="src" path="/_fwAndami"/>
11
	<classpathentry kind="lib" path="/libFMap/lib/org.gvsig.raster.jar" sourcepath="/libRaster/src"/>
12
	<classpathentry kind="lib" path="/libFMap/lib/gdbms-0.8-SNAPSHOT.jar" sourcepath="/libGDBMS"/>
13
	<classpathentry kind="lib" path="/_fwAndami/lib/log4j-1.2.8.jar"/>
14
	<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.exceptions.jar"/>
15
	<classpathentry kind="lib" path="/libFMap/lib/jts-1.8.jar"/>
16
	<classpathentry kind="lib" path="/libFMap/lib/org.cresques.cts.jar"/>
17
	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
18
	<classpathentry kind="lib" path="/libFMap/lib/batik-awt-util.jar"/>
19
	<classpathentry kind="lib" path="/libFMap/lib/batik-gvt.jar"/>
20
	<classpathentry kind="lib" path="/libFMap/lib/batik-bridge.jar"/>
21
	<classpathentry kind="lib" path="/libFMap/lib/batik-ext.jar"/>
22
	<classpathentry kind="lib" path="/libFMap/lib/batik-svg-dom.jar"/>
23
	<classpathentry kind="lib" path="/libFMap/lib/batik-css.jar"/>
24
	<classpathentry kind="lib" path="/libFMap/lib/batik-script.jar"/>
25
	<classpathentry kind="lib" path="/libFMap/lib/batik-util.jar"/>
26
	<classpathentry kind="lib" path="/libFMap/lib/batik-svggen.jar"/>
27
	<classpathentry kind="lib" path="/libFMap/lib/xml-apis-ext.jar"/>
28
	<classpathentry kind="lib" path="/libFMap/lib/batik-dom.jar"/>
29
	<classpathentry kind="lib" path="/_fwAndami/lib/xml-apis.jar"/>
30
	<classpathentry kind="output" path="bin"/>
31
</classpath>
trunk/extSymbology/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>extSymbology</name>
4
	<comment>JavaCC Nature</comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>sf.eclipse.javacc.javaccbuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>pi.eclipse.cle.CupBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>pi.eclipse.cle.LexBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
		<buildCommand>
24
			<name>org.eclipse.jdt.core.javabuilder</name>
25
			<arguments>
26
			</arguments>
27
		</buildCommand>
28
	</buildSpec>
29
	<natures>
30
		<nature>pi.eclipse.cle.CupLexNature</nature>
31
		<nature>org.eclipse.jdt.core.javanature</nature>
32
		<nature>sf.eclipse.javacc.javaccnature</nature>
33
	</natures>
34
</projectDescription>
trunk/extSymbology/src-test/org/gvsig/symbology/fmap/labeling/parse/TestLabelExpressionParser.java
1
package org.gvsig.symbology.fmap.labeling.parse;
2

  
3
import java.io.CharArrayReader;
4
import java.util.Date;
5

  
6
import junit.framework.TestCase;
7

  
8
import org.gvsig.symbology.fmap.labeling.lang.Symbol;
9
import org.gvsig.symbology.fmap.labeling.lang.functions.Substring;
10
import org.gvsig.symbology.fmap.labeling.parse.LabelExpressionParser;
11
import org.gvsig.symbology.fmap.labeling.parse.ParseException;
12

  
13
import com.hardcode.gdbms.engine.values.BooleanValue;
14
import com.hardcode.gdbms.engine.values.DateValue;
15
import com.hardcode.gdbms.engine.values.DoubleValue;
16
import com.hardcode.gdbms.engine.values.IntValue;
17
import com.hardcode.gdbms.engine.values.NullValue;
18
import com.hardcode.gdbms.engine.values.StringValue;
19
import com.hardcode.gdbms.engine.values.ValueFactory;
20

  
21
public class TestLabelExpressionParser extends TestCase {
22
	LabelExpressionParser parser;
23
	
24
	@Override
25
	protected void setUp() throws Exception {
26
		super.setUp();
27
		LabelExpressionParser.addFunction(Substring.class);
28
	}
29
	private Symbol[] symbols = new Symbol[] {
30
			new Symbol(
31
					"A_DOUBLE_VALUE", 
32
					Symbol.DATA_TYPE_FLOATING,
33
					ValueFactory.createValue(4.0)
34
			),
35
			new Symbol(
36
					"ANOTHER_DOUBLE_VALUE", 
37
					Symbol.DATA_TYPE_FLOATING,
38
					ValueFactory.createValue(Math.PI)
39
			),
40
			new Symbol(
41
					"A_INTEGER_VALUE", 
42
					Symbol.DATA_TYPE_INT,
43
					ValueFactory.createValue(12)
44
			),
45
			new Symbol(
46
					"A_STRING_VALUE", 
47
					Symbol.DATA_TYPE_STRING,
48
					ValueFactory.createValue("this is a String")
49
			),
50
			new Symbol(
51
					"A_BOOLEAN_VALUE", 
52
					Symbol.DATA_TYPE_BOOLEAN,
53
					ValueFactory.createValue(true)
54
			),
55
			new Symbol(
56
					"ANOTHER_BOOLEAN_VALUE", 
57
					Symbol.DATA_TYPE_BOOLEAN,
58
					ValueFactory.createValue(false)
59
			),
60
			new Symbol(
61
					"A_NULL_VALUE", 
62
					Symbol.DATA_TYPE_NULL,
63
					ValueFactory.createNullValue()
64
			),
65
			new Symbol(
66
					"A_DATE_VALUE", 
67
					Symbol.DATA_TYPE_DATE,
68
					ValueFactory.createValue(new Date())
69
			)
70
			
71
			
72
	};
73
	
74
	public void testExpression() {
75
		
76
	}
77
	
78
	private String[] ArgumentsExpressions = new String[] {
79
			"(754)",
80
			"(754, \"blah\")",
81
			"(-9.68, [A_DOUBLE_VALUE]) ",
82
			"(false, true) ",
83
	};
84
	private Object[][] ArgumentsExpressionsValue = new Object[][]  {
85
			new Object[] { 754 },
86
			new Object[] { 754, "blah" },
87
			new Object[] { -9.68, 4.0 },
88
			new Object[] { false, true },
89
	};	
90
	public void testArguments() {
91
		
92
		String[] expressions = ArgumentsExpressions;
93
		Object[][] expectedValues = ArgumentsExpressionsValue;
94
		System.out.println("\nTestLabelExpressionParser.testArgumens()");
95
		
96
		for (int i = 0; i < expressions.length; i++) {
97
			String expr = expressions[i];
98
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
99
			for (int j = 0; j < symbols.length; j++) {
100
				parser.putSymbol(symbols[j]);
101
			}
102
			System.out.print("Parsing '"+expr+"'");
103
			try {
104
				int amount = parser.Arguments();
105
				System.out.print(": [ parsed ]. Evaluating: ");
106
				Object[] expected = expectedValues[i];
107
				assertTrue("Failed detecting argument number. Expected "+expected.length+", but got "+amount+".", amount == expected.length);
108
				
109
				for (int j = expected.length-1; j >= 0; j--) { // <- Last in first out
110
					Object value = parser.pop();
111
					assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected[j]+"]", value.equals(expected[j]));
112
					System.out.print(value+" [ Ok! ]\t");
113
				}
114
				
115

  
116
			} catch (ParseException e) {
117
				System.err.println(":\t [ Fail! ]");
118
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
119
			}
120
			System.out.println();
121
		}
122
	}
123
	
124
	private String[] LiteralExpressions = new String[] {
125
			"true",
126
			"false",
127
			" 43564356435.234",
128
			" 12455 ",
129
			" \"a string\"",
130
	};
131
	private Object[] LiteralExpressionsValue = new Object[]  {
132
			 true ,
133
			 false,
134
			 43564356435.234,
135
			 12455,
136
			 "a string"
137
	};	
138
	public void testLiteral() {
139
		String[] expressions = LiteralExpressions;
140
		Object[] expectedValues = LiteralExpressionsValue;
141
		System.out.println("\nTestLabelExpressionParser.testLiteral()");
142
		
143
		for (int i = 0; i < expressions.length; i++) {
144
			String expr = expressions[i];
145
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
146
			for (int j = 0; j < symbols.length; j++) {
147
				parser.putSymbol(symbols[j]);
148
			}
149
			System.out.print("Parsing '"+expr+"'");
150
			try {
151
				parser.Literal();
152
				System.out.print(": [ parsed ]. Evaluating: ");
153
				Object expected = expectedValues[i];
154

  
155
				Object value = parser.pop();
156
				assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected+"]", value.equals(expected));
157
				System.out.print(value+" [ Ok! ]\t");
158

  
159

  
160
			} catch (ParseException e) {
161
				System.err.println(":\t [ Fail! ]");
162
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
163
			}
164
			System.out.println();
165
		}
166
	}
167
	
168
	private String[] FunctionExpressions = new String[] {
169
			new Substring().getName()+"(\"My taylor is rich!\", 3, 9)",
170
			new Substring().getName()+"("+new Substring().getName()+"(\"My taylor is rich!\", 3, 9), 2,3)",
171
	};
172
	private Object[] FunctionExpressionsValue = new Object[]  {
173
			 "taylor" ,
174
			 "y",
175
	};	
176
	public void testFunction() {
177
		String[] expressions = FunctionExpressions;
178
		Object[] expectedValues = FunctionExpressionsValue;
179
		System.out.println("\nTestLabelExpressionParser.testFunction()");
180
		
181
		for (int i = 0; i < expressions.length; i++) {
182
			String expr = expressions[i];
183
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
184
			for (int j = 0; j < symbols.length; j++) {
185
				parser.putSymbol(symbols[j]);
186
			}
187
			System.out.print("Parsing '"+expr+"'");
188
			try {
189
				parser.Function();
190
				System.out.print(": [ parsed ]. Evaluating: ");
191
				Object expected = expectedValues[i];
192

  
193
				Object value = parser.pop();
194
				assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected+"]", value.equals(expected));
195
				System.out.print(value+" [ Ok! ]\t");
196

  
197

  
198
			} catch (ParseException e) {
199
				System.err.println(":\t [ Fail! ]");
200
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
201
			}
202
			System.out.println();
203
		}
204
	}
205

  
206
	
207
	public void testPrimitiveExpression() {
208
		String[] PrimitiveExpressions = new String[symbols.length];
209
		Object[] PrimitiveExpressionsValue = new Object[symbols.length];
210
		for (int i = 0; i < symbols.length; i++) {
211
			PrimitiveExpressions[i] = "["+symbols[i].getName()+"]";
212
			PrimitiveExpressionsValue[i] = symbols[i].getValue();
213
		}
214
		
215
		String[] expressions = PrimitiveExpressions;
216
		Object[] expectedValues = PrimitiveExpressionsValue;
217
		
218
		System.out.println("\nTestLabelExpressionParser.testPrimitiveExpression()");
219
		
220
		for (int i = 0; i < expressions.length; i++) {
221
			String expr = expressions[i];
222
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
223
			for (int j = 0; j < symbols.length; j++) {
224
				parser.putSymbol(symbols[j]);
225
			}
226
			System.out.print("Parsing '"+expr+"'");
227
			try {
228
				parser.PrimitiveExpression();
229
				System.out.print(": [ parsed ]. Evaluating: ");
230
				Object expected = expectedValues[i];
231
				
232
				// GDBMS values are evaluated as java primitives
233
				if (expected instanceof DoubleValue) {
234
					expected = ((DoubleValue) expected).getValue();
235
				} else if (expected instanceof IntValue) {
236
					expected = ((IntValue) expected).getValue();
237
				} else if (expected instanceof StringValue) {
238
					expected = ((StringValue) expected).getValue();
239
				} else if (expected instanceof DateValue) {
240
					expected = ((DateValue) expected).getValue();
241
				} else if (expected instanceof BooleanValue) {
242
					expected = ((BooleanValue) expected).getValue();
243
				} else if (expected instanceof NullValue) {
244
					expected = null;
245
				}
246
			
247

  
248
				Object value = parser.pop();
249
				assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected+"]", value == null ? value == expected : value.equals(expected));
250
				System.out.print(value+" [ Ok! ]\t");
251

  
252

  
253
			} catch (ParseException e) {
254
				System.err.println(":\t [ Fail! ]");
255
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
256
			}
257
			System.out.println();
258
		}
259
	}
260
	
261
	
262
	private String[] UnaryBooleanExpressions = new String[] {
263
			"!false",
264
			"!true",
265
			"![A_BOOLEAN_VALUE]",
266
			"![ANOTHER_BOOLEAN_VALUE]",
267
	};
268
	private Object[] UnaryBooleanExpressionsValue = new Object[]  {
269
			 !false,
270
			 !true,
271
			 !((BooleanValue) symbols[4].getValue()).getValue(),
272
			 !((BooleanValue) symbols[5].getValue()).getValue(),
273
	};	
274
	public void testBooleanUnaryExpression() {
275
		String[] expressions = UnaryBooleanExpressions;
276
		Object[] expectedValues = UnaryBooleanExpressionsValue;
277
		System.out.println("\nTestLabelExpressionParser.testBooleanUnaryExpression()");
278
		
279
		for (int i = 0; i < expressions.length; i++) {
280
			String expr = expressions[i];
281
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
282
			for (int j = 0; j < symbols.length; j++) {
283
				parser.putSymbol(symbols[j]);
284
			}
285
			System.out.print("Parsing '"+expr+"'");
286
			try {
287
				parser.BooleanUnaryExpression();
288
				System.out.print(": [ parsed ]. Evaluating: ");
289
				Object expected = expectedValues[i];
290

  
291
				Object value = parser.pop();
292
				assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected+"]", value.equals(expected));
293
				System.out.print(value+" [ Ok! ]\t");
294

  
295

  
296
			} catch (ParseException e) {
297
				System.err.println(":\t [ Fail! ]");
298
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
299
			}
300
			System.out.println();
301
		}
302
	}
303

  
304
	private String[] UnaryArithmeticExpressions = new String[] {
305
			"+65",
306
			"-5.5",
307
			"+-+-[A_DOUBLE_VALUE]",
308
			"--+[ANOTHER_DOUBLE_VALUE]",
309
	};
310
	private Object[] UnaryArithmeticExpressionsValue = new Object[]  {
311
			65,
312
			-5.5,
313
			((DoubleValue) symbols[0].getValue()).getValue(),
314
			((DoubleValue) symbols[1].getValue()).getValue(),
315
	};	
316
	public void testArithmeticUnaryExpression() {
317
		String[] expressions = UnaryArithmeticExpressions;
318
		Object[] expectedValues = UnaryArithmeticExpressionsValue;
319
		System.out.println("\nTestLabelExpressionParser.testArithmeticUnaryExpression()");
320
		
321
		for (int i = 0; i < expressions.length; i++) {
322
			String expr = expressions[i];
323
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
324
			for (int j = 0; j < symbols.length; j++) {
325
				parser.putSymbol(symbols[j]);
326
			}
327
			System.out.print("Parsing '"+expr+"'");
328
			try {
329
				parser.ArithmeticUnaryExpression();
330
				System.out.print(": [ parsed ]. Evaluating: ");
331
				Object expected = expectedValues[i];
332

  
333
				Object value = parser.pop();
334
				assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected+"]", value.equals(expected));
335
				System.out.print(value+" [ Ok! ]\t");
336

  
337

  
338
			} catch (ParseException e) {
339
				System.err.println(":\t [ Fail! ]");
340
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
341
			}
342
			System.out.println();
343
		}
344
	}
345

  
346
	
347
	private String[] MultiplicativeArithmeticExpressions = new String[] {
348
			"3*4356.234",
349
			"8768758/2432432",
350
			"[A_DOUBLE_VALUE]*[ANOTHER_DOUBLE_VALUE]",
351
			"[A_DOUBLE_VALUE]/[ANOTHER_DOUBLE_VALUE]",
352
	};
353
	private Object[] MultiplicativeArithmeticExpressionsValue = new Object[]  {
354
			3*4356.234,
355
			8768758/2432432,
356
			((DoubleValue) symbols[0].getValue()).getValue()*((DoubleValue) symbols[1].getValue()).getValue(),
357
			((DoubleValue) symbols[0].getValue()).getValue()/((DoubleValue) symbols[1].getValue()).getValue(),
358
	};	
359
	public void testMultiplicativeExpression() {
360
		String[] expressions = MultiplicativeArithmeticExpressions;
361
		Object[] expectedValues = MultiplicativeArithmeticExpressionsValue;
362
		System.out.println("\nTestLabelExpressionParser.testMultiplicativeExpression()");
363
		
364
		for (int i = 0; i < expressions.length; i++) {
365
			String expr = expressions[i];
366
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
367
			for (int j = 0; j < symbols.length; j++) {
368
				parser.putSymbol(symbols[j]);
369
			}
370
			System.out.print("Parsing '"+expr+"'");
371
			try {
372
				parser.MultiplicativeExpression();
373
				System.out.print(": [ parsed ]. Evaluating: ");
374
				Object expected = expectedValues[i];
375

  
376
				Object value = parser.pop();
377
				assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected+"]", value.equals(expected));
378
				System.out.print(value+" [ Ok! ]\t");
379

  
380

  
381
			} catch (ParseException e) {
382
				System.err.println(":\t [ Fail! ]");
383
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
384
			}
385
			System.out.println();
386
		}
387
	}
388
	
389
	private String[] AdditiveArithmeticExpressions = new String[] {
390
			"3-4356.234",
391
			"8768758+2432432",
392
			"[A_DOUBLE_VALUE]+[ANOTHER_DOUBLE_VALUE]",
393
			"[A_DOUBLE_VALUE]-[ANOTHER_DOUBLE_VALUE]",
394
	};
395
	private Object[] AdditiveArithmeticExpressionsValue = new Object[]  {
396
			3-4356.234,
397
			8768758+2432432,
398
			((DoubleValue) symbols[0].getValue()).getValue()+((DoubleValue) symbols[1].getValue()).getValue(),
399
			((DoubleValue) symbols[0].getValue()).getValue()-((DoubleValue) symbols[1].getValue()).getValue(),
400
	};
401
	public void testAdditiveExpression() {
402
		String[] expressions = AdditiveArithmeticExpressions;
403
		Object[] expectedValues = AdditiveArithmeticExpressionsValue;
404
		System.out.println("\nTestLabelExpressionParser.testAdditiveExpression()");
405
		
406
		for (int i = 0; i < expressions.length; i++) {
407
			String expr = expressions[i];
408
			parser = new LabelExpressionParser(new CharArrayReader(expr.toCharArray()));
409
			for (int j = 0; j < symbols.length; j++) {
410
				parser.putSymbol(symbols[j]);
411
			}
412
			System.out.print("Parsing '"+expr+"'");
413
			try {
414
				parser.AdditiveExpression();
415
				System.out.print(": [ parsed ]. Evaluating: ");
416
				Object expected = expectedValues[i];
417

  
418
				Object value = parser.pop();
419
				assertTrue("Parsed text '"+expr+"' evaluated to ("+value+") when expecting ["+expected+"]", value.equals(expected));
420
				System.out.print(value+" [ Ok! ]\t");
421

  
422

  
423
			} catch (ParseException e) {
424
				System.err.println(":\t [ Fail! ]");
425
				fail("Failed parsing text '"+expr+"'\n"+e.getMessage());
426
			}
427
			System.out.println();
428
		}
429
	}
430

  
431
	public void testComparisonExpression() {
432
		
433
	}
434

  
435
	public void testEqComparisonExpression() {
436
		
437
	}
438
	
439
	public void testAndComparisonExpression() {
440
		
441
	}
442
	
443
	public void testFieldExpression() {
444
		
445
	}
446
	
447
	public void testLabelExpression() {
448
		
449
	}
450
}
trunk/extSymbology/src-test/org/gvsig/symbology/symbols/PictureFillSymbolTest.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.symbols;
42

  
43
import java.io.File;
44
import java.io.IOException;
45

  
46
import org.gvsig.symbology.fmap.symbols.PictureFillSymbol;
47
import org.gvsig.symbology.fmap.symbols.PictureLineSymbol;
48

  
49
import com.iver.cit.gvsig.fmap.core.symbols.AbstractSymbolTestCase;
50
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
51
import com.iver.cit.gvsig.fmap.core.symbols.TestISymbol;
52

  
53
public class PictureFillSymbolTest extends AbstractSymbolTestCase {
54
	public PictureFillSymbolTest() {
55
		super(PictureLineSymbol.class);
56
	}
57
	
58
	@Override
59
	public ISymbol newInstance() {
60
		PictureFillSymbol pfs = (PictureFillSymbol) super.newInstance();
61
		try {
62
			pfs.setImage(new File(TestISymbol.class.getResource("picture-line.png").getFile()));
63
			return pfs;
64
		} catch (IOException e) {
65
			fail("setting up a PictureFillSymbol");
66
			return null;
67
		}
68
	}
69
}
trunk/extSymbology/src-test/org/gvsig/symbology/symbols/PictureLineSymbolTest.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.symbols;
42

  
43
import java.io.File;
44
import java.io.IOException;
45

  
46
import org.gvsig.symbology.fmap.symbols.PictureLineSymbol;
47

  
48
import com.iver.cit.gvsig.fmap.core.symbols.AbstractSymbolTestCase;
49
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
50
import com.iver.cit.gvsig.fmap.core.symbols.TestISymbol;
51

  
52
public class PictureLineSymbolTest extends AbstractSymbolTestCase {
53
	public PictureLineSymbolTest() {
54
		super(PictureLineSymbol.class);
55
	}
56
	
57
	@Override
58
	public ISymbol newInstance() {
59
		PictureLineSymbol pls = (PictureLineSymbol) super.newInstance();
60
		try {
61
			pls.setImage(new File(TestISymbol.class.getResource("picture-line.png").getFile()));
62
			pls.setSelImage(new File(TestISymbol.class.getResource("picture-line-selected.png").getFile()));
63
			return pls;
64
		} catch (IOException e) {
65
			fail("setting up a PictureLineSymbol");
66
			return null;
67
		}
68
	}
69
}
trunk/extSymbology/src-test/org/gvsig/symbology/symbols/DrawLineFillSymbol.java
1
package org.gvsig.symbology.symbols;
2

  
3
import org.gvsig.symbology.fmap.symbols.LineFillSymbol;
4

  
5
import com.iver.cit.gvsig.fmap.core.symbols.IDrawFillSymbol;
6
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
7

  
8
public class DrawLineFillSymbol implements IDrawFillSymbol {
9
	
10
	
11
	
12
	public IFillSymbol makeSymbolTransparent(IFillSymbol newSymbol) {
13
		
14
		if (newSymbol instanceof LineFillSymbol) {
15
			LineFillSymbol mySymbol = (LineFillSymbol) newSymbol;
16
			((LineFillSymbol) mySymbol).setLineSymbol(null);
17
			return mySymbol;
18
		}
19
		return newSymbol;
20
		
21
	}
22

  
23
	public boolean isSuitableFor(IFillSymbol newSymbol) {
24
		return (newSymbol instanceof LineFillSymbol);
25
	}
26

  
27

  
28

  
29

  
30
}
trunk/extSymbology/src-test/org/gvsig/symbology/symbols/PictureMarkerSymbolTest.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.symbols;
42

  
43
import java.io.File;
44

  
45
import org.gvsig.symbology.fmap.symbols.PictureLineSymbol;
46
import org.gvsig.symbology.fmap.symbols.PictureMarkerSymbol;
47

  
48
import com.iver.cit.gvsig.fmap.core.symbols.AbstractSymbolTestCase;
49
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
50
import com.iver.cit.gvsig.fmap.core.symbols.TestISymbol;
51

  
52
public class PictureMarkerSymbolTest extends AbstractSymbolTestCase {
53
	public PictureMarkerSymbolTest() {
54
		super(PictureLineSymbol.class);
55
	}
56
	
57
	@Override
58
	public ISymbol newInstance() {
59
        try {
60
    		PictureMarkerSymbol pms = (PictureMarkerSymbol) super.newInstance();
61
			pms.setImage(new File(TestISymbol.class.getResource("picture-marker.png").getFile()));
62
			pms.setSelImage(new File(TestISymbol.class.getResource("picture-marker-selected.png").getFile()));
63
			return pms;
64
        }  catch (Exception e) {
65
			fail("Failed installing symbol to test "+symClazz.getName());
66
			return null;
67
		} 
68
	}
69

  
70
}
trunk/extSymbology/src-test/org/gvsig/symbology/symbols/DrawPictureFillSymbol.java
1
package org.gvsig.symbology.symbols;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.symbology.fmap.symbols.PictureFillSymbol;
6

  
7
import com.iver.cit.gvsig.fmap.core.symbols.IDrawFillSymbol;
8
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
9

  
10
public class DrawPictureFillSymbol implements IDrawFillSymbol {
11

  
12
	public boolean isSuitableFor(IFillSymbol newSymbol) {
13
		return (newSymbol instanceof PictureFillSymbol);
14
	}
15

  
16
	public IFillSymbol makeSymbolTransparent(IFillSymbol newSymbol) {
17
		if (newSymbol instanceof PictureFillSymbol) {
18
			PictureFillSymbol mySymbol = (PictureFillSymbol) newSymbol;
19
			try {
20
				((PictureFillSymbol) mySymbol).setImage(null);
21
			} catch (IOException e) {
22
				e.printStackTrace();
23
			}
24
			return mySymbol;
25
		}
26
		return newSymbol;
27
	}
28
}
trunk/extSymbology/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<libraries library-dir="."/>
4
	<depends plugin-name="com.iver.cit.gvsig"/>
5
		<resourceBundle name="text"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.symbology.ExtendedSymbologyExtension"
8
			description="Enables the extended symbology (available since v1.2)."
9
			active="true"
10
			priority="20">
11
		</extension>
12
	</extensions>
13
</plugin-config>
trunk/extSymbology/src/org/gvsig/symbology/Utils.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;
42

  
43
import java.awt.Color;
44
import java.io.File;
45
import java.io.IOException;
46

  
47
import org.gvsig.symbology.fmap.symbols.LineFillSymbol;
48
import org.gvsig.symbology.fmap.symbols.PictureMarkerSymbol;
49

  
50
import com.iver.cit.gvsig.fmap.core.CartographicSupport;
51
import com.iver.cit.gvsig.fmap.core.FShape;
52
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
53
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle;
54
import com.iver.cit.gvsig.fmap.core.symbols.AbstractSymbol;
55
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
56
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
57
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
58
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol;
59
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
60
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
61
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
62
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
63
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
64
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
65

  
66
public class Utils {
67
	public static ISymbol deriveFSymbol(FSymbol fSymbol) {
68
		ISymbol derivedSymbol;
69
		
70
		int symbolType = fSymbol.getSymbolType();
71
		Color color = fSymbol.getColor();
72
		double size = fSymbol.getSize();
73
		int unit = fSymbol.isSizeInPixels() ? -1 : 1; // only meters or pixels
74
														// were supported in
75
														// FSymbol
76
		if (symbolType == FShape.LINE) {
77
			ILineSymbol line = SymbologyFactory.createDefaultLineSymbol();
78
			line.setLineColor(color);
79

  
80
			SimpleLineStyle lineStyle = new SimpleLineStyle();
81
			lineStyle.setUnit(unit); 
82
			lineStyle.setStroke(fSymbol.getStroke());
83
			lineStyle.setOffset(0);
84
			lineStyle.setReferenceSystem(CartographicSupport.WORLD);
85
			lineStyle.setLineWidth((float) size);
86
			line.setLineStyle(lineStyle);
87
			derivedSymbol = line;
88
			
89
		} else if (symbolType == FShape.POINT) {
90
			int style = fSymbol.getStyle();
91
			IMarkerSymbol marker; 
92
			if (style == FConstant.SYMBOL_STYLE_MARKER_IMAGEN) {
93
				marker = new PictureMarkerSymbol();
94
				PictureMarkerSymbol pic = (PictureMarkerSymbol) marker;
95
				try {
96
					pic.setImage(new File(fSymbol.getIconURI().getPath()));
97
				} catch (IOException e) {
98
					// image could not be restored,
99
					// will use a regular point as symbol
100
					fSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE);
101
					return deriveFSymbol(fSymbol);
102
				}
103
			} else {
104
				marker = new SimpleMarkerSymbol();
105
				SimpleMarkerSymbol sms = (SimpleMarkerSymbol) marker;
106
				if (style == FConstant.SYMBOL_STYLE_MARKER_CIRCLE) {
107
					sms.setStyle(SimpleMarkerSymbol.CIRCLE_STYLE);
108
				} else if (style == FConstant.SYMBOL_STYLE_MARKER_CROSS) {
109
					sms.setStyle(SimpleMarkerSymbol.CROSS_STYLE);
110
				} else if (style == FConstant.SYMBOL_STYLE_MARKER_SQUARE) {
111
					sms.setStyle(SimpleMarkerSymbol.SQUARE_STYLE);
112
				} else if (style == FConstant.SYMBOL_STYLE_MARKER_TRIANGLE) {
113
					sms.setStyle(SimpleMarkerSymbol.TRIANGLE_STYLE);
114
				}
115
				Color outlineColor = fSymbol.getOutlineColor();
116
				if (outlineColor != null) {
117
					sms.setOutlined(true);
118
					sms.setOutlineColor(outlineColor);
119
				}
120
			}
121
			marker.setColor(color);
122
			marker.setSize(size);
123
			marker.setRotation(fSymbol.getRotation());
124
			derivedSymbol = marker;
125
			
126
		} else if (symbolType == FShape.POLYGON) {
127
			IFillSymbol fill;
128
			int fSymbolStyle = fSymbol.getStyle();
129
			color = null;
130
			if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_SOLID) {
131
				fill = SymbologyFactory.createDefaultFillSymbol();
132
				color = fSymbol.getColor();
133
			} else if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_TRANSPARENT ||
134
					   fSymbolStyle == FConstant.SYMBOL_STYLE_DGNSPECIAL) {
135
				fill = SymbologyFactory.createDefaultFillSymbol();
136
			} else {
137
				// lets see how to derive FSymbol with fill patterns
138
				if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_CROSS) {
139
					// the cross will be substituted by two line fill symbols
140
					// with
141
					// perpendicular line angles mixed into a multilayer symbol
142
					IMultiLayerSymbol mfs = SymbologyFactory.createEmptyMultiLayerSymbol(FShape.POLYGON);
143
					fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_VERTICAL);
144
					LineFillSymbol firstLayer = (LineFillSymbol) deriveFSymbol(fSymbol);
145
					fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_HORIZONTAL);
146
					LineFillSymbol secondLayer = (LineFillSymbol) deriveFSymbol(fSymbol);
147
					mfs.addLayer(firstLayer);
148
					mfs.addLayer(secondLayer);
149
					fill = (IFillSymbol) mfs;
150
					fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_CROSS); // restore
151
																			// old
152
																			// style
153
																			// (just
154
																			// in
155
																			// case)
156
				} else if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL ) {
157
					// the cross will be substituted by two line fill symbols
158
					// with
159
					// perpendicular line angles mixed into a multilayer symbol
160
					IMultiLayerSymbol mfs = SymbologyFactory.createEmptyMultiLayerSymbol(FShape.POLYGON);
161
					fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL);
162
					LineFillSymbol firstLayer = (LineFillSymbol) deriveFSymbol(fSymbol);
163
					fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL);
164
					LineFillSymbol secondLayer = (LineFillSymbol) deriveFSymbol(fSymbol);
165
					mfs.addLayer(firstLayer);
166
					mfs.addLayer(secondLayer);
167
					fill = (IFillSymbol) mfs;
168
					fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL); // restore
169
																			// old
170
																			// style
171
																			// (just
172
																			// in
173
																			// case)
174
				} else {
175
					LineFillSymbol lfs = new LineFillSymbol();
176
					// Let's create the filling line symbol
177
					fSymbol.setSymbolType(FShape.LINE);
178
					ILineSymbol lineSymbol = (ILineSymbol) deriveFSymbol(fSymbol);
179
					SimpleLineStyle lineStyle = new SimpleLineStyle();
180
					lineStyle.setLineWidth(1f);
181
					lineSymbol.setLineStyle(lineStyle);
182
					
183
					// restore the old value for symbol type (should be always
184
					// FShape.POLYGON)
185
					assert symbolType == FShape.POLYGON;
186
					fSymbol.setSymbolType(symbolType);
187
					double angle = 0;
188
					switch (fSymbolStyle) {
189
					case FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL:
190
						angle = 45;
191
						break;
192
					case FConstant.SYMBOL_STYLE_FILL_VERTICAL:
193
						angle = 90;
194
						break;
195
					case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL:
196
						angle = 0;
197
						break;
198
					case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL:
199
						angle = -45;
200
						break;
201
					}
202
					lfs.setSeparation(10);
203
					lfs.setAngle(angle*FConstant.DEGREE_TO_RADIANS);
204
					lfs.setLineSymbol(lineSymbol);
205
					fill = lfs;
206
				}
207
			}
208
			
209
			fill.setFillColor(color);
210

  
211
			if (fSymbol.isOutlined()) {
212
				// Let's create the outline line symbol
213
				fSymbol.setSymbolType(FShape.LINE);
214
				ILineSymbol outline = (ILineSymbol) deriveFSymbol(fSymbol);
215
				
216
				// restore the old value for symbol type (should be always
217
				// FShape.POLYGON)
218
				assert symbolType == FShape.POLYGON;
219
				fSymbol.setSymbolType(symbolType);
220
				outline.setLineColor(fSymbol.getOutlineColor());
221
				fill.setOutline(outline);
222
			}
223
			derivedSymbol = fill;
224
		} else if (symbolType == FShape.MULTI) {
225
			fSymbol.setSymbolType(FShape.LINE);
226
			ILineSymbol line = (ILineSymbol) deriveFSymbol(fSymbol);
227
			fSymbol.setSymbolType(FShape.POINT);
228
			IMarkerSymbol marker = (IMarkerSymbol) deriveFSymbol(fSymbol);
229
			fSymbol.setSymbolType(FShape.POLYGON);
230
			IFillSymbol fill = (IFillSymbol) deriveFSymbol(fSymbol);
231
			assert symbolType == FShape.MULTI;
232
			fSymbol.setSymbolType(symbolType);
233
			MultiShapeSymbol multiShapeSymbol = new MultiShapeSymbol();
234
			multiShapeSymbol.setMarkerSymbol(marker);
235
			multiShapeSymbol.setLineSymbol(line);
236
			multiShapeSymbol.setFillSymbol(fill);
237
			
238
			derivedSymbol = multiShapeSymbol;
239
		} else if (symbolType == FShape.TEXT) {
240
			ITextSymbol textSym = SymbologyFactory.createDefaultTextSymbol();
241
			textSym.setTextColor(color);
242
			derivedSymbol = textSym;
243
		} else {
244
			throw new Error("FSymbol of type "+symbolType+" cannot be imported yet!");
245
		}
246
		
247
		// establish the general description;
248
		if (derivedSymbol instanceof AbstractSymbol) {
249
			AbstractSymbol symbol = (AbstractSymbol) derivedSymbol;
250
			symbol.setIsShapeVisible(true);
251
			symbol.setDescription(fSymbol.getDescription());
252
		}
253
		
254
		
255
		
256
		if (derivedSymbol instanceof CartographicSupport) {
257
			CartographicSupport cs = (CartographicSupport) derivedSymbol;
258
			// the only options allowed by the old FSymbol class
259
			cs.setUnit(unit);
260
			cs.setReferenceSystem(CartographicSupport.WORLD);
261
		}
262
		
263
		return derivedSymbol;
264
	}
265
}
trunk/extSymbology/src/org/gvsig/symbology/ExtendedSymbologyExtension.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;
42

  
43
import org.gvsig.symbology.fmap.labeling.FeatureDependentLabeled;
44
import org.gvsig.symbology.fmap.labeling.GeneralLabelingStrategy;
45
import org.gvsig.symbology.fmap.labeling.OnSelectionLabeled;
46
import org.gvsig.symbology.fmap.labeling.PlacementManager;
47
import org.gvsig.symbology.fmap.labeling.lang.functions.IndexOf;
48
import org.gvsig.symbology.fmap.labeling.lang.functions.Substring;
49
import org.gvsig.symbology.fmap.labeling.parse.LabelExpressionParser;
50
import org.gvsig.symbology.fmap.labeling.placements.LinePlacementAtBest;
51
import org.gvsig.symbology.fmap.labeling.placements.LinePlacementAtExtremities;
52
import org.gvsig.symbology.fmap.labeling.placements.LinePlacementInTheMiddle;
53
import org.gvsig.symbology.fmap.labeling.placements.MarkerCenteredAtPoint;
54
import org.gvsig.symbology.fmap.labeling.placements.MarkerPlacementAroundPoint;
55
import org.gvsig.symbology.fmap.labeling.placements.MarkerPlacementOnPoint;
56
import org.gvsig.symbology.fmap.labeling.placements.PolygonPlacementOnCentroid;
57
import org.gvsig.symbology.fmap.labeling.placements.PolygonPlacementParallel;
58
import org.gvsig.symbology.gui.layerproperties.DotDensity;
59
import org.gvsig.symbology.gui.layerproperties.GeneralLabeling;
60
import org.gvsig.symbology.gui.layerproperties.GraduatedSymbols;
61
import org.gvsig.symbology.gui.layerproperties.QuantityByCategory;
62
import org.gvsig.symbology.gui.styling.CharacterMarker;
63
import org.gvsig.symbology.gui.styling.GradientFill;
64
import org.gvsig.symbology.gui.styling.LineFill;
65
import org.gvsig.symbology.gui.styling.MarkerFill;
66
import org.gvsig.symbology.gui.styling.MarkerLine;
67
import org.gvsig.symbology.gui.styling.PictureFill;
68
import org.gvsig.symbology.gui.styling.PictureLine;
69
import org.gvsig.symbology.gui.styling.PictureMarker;
70
import org.gvsig.symbology.gui.styling.editortools.LabelStyleNewTextFieldTool;
71
import org.gvsig.symbology.gui.styling.editortools.LabelStyleOpenBackgroundFile;
72
import org.gvsig.symbology.gui.styling.editortools.LabelStylePanTool;
73
import org.gvsig.symbology.gui.styling.editortools.LabelStyleRemoveLastTextField;
74

  
75
import com.iver.andami.PluginServices;
76
import com.iver.andami.plugins.Extension;
77
import com.iver.cit.gvsig.fmap.core.FShape;
78
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.DefaultLabelingMethod;
79
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory;
80
import com.iver.cit.gvsig.gui.styling.StyleEditor;
81
import com.iver.cit.gvsig.gui.styling.SymbolEditor;
82
import com.iver.cit.gvsig.project.documents.view.legend.gui.LabelingManager;
83
import com.iver.cit.gvsig.project.documents.view.legend.gui.LegendManager;
84

  
85
public class ExtendedSymbologyExtension extends Extension {
86

  
87
	public void execute(String actionCommand) {
88
		
89
	}
90

  
91
	public void initialize() {
92
		
93
        PluginServices.getIconTheme().registerDefault(
94
        		"high-density",
95
        		DotDensity.class.getClassLoader().getResource("images/high-density-sample.png")
96
        	);
97
        PluginServices.getIconTheme().registerDefault(
98
        		"medium-density",
99
        		DotDensity.class.getClassLoader().getResource("images/medium-density-sample.png")
100
        	);
101
        PluginServices.getIconTheme().registerDefault(
102
        		"low-density",
103
        		DotDensity.class.getClassLoader().getResource("images/low-density-sample.png")
104
        	);
105
        PluginServices.getIconTheme().registerDefault(
106
        		"quantities-by-category",
107
        		QuantityByCategory.class.getClassLoader().getResource("images/QuantitiesByCategory.png")
108
        );
109
        PluginServices.getIconTheme().registerDefault(
110
				"add-text-icon",
111
				this.getClass().getClassLoader().getResource("images/add-text.png")
112
			);      
113
        PluginServices.getIconTheme().registerDefault(
114
        		"remove-text-icon",
115
        		this.getClass().getClassLoader().getResource("images/remove-text.png")
116
        );
117
        PluginServices.getIconTheme().registerDefault(
118
				"hand-icon",
119
				this.getClass().getClassLoader().getResource("images/hand.gif")
120
			);
121
        
122
		// modules for symbol editor
123
		SymbolEditor.addSymbolEditorPanel(MarkerFill.class, FShape.POLYGON);
124
		SymbolEditor.addSymbolEditorPanel(PictureFill.class, FShape.POLYGON);
125
		SymbolEditor.addSymbolEditorPanel(LineFill.class, FShape.POLYGON);
126
		SymbolEditor.addSymbolEditorPanel(GradientFill.class, FShape.POLYGON);
127
		SymbolEditor.addSymbolEditorPanel(CharacterMarker.class, FShape.POINT);
128
		SymbolEditor.addSymbolEditorPanel(PictureMarker.class, FShape.POINT);
129
		SymbolEditor.addSymbolEditorPanel(PictureLine.class, FShape.LINE);
130
		SymbolEditor.addSymbolEditorPanel(MarkerLine.class, FShape.LINE);
131

  
132
		// legends available in the legend page
133
		LegendManager.addLegendPage(DotDensity.class);
134
		LegendManager.addLegendPage(GraduatedSymbols.class);
135
//		LegendManager.addLegendPage(QuantityByCategory.class);
136
//		LegendManager.addLegendPage(ProportionalSymbols.class);
137
		
138
		// Editor tools
139
		StyleEditor.addEditorTool(LabelStylePanTool.class);
140
		StyleEditor.addEditorTool(LabelStyleNewTextFieldTool.class);
141
		StyleEditor.addEditorTool(LabelStyleRemoveLastTextField.class);
142
		StyleEditor.addEditorTool(LabelStyleOpenBackgroundFile.class);
143
		
144
		LabelingManager.addLabelingStrategy(GeneralLabeling.class);
145

  
146

  
147
		// labeling methods in the labeling page
148
		//						(inverse order to the wanted to be shown)
149
		GeneralLabeling.addLabelingMethod(
150
				PluginServices.getText(this, "label_only_when_selected")+".",
151
				OnSelectionLabeled.class);
152
		GeneralLabeling.addLabelingMethod(
153
				PluginServices.getText(this, "define_classes_of_features_and_label_each_differently")+".",
154
				FeatureDependentLabeled.class);
155
		GeneralLabeling.addLabelingMethod(
156
				PluginServices.getText(this, "label_features_in_the_same_way")+".",
157
				DefaultLabelingMethod.class);
158

  
159
		PlacementManager.addLabelPlacement(LinePlacementAtExtremities.class);
160
		PlacementManager.addLabelPlacement(LinePlacementAtBest.class);
161
		PlacementManager.addLabelPlacement(LinePlacementInTheMiddle.class);
162
		PlacementManager.addLabelPlacement(MarkerPlacementOnPoint.class);
163
		PlacementManager.addLabelPlacement(MarkerCenteredAtPoint.class);
164
		PlacementManager.addLabelPlacement(MarkerPlacementAroundPoint.class);
165
		PlacementManager.addLabelPlacement(PolygonPlacementOnCentroid.class);
166
		PlacementManager.addLabelPlacement(PolygonPlacementParallel.class);
167
		
168
		LabelingFactory.setDefaultLabelingStrategy(GeneralLabelingStrategy.class);
169
		
170
		LabelExpressionParser.addFunction(Substring.class);
171
		LabelExpressionParser.addFunction(IndexOf.class);
172
	}
173

  
174
	public boolean isEnabled() {
175
		return true; // or whatever
176
	}
177

  
178
	public boolean isVisible() {
179
		return true; // or whatever
180
	}
181

  
182

  
183

  
184
}
trunk/extSymbology/src/org/gvsig/symbology/fmap/styles/PointLabelPositioneer.java
1
package org.gvsig.symbology.fmap.styles;
2

  
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.awt.Graphics2D;
6
import java.awt.Rectangle;
7
import java.awt.RenderingHints;
8

  
9
import com.iver.cit.gvsig.fmap.core.FShape;
10
import com.iver.cit.gvsig.fmap.core.styles.AbstractStyle;
11
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
12
import com.iver.utiles.XMLEntity;
13

  
14

  
15
/**
16
 *  Specifies the point positioner for a label
17
 *
18
 *
19
 */
20
public class PointLabelPositioneer extends AbstractStyle {
21
	private byte[] preferenceVector = new byte[8];
22
	private static final Color[] colorVector = new Color[] {
23
		new Color(140, 140, 140), // gray
24
		new Color(140, 245, 130), // green
25
		new Color(130, 170, 245), // light blue
26
		new Color(100, 100, 255),   // dark blue
27
	};
28
	
29
	public static final byte FORBIDDEN 		   = 0;
30
	public static final byte PREFERENCE_HIGH   = 1;
31
	public static final byte PREFERENCE_NORMAL = 2;
32
	public static final byte PREFERENCE_LOW    = 3;
33
	/**
34
	 * Constructor method
35
	 *
36
	 */
37
	public PointLabelPositioneer() {}
38

  
39
	/**
40
	 * Constructor method
41
	 *
42
	 * @param preferenceVector
43
	 * @param description
44
	 */
45
	public PointLabelPositioneer(byte[] preferenceVector, String description) {
46
		this.preferenceVector = preferenceVector;
47
		setDescription(description);
48
	}
49

  
50
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
51
		int size = Math.min(r.width, r.height) / 3;
52
		int j = -1;
53
		final int fontSize = (int) (size * 0.8);
54
		final Font font = new Font("Arial", Font.PLAIN, fontSize);
55
		RenderingHints old = g.getRenderingHints();
56
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
57
		for (int i = 0; i < 9; i++) {
58
			if (i == 4) continue;
59
			j++;
60
			int value = Math.abs(preferenceVector[j] % colorVector.length);
61
			int col = i % 3;
62
			int row = i / 3;
63

  
64
			g.setColor(colorVector[value]);
65
			g.fillRect(size * col, size*row, size, size);
66
			g.setColor(Color.BLACK);
67
			g.drawRect(size * col, size*row, size, size);
68
			g.setFont(font);
69
			g.drawString(String.valueOf(value),
70
					(float) ((size/2) - (fontSize/4)) + size * col,
71
					(float) (size * 0.8) + size*row);
72
		}
73
		g.setRenderingHints(old);
74
	}
75

  
76
	public boolean isSuitableFor(ISymbol symbol) {
77
		return symbol.getSymbolType() == FShape.POINT;
78
	}
79

  
80
	public String getClassName() {
81
		return getClass().getName();
82
	}
83

  
84
	public XMLEntity getXMLEntity() {
85
		XMLEntity xml = new XMLEntity();
86
		xml.putProperty("className", getClassName());
87
		xml.putProperty("desc", getDescription());
88
		StringBuffer sb = new StringBuffer();
89
		for (int i = 0; i < preferenceVector.length; i++) {
90
			sb.append(preferenceVector[i]+" ,");
91
		}
92
		String s = sb.substring(0, sb.length()-2);
93
		xml.putProperty("preferenceVector", s);
94
		return xml;
95
	}
96

  
97
	public void setXMLEntity(XMLEntity xml) {
98
		setDescription(xml.getStringProperty("desc"));
99
		preferenceVector = xml.getByteArrayProperty("preferenceVector");
100
	}
101

  
102
	public void drawOutline(Graphics2D g, Rectangle r) {
103
		drawInsideRectangle(g, r);
104
	}
105

  
106
	public byte[] getPreferenceVector() {
107
		return preferenceVector;
108
	}
109
}
trunk/extSymbology/src/org/gvsig/symbology/fmap/styles/SimpleLabelStyle.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.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff