Revision 10401
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
org.gvsig.tools packages. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.tools"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
<category name="org.gvsig.construc"> |
|
26 |
<priority value="DEBUG" /> |
|
27 |
</category> |
|
28 |
|
|
29 |
<!-- |
|
30 |
By default, show only logging messages of INFO level or higher, |
|
31 |
through the previously configured CONSOLE appender. |
|
32 |
--> |
|
33 |
<root> |
|
34 |
<priority value="INFO" /> |
|
35 |
<appender-ref ref="CONSOLE" /> |
|
36 |
</root> |
|
37 |
</log4j:configuration> |
|
0 | 38 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your classes. |
|
2 |
|
|
3 |
This folder is added to the classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your classes. |
|
0 | 9 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/main/java/org/gvsig/complexlegend/ComplexLegendItem.java | ||
---|---|---|
1 |
package org.gvsig.complexlegend; |
|
2 |
|
|
3 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
4 |
|
|
5 |
public interface ComplexLegendItem extends org.gvsig.tools.lang.Cloneable{ |
|
6 |
|
|
7 |
public ILegend getLegend(); |
|
8 |
public void setLegend(ILegend legend); |
|
9 |
|
|
10 |
public double getMaxScale(); |
|
11 |
public void setMaxScale(double maxScale); |
|
12 |
|
|
13 |
public double getMinScale(); |
|
14 |
public void setMinScale(double maxScale); |
|
15 |
|
|
16 |
public String toString(); |
|
17 |
} |
|
0 | 18 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/main/java/org/gvsig/complexlegend/VectorComplexLegend.java | ||
---|---|---|
1 |
package org.gvsig.complexlegend; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend; |
|
6 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
7 |
|
|
8 |
public interface VectorComplexLegend extends IVectorLegend, IClassifiedLegend{ |
|
9 |
|
|
10 |
public List<ComplexLegendItem> getLegends(); |
|
11 |
|
|
12 |
public boolean add(ComplexLegendItem legend); |
|
13 |
public boolean remove(ComplexLegendItem legend); |
|
14 |
|
|
15 |
public boolean isOverlapped(ComplexLegendItem legend); |
|
16 |
public ComplexLegendItem getLegend(double scale); |
|
17 |
|
|
18 |
public boolean getAllowOverlap(); |
|
19 |
public void setAllowOverlap(boolean allowOverlap); |
|
20 |
} |
|
0 | 21 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/main/java/org/gvsig/complexlegend/ComplexLegendLibrary.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.complexlegend; |
|
23 |
|
|
24 |
import org.gvsig.fmap.dal.DALLibrary; |
|
25 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
26 |
import org.gvsig.symbology.SymbologyLibrary; |
|
27 |
import org.gvsig.tools.ToolsLibrary; |
|
28 |
import org.gvsig.tools.library.AbstractLibrary; |
|
29 |
import org.gvsig.tools.library.LibraryException; |
|
30 |
|
|
31 |
|
|
32 |
/** |
|
33 |
* Library for API initialization and configuration. |
|
34 |
* |
|
35 |
* @author gvSIG team |
|
36 |
* @version $Id$ |
|
37 |
*/ |
|
38 |
public class ComplexLegendLibrary extends AbstractLibrary { |
|
39 |
|
|
40 |
@Override |
|
41 |
public void doRegistration() { |
|
42 |
registerAsAPI(ComplexLegendLibrary.class); |
|
43 |
this.require(ToolsLibrary.class); |
|
44 |
this.require(GeometryLibrary.class); |
|
45 |
this.require(SymbologyLibrary.class); |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
@Override |
|
50 |
protected void doInitialize() throws LibraryException { |
|
51 |
// Do nothing |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
protected void doPostInitialize() throws LibraryException { |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
} |
|
0 | 60 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/main/java/org/gvsig/complexlabel/ComplexLabelClass.java | ||
---|---|---|
1 |
package org.gvsig.complexlabel; |
|
2 |
|
|
3 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
|
4 |
|
|
5 |
public interface ComplexLabelClass extends ILabelClass{ |
|
6 |
|
|
7 |
public double getMinScale(); |
|
8 |
|
|
9 |
public double getMaxScale(); |
|
10 |
|
|
11 |
public void setMinScale(double scale); |
|
12 |
|
|
13 |
public void setMaxScale(double scale); |
|
14 |
|
|
15 |
} |
|
0 | 16 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/main/java/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.landregistryviewer package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>LandRegistryViewer library API.</p> |
|
11 |
|
|
12 |
<p> |
|
13 |
It allows to get new LandRegistryViewer and get their text. |
|
14 |
</p> |
|
15 |
|
|
16 |
</body> |
|
17 |
</html> |
|
0 | 18 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.complexlegend.ComplexLegendLibrary |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.api/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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.complexlegend.lib.api</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.complexlegend.lib.api</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.complexlegend.lib</artifactId> |
|
10 |
<version>1.0.255</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
16 |
<scope>compile</scope> |
|
17 |
</dependency> |
|
18 |
<dependency> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.fmap.mapcontext.api</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.symbology.lib.api</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
</dependencies> |
|
34 |
<build> |
|
35 |
<plugins> |
|
36 |
<plugin> |
|
37 |
<groupId>org.apache.maven.plugins</groupId> |
|
38 |
<artifactId>maven-jar-plugin</artifactId> |
|
39 |
<configuration> |
|
40 |
</configuration> |
|
41 |
<executions> |
|
42 |
<!-- Generates a jar file only with the test classes --> |
|
43 |
<execution> |
|
44 |
<goals> |
|
45 |
<goal>test-jar</goal> |
|
46 |
</goals> |
|
47 |
</execution> |
|
48 |
</executions> |
|
49 |
</plugin> |
|
50 |
</plugins> |
|
51 |
</build> |
|
52 |
|
|
53 |
</project> |
|
0 | 54 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.complexlegend.lib</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>org.gvsig.complexlegend.lib</name> |
|
8 |
<parent> |
|
9 |
<groupId>org.gvsig</groupId> |
|
10 |
<artifactId>org.gvsig.complexlegend</artifactId> |
|
11 |
<version>1.0.255</version> |
|
12 |
</parent> |
|
13 |
<dependencies> |
|
14 |
</dependencies> |
|
15 |
<modules> |
|
16 |
<module>org.gvsig.complexlegend.lib.api</module> |
|
17 |
<module>org.gvsig.complexlegend.lib.impl</module> |
|
18 |
</modules> |
|
19 |
</project> |
|
0 | 20 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.complexlegend.lib.impl</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.complexlegend.lib.impl</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.complexlegend.lib</artifactId> |
|
10 |
<version>1.0.255</version> |
|
11 |
</parent> |
|
12 |
|
|
13 |
<dependencies> |
|
14 |
<dependency> |
|
15 |
<groupId>org.gvsig</groupId> |
|
16 |
<artifactId>org.gvsig.complexlegend.lib.api</artifactId> |
|
17 |
<scope>compile</scope> |
|
18 |
</dependency> |
|
19 |
<dependency> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.symbology.lib.api</artifactId> |
|
22 |
<scope>compile</scope> |
|
23 |
</dependency> |
|
24 |
<dependency> |
|
25 |
<groupId>org.gvsig</groupId> |
|
26 |
<artifactId>org.gvsig.symbology.lib.impl</artifactId> |
|
27 |
<scope>compile</scope> |
|
28 |
</dependency> |
|
29 |
<dependency> |
|
30 |
<groupId>org.gvsig</groupId> |
|
31 |
<artifactId>org.gvsig.symbology.swing.api</artifactId> |
|
32 |
<scope>compile</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.fmap.mapcontext.api</artifactId> |
|
37 |
<scope>compile</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>org.gvsig</groupId> |
|
41 |
<artifactId> org.gvsig.app.mainplugin</artifactId> |
|
42 |
<scope>compile</scope> |
|
43 |
</dependency> |
|
44 |
</dependencies> |
|
45 |
</project> |
|
0 | 46 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.complexlegend.impl.DefaultComplexLegendLibrary |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/java/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.landregistryviewer package documentation</title> |
|
7 |
</head> |
|
8 |
<body> |
|
9 |
|
|
10 |
<p>LandRegistryViewer library API default implementation.</p> |
|
11 |
|
|
12 |
</body> |
|
13 |
</html> |
|
0 | 14 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/java/org/gvsig/complexlegend/impl/ComplexLegendUtils.java | ||
---|---|---|
1 |
package org.gvsig.complexlegend.impl; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.gvsig.app.project.documents.view.legend.gui.AbstractParentPanel; |
|
7 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
|
8 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
9 |
import org.gvsig.symbology.swing.SymbologySwingLocator; |
|
10 |
|
|
11 |
public class ComplexLegendUtils { |
|
12 |
|
|
13 |
public static ILegendPanel getLegendPanel(ILegend legend){ |
|
14 |
List panels = SymbologySwingLocator.getSwingManager().getLegendEditorClasses(); |
|
15 |
Iterator it = panels.iterator(); |
|
16 |
while(it.hasNext()){ |
|
17 |
Class panelClass = (Class) it.next(); |
|
18 |
ILegendPanel panel; |
|
19 |
try { |
|
20 |
panel = (ILegendPanel) panelClass.newInstance(); |
|
21 |
if(!(panel instanceof AbstractParentPanel)){ |
|
22 |
if(panel.getLegendClass().equals(legend.getClass())){ |
|
23 |
return panel; |
|
24 |
} |
|
25 |
} |
|
26 |
} catch (Exception e) { |
|
27 |
return null; |
|
28 |
} |
|
29 |
} |
|
30 |
return null; |
|
31 |
} |
|
32 |
|
|
33 |
} |
|
0 | 34 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/java/org/gvsig/complexlegend/impl/DefaultComplexLegendItem.java | ||
---|---|---|
1 |
package org.gvsig.complexlegend.impl; |
|
2 |
|
|
3 |
import java.text.NumberFormat; |
|
4 |
|
|
5 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
|
6 |
import org.gvsig.complexlegend.ComplexLegendItem; |
|
7 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
8 |
import org.gvsig.tools.ToolsLocator; |
|
9 |
import org.gvsig.tools.dynobject.DynStruct; |
|
10 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
11 |
import org.gvsig.tools.persistence.Persistent; |
|
12 |
import org.gvsig.tools.persistence.PersistentState; |
|
13 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
14 |
import org.gvsig.tools.util.Callable; |
|
15 |
import org.slf4j.Logger; |
|
16 |
import org.slf4j.LoggerFactory; |
|
17 |
|
|
18 |
public class DefaultComplexLegendItem implements ComplexLegendItem, Persistent { |
|
19 |
|
|
20 |
public static final Logger logger = LoggerFactory.getLogger(DefaultComplexLegendItem.class); |
|
21 |
public static final String COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME = "ComplexLegendItem"; |
|
22 |
private ILegend legend; |
|
23 |
private double maxScale; |
|
24 |
private double minScale; |
|
25 |
|
|
26 |
public ILegend getLegend() { |
|
27 |
return legend; |
|
28 |
} |
|
29 |
|
|
30 |
public void setLegend(ILegend legend) { |
|
31 |
this.legend = legend; |
|
32 |
} |
|
33 |
|
|
34 |
public double getMaxScale() { |
|
35 |
return maxScale; |
|
36 |
} |
|
37 |
|
|
38 |
public void setMaxScale(double maxScale) { |
|
39 |
this.maxScale = maxScale; |
|
40 |
} |
|
41 |
|
|
42 |
public double getMinScale() { |
|
43 |
return minScale; |
|
44 |
} |
|
45 |
|
|
46 |
public void setMinScale(double minScale) { |
|
47 |
this.minScale = minScale; |
|
48 |
} |
|
49 |
|
|
50 |
public String toString() { |
|
51 |
|
|
52 |
String panel = ""; |
|
53 |
if (legend != null) { |
|
54 |
ILegendPanel legPanel = ComplexLegendUtils.getLegendPanel(legend); |
|
55 |
if (legPanel != null) { |
|
56 |
panel = " " + legPanel.getTitle(); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
Double mind = (Double) getMinScale(); |
|
61 |
String min = "0"; |
|
62 |
if (mind >= 0) { |
|
63 |
int mini = mind.intValue(); |
|
64 |
min = NumberFormat.getIntegerInstance().format(mini); |
|
65 |
} |
|
66 |
|
|
67 |
Double maxd = (Double) getMaxScale(); |
|
68 |
String max = "inf"; |
|
69 |
if (maxd >= 0) { |
|
70 |
int maxi = maxd.intValue(); |
|
71 |
max = NumberFormat.getIntegerInstance().format(maxi); |
|
72 |
} |
|
73 |
return "[1:" + min + " - 1:" + max + "]" + panel; |
|
74 |
} |
|
75 |
|
|
76 |
public void loadFromState(PersistentState state) |
|
77 |
throws PersistenceException { |
|
78 |
// Set own properties |
|
79 |
setLegend((ILegend) state.get("legend")); |
|
80 |
setMinScale(state.getDouble("minScale")); |
|
81 |
setMaxScale(state.getDouble("maxScale")); |
|
82 |
} |
|
83 |
|
|
84 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
85 |
// Save own properties |
|
86 |
state.set("legend", getLegend()); |
|
87 |
state.set("minScale", getMinScale()); |
|
88 |
state.set("maxScale", getMaxScale()); |
|
89 |
} |
|
90 |
|
|
91 |
public static class RegisterPersistence implements Callable { |
|
92 |
|
|
93 |
public Object call() throws Exception { |
|
94 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
95 |
if (manager.getDefinition( |
|
96 |
COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME) == null) { |
|
97 |
DynStruct definition = manager.addDefinition( |
|
98 |
DefaultComplexLegendItem.class, |
|
99 |
COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME, |
|
100 |
COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME |
|
101 |
+ " Persistence definition", |
|
102 |
null, |
|
103 |
null |
|
104 |
); |
|
105 |
|
|
106 |
definition.addDynFieldObject("legend").setMandatory(true) |
|
107 |
.setClassOfValue(ILegend.class); |
|
108 |
definition.addDynFieldDouble("minScale").setMandatory(true); |
|
109 |
definition.addDynFieldDouble("maxScale").setMandatory(true); |
|
110 |
} |
|
111 |
return Boolean.TRUE; |
|
112 |
} |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public Object clone() throws CloneNotSupportedException { |
|
118 |
DefaultComplexLegendItem cloned = (DefaultComplexLegendItem) super.clone(); //To change body of generated methods, choose Tools | Templates. |
|
119 |
cloned.legend = (ILegend) this.legend.clone(); |
|
120 |
return cloned; |
|
121 |
} |
|
122 |
} |
|
0 | 123 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/java/org/gvsig/complexlegend/impl/DefaultVectorComplexLegend.java | ||
---|---|---|
1 |
package org.gvsig.complexlegend.impl; |
|
2 |
|
|
3 |
import java.awt.Graphics2D; |
|
4 |
import java.awt.geom.AffineTransform; |
|
5 |
import java.awt.image.BufferedImage; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.Collections; |
|
8 |
import java.util.Comparator; |
|
9 |
import java.util.Iterator; |
|
10 |
import java.util.List; |
|
11 |
import java.util.Map; |
|
12 |
|
|
13 |
import org.cresques.cts.ICoordTrans; |
|
14 |
import org.gvsig.compat.print.PrintAttributes; |
|
15 |
import org.gvsig.complexlegend.ComplexLegendItem; |
|
16 |
import org.gvsig.complexlegend.VectorComplexLegend; |
|
17 |
import org.gvsig.fmap.dal.exception.DataException; |
|
18 |
import org.gvsig.fmap.dal.feature.Feature; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
20 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
21 |
import org.gvsig.fmap.geom.Geometry; |
|
22 |
import org.gvsig.fmap.mapcontext.MapContextException; |
|
23 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
24 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
25 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
26 |
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend; |
|
27 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend; |
|
28 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
29 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
|
30 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
|
31 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
|
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
34 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
35 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
|
36 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
|
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.Persistent; |
|
41 |
import org.gvsig.tools.persistence.PersistentState; |
|
42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
43 |
import org.gvsig.tools.task.Cancellable; |
|
44 |
import org.gvsig.tools.util.Callable; |
|
45 |
|
|
46 |
public class DefaultVectorComplexLegend extends AbstractVectorialLegend implements VectorComplexLegend, Persistent { |
|
47 |
|
|
48 |
public static final String COMPLEX_LEGEND_PERSISTENCE_DEFINITION_NAME = "ComplexLegendPersistence"; |
|
49 |
public static final String COMPLEX_LEGEND_NAME = "ComplexLegend"; |
|
50 |
public static final String COMPLEX_LEGEND_FIELD = "Legends"; |
|
51 |
private List<ComplexLegendItem> legends; |
|
52 |
private boolean useDefault; |
|
53 |
private int shapeType; |
|
54 |
private ISymbol defaultSymbol; |
|
55 |
private int currentLegend; |
|
56 |
|
|
57 |
private LegendContentsChangedListener changeListener; |
|
58 |
|
|
59 |
private boolean allowOverlap; |
|
60 |
|
|
61 |
public DefaultVectorComplexLegend() { |
|
62 |
super(); |
|
63 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
|
64 |
this.defaultSymbol = manager.createSymbol(Geometry.TYPES.SURFACE); |
|
65 |
this.allowOverlap = true; |
|
66 |
this.currentLegend = -1; |
|
67 |
this.changeListener = new LegendContentsChangedListener() { |
|
68 |
@Override |
|
69 |
public boolean symbolChanged(SymbolLegendEvent e) { |
|
70 |
fireDefaultSymbolChangedEvent(e); |
|
71 |
return true; |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public void legendCleared(LegendClearEvent event) { |
|
76 |
fireDefaultSymbolChangedEvent(new ComplexLegendChangedEvent()); |
|
77 |
} |
|
78 |
}; |
|
79 |
} |
|
80 |
|
|
81 |
public List<ComplexLegendItem> getLegends() { |
|
82 |
if (legends == null) { |
|
83 |
legends = new ArrayList<ComplexLegendItem>(); |
|
84 |
} |
|
85 |
return Collections.unmodifiableList(legends); |
|
86 |
} |
|
87 |
|
|
88 |
public List<ComplexLegendItem> getEditedLegends() { |
|
89 |
if (legends == null) { |
|
90 |
legends = new ArrayList<ComplexLegendItem>(); |
|
91 |
} |
|
92 |
return legends; |
|
93 |
} |
|
94 |
|
|
95 |
public boolean isOverlapped(ComplexLegendItem legend) { |
|
96 |
Iterator it = getLegends().iterator(); |
|
97 |
while (it.hasNext()) { |
|
98 |
ComplexLegendItem aux = (ComplexLegendItem) it.next(); |
|
99 |
if ((aux.getMinScale() == -1 |
|
100 |
&& aux.getMaxScale() > legend.getMinScale())) { |
|
101 |
return true; |
|
102 |
} |
|
103 |
if ((aux.getMaxScale() == -1 |
|
104 |
&& aux.getMinScale() < legend.getMaxScale())) { |
|
105 |
return true; |
|
106 |
} |
|
107 |
if (!(aux.getMinScale() >= legend.getMaxScale() |
|
108 |
|| aux.getMaxScale() <= legend.getMinScale())) { |
|
109 |
return true; |
|
110 |
} |
|
111 |
} |
|
112 |
return false; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public Object clone() throws CloneNotSupportedException { |
|
117 |
DefaultVectorComplexLegend cloned = (DefaultVectorComplexLegend) super.clone(); //To change body of generated methods, choose Tools | Templates. |
|
118 |
cloned.defaultSymbol = (ISymbol) this.defaultSymbol.clone(); |
|
119 |
|
|
120 |
cloned.legends = new ArrayList<>(); |
|
121 |
if (legends != null) { |
|
122 |
for (ComplexLegendItem legend : legends) { |
|
123 |
cloned.add((ComplexLegendItem) legend.clone()); |
|
124 |
} |
|
125 |
} |
|
126 |
return cloned; |
|
127 |
} |
|
128 |
|
|
129 |
public boolean add(ComplexLegendItem legend) { |
|
130 |
if (legends == null) { |
|
131 |
getLegends(); |
|
132 |
} |
|
133 |
|
|
134 |
boolean result = legends.add(legend); |
|
135 |
Collections.sort(legends, new Comparator<ComplexLegendItem>() { |
|
136 |
public int compare(ComplexLegendItem o1, ComplexLegendItem o2) { |
|
137 |
if (o1.getMinScale() == o2.getMinScale()) { |
|
138 |
return 0; |
|
139 |
} |
|
140 |
return o1.getMinScale() < o2.getMinScale() ? -1 : 1; |
|
141 |
} |
|
142 |
}); |
|
143 |
|
|
144 |
legend.getLegend().addLegendListener(this.changeListener); |
|
145 |
fireDefaultSymbolChangedEvent(new ComplexLegendChangedEvent()); |
|
146 |
return result; |
|
147 |
} |
|
148 |
|
|
149 |
public boolean remove(ComplexLegendItem legend) { |
|
150 |
if (legends == null) { |
|
151 |
getLegends(); |
|
152 |
} |
|
153 |
|
|
154 |
boolean result = legends.remove(legend); |
|
155 |
legend.getLegend().removeLegendListener(changeListener); |
|
156 |
fireDefaultSymbolChangedEvent(new ComplexLegendChangedEvent()); |
|
157 |
return result; |
|
158 |
} |
|
159 |
|
|
160 |
public ComplexLegendItem getLegend(double scale) { |
|
161 |
Iterator<ComplexLegendItem> it = getLegends().iterator(); |
|
162 |
while (it.hasNext()) { |
|
163 |
ComplexLegendItem cleg = (ComplexLegendItem) it.next(); |
|
164 |
if (cleg.getMinScale() == -1 |
|
165 |
&& cleg.getMaxScale() >= scale) { |
|
166 |
return cleg; |
|
167 |
} |
|
168 |
if (cleg.getMinScale() <= scale |
|
169 |
&& cleg.getMaxScale() >= scale) { |
|
170 |
return cleg; |
|
171 |
} |
|
172 |
if (cleg.getMinScale() <= scale |
|
173 |
&& cleg.getMaxScale() == -1) { |
|
174 |
return cleg; |
|
175 |
} |
|
176 |
} |
|
177 |
return null; |
|
178 |
} |
|
179 |
|
|
180 |
public List<ComplexLegendItem> getLegendsInScale(double scale) { |
|
181 |
Iterator<ComplexLegendItem> it = getLegends().iterator(); |
|
182 |
ArrayList<ComplexLegendItem> legendsInScale = new ArrayList<ComplexLegendItem>(); |
|
183 |
while (it.hasNext()) { |
|
184 |
ComplexLegendItem cleg = (ComplexLegendItem) it.next(); |
|
185 |
if (cleg.getMinScale() == -1 |
|
186 |
&& cleg.getMaxScale() >= scale) { |
|
187 |
legendsInScale.add(cleg); |
|
188 |
} |
|
189 |
if (cleg.getMinScale() <= scale |
|
190 |
&& cleg.getMaxScale() >= scale) { |
|
191 |
legendsInScale.add(cleg); |
|
192 |
} |
|
193 |
if (cleg.getMinScale() <= scale |
|
194 |
&& cleg.getMaxScale() == -1) { |
|
195 |
legendsInScale.add(cleg); |
|
196 |
} |
|
197 |
} |
|
198 |
return legendsInScale; |
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
203 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
|
204 |
FeatureStore featureStore, FeatureQuery fquery, |
|
205 |
PrintAttributes properties) throws LegendException { |
|
206 |
List<ComplexLegendItem> legendsToDraw; |
|
207 |
if (this.getAllowOverlap()) { |
|
208 |
legendsToDraw = this.getLegendsInScale(scale); |
|
209 |
} else { |
|
210 |
legendsToDraw = new ArrayList<>(); |
|
211 |
ComplexLegendItem legendInScale = getLegend(scale); |
|
212 |
legendsToDraw.add(legendInScale); |
|
213 |
} |
|
214 |
|
|
215 |
int n = 0; |
|
216 |
for (ComplexLegendItem legend : legendsToDraw) { |
|
217 |
if (legend != null) { |
|
218 |
if (legend.getLegend() != null) { |
|
219 |
setCurrentLegend(n); |
|
220 |
if (legend.getLegend() instanceof AbstractVectorialLegend) { |
|
221 |
((AbstractVectorialLegend) legend.getLegend()).print(g, viewPort, cancel, scale, queryParameters, coordTrans, |
|
222 |
featureStore, fquery, properties); |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
@Override |
|
230 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
231 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
|
232 |
FeatureStore featureStore, PrintAttributes properties) |
|
233 |
throws LegendException { |
|
234 |
print(g, viewPort, cancel, scale, queryParameters, coordTrans, |
|
235 |
featureStore, null, properties); |
|
236 |
} |
|
237 |
|
|
238 |
@Override |
|
239 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
240 |
Cancellable cancel, double scale, Map queryParameters, |
|
241 |
ICoordTrans coordTrans, FeatureStore featureStore) |
|
242 |
throws LegendException { |
|
243 |
List<ComplexLegendItem> legendsToDraw; |
|
244 |
if (this.getAllowOverlap()) { |
|
245 |
legendsToDraw = this.getLegendsInScale(scale); |
|
246 |
} else { |
|
247 |
legendsToDraw = new ArrayList<>(); |
|
248 |
ComplexLegendItem legendInScale = getLegend(scale); |
|
249 |
legendsToDraw.add(legendInScale); |
|
250 |
} |
|
251 |
|
|
252 |
int n = 0; |
|
253 |
for (ComplexLegendItem legend : legendsToDraw) { |
|
254 |
if (legend != null) { |
|
255 |
if (legend.getLegend() != null) { |
|
256 |
setCurrentLegend(n); |
|
257 |
if (legend.getLegend() instanceof AbstractVectorialLegend) { |
|
258 |
((AbstractVectorialLegend) legend.getLegend()).draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, |
|
259 |
featureStore); |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
@Override |
|
267 |
protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
268 |
Cancellable cancel, double scale, Map queryParameters, |
|
269 |
ICoordTrans coordTrans, FeatureStore featureStore, |
|
270 |
FeatureQuery featureQuery, double dpi) throws LegendException { |
|
271 |
|
|
272 |
List<ComplexLegendItem> legendsToDraw; |
|
273 |
if (this.getAllowOverlap()) { |
|
274 |
legendsToDraw = this.getLegendsInScale(scale); |
|
275 |
} else { |
|
276 |
legendsToDraw = new ArrayList<>(); |
|
277 |
ComplexLegendItem legendInScale = getLegend(scale); |
|
278 |
legendsToDraw.add(legendInScale); |
|
279 |
} |
|
280 |
int n = 0; |
|
281 |
for (ComplexLegendItem legend : legendsToDraw) { |
|
282 |
if (legend != null) { |
|
283 |
if (legend.getLegend() != null) { |
|
284 |
setCurrentLegend(n); |
|
285 |
if (legend.getLegend() instanceof AbstractVectorialLegend) { |
|
286 |
|
|
287 |
((AbstractVectorialLegend) legend.getLegend()).draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, |
|
288 |
featureStore, featureQuery); |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
n++; |
|
293 |
} |
|
294 |
|
|
295 |
} |
|
296 |
|
|
297 |
private IVectorLegend getCurrentLegend() { |
|
298 |
if (this.currentLegend >= 0 && getLegends() != null && !getLegends().isEmpty()) { |
|
299 |
return (IVectorLegend) getLegends().get(this.currentLegend).getLegend(); |
|
300 |
} |
|
301 |
return null; |
|
302 |
} |
|
303 |
|
|
304 |
private void setCurrentLegend(int legend) { |
|
305 |
this.currentLegend = legend; |
|
306 |
} |
|
307 |
|
|
308 |
@Override |
|
309 |
public boolean getAllowOverlap() { |
|
310 |
return this.allowOverlap; |
|
311 |
} |
|
312 |
|
|
313 |
@Override |
|
314 |
public void setAllowOverlap(boolean allowOverlap) { |
|
315 |
this.allowOverlap = allowOverlap; |
|
316 |
} |
|
317 |
|
|
318 |
public static class RegisterPersistence implements Callable { |
|
319 |
|
|
320 |
public Object call() throws Exception { |
|
321 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
322 |
if (manager.getDefinition( |
|
323 |
COMPLEX_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) { |
|
324 |
DynStruct definition = manager |
|
325 |
.addDefinition(DefaultVectorComplexLegend.class, |
|
326 |
COMPLEX_LEGEND_PERSISTENCE_DEFINITION_NAME, |
|
327 |
COMPLEX_LEGEND_PERSISTENCE_DEFINITION_NAME |
|
328 |
+ " Persistence definition", null, null); |
|
329 |
|
|
330 |
definition.extend(manager.getDefinition( |
|
331 |
AbstractVectorialLegend.VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
|
332 |
|
|
333 |
definition.addDynFieldList(COMPLEX_LEGEND_FIELD).setClassOfItems(DefaultComplexLegendItem.class); |
|
334 |
definition.addDynFieldBoolean("allowOverlay"); |
|
335 |
} |
|
336 |
return Boolean.TRUE; |
|
337 |
} |
|
338 |
|
|
339 |
} |
|
340 |
|
|
341 |
public void loadFromState(PersistentState state) |
|
342 |
throws PersistenceException { |
|
343 |
super.loadFromState(state); |
|
344 |
try { |
|
345 |
this.allowOverlap = state.getBoolean("allowOverlay"); |
|
346 |
} catch (Exception e) { |
|
347 |
this.allowOverlap = false; |
|
348 |
} |
|
349 |
|
|
350 |
setLegends(state.getList(COMPLEX_LEGEND_FIELD)); |
|
351 |
} |
|
352 |
|
|
353 |
private void setLegends(List list) { |
|
354 |
this.legends = list; |
|
355 |
} |
|
356 |
|
|
357 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
358 |
super.saveToState(state); |
|
359 |
state.set("allowOverlay", this.allowOverlap); |
|
360 |
state.set(COMPLEX_LEGEND_FIELD, getEditedLegends()); |
|
361 |
} |
|
362 |
|
|
363 |
public static class RegisterLegend implements Callable { |
|
364 |
|
|
365 |
public Object call() throws Exception { |
|
366 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
|
367 |
|
|
368 |
manager.registerLegend( |
|
369 |
COMPLEX_LEGEND_NAME, |
|
370 |
DefaultVectorComplexLegend.class); |
|
371 |
|
|
372 |
return Boolean.TRUE; |
|
373 |
} |
|
374 |
|
|
375 |
} |
|
376 |
|
|
377 |
public ISymbol getSymbolByFeature(Feature feat) throws MapContextException { |
|
378 |
|
|
379 |
if (this.getCurrentLegend() != null |
|
380 |
&& this.getCurrentLegend() instanceof IVectorLegend) { |
|
381 |
return ((IVectorLegend) this.getCurrentLegend()).getSymbolByFeature(feat); |
|
382 |
} |
|
383 |
return null; |
|
384 |
} |
|
385 |
|
|
386 |
public int getShapeType() { |
|
387 |
return this.shapeType; |
|
388 |
} |
|
389 |
|
|
390 |
public void setShapeType(int shapeType) { |
|
391 |
this.shapeType = shapeType; |
|
392 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
|
393 |
this.defaultSymbol = manager.createSymbol(shapeType); |
|
394 |
} |
|
395 |
|
|
396 |
public void setDefaultSymbol(ISymbol s) { |
|
397 |
this.defaultSymbol = s; |
|
398 |
} |
|
399 |
|
|
400 |
public boolean isUseDefaultSymbol() { |
|
401 |
return useDefault; |
|
402 |
} |
|
403 |
|
|
404 |
public void useDefaultSymbol(boolean b) { |
|
405 |
this.useDefault = b; |
|
406 |
} |
|
407 |
|
|
408 |
public boolean isSuitableForShapeType(int shapeType) { |
|
409 |
return true; |
|
410 |
} |
|
411 |
|
|
412 |
public ISymbol getDefaultSymbol() { |
|
413 |
return defaultSymbol; |
|
414 |
} |
|
415 |
|
|
416 |
@Override |
|
417 |
protected String[] getRequiredFeatureAttributeNames( |
|
418 |
FeatureStore featureStore) throws DataException { |
|
419 |
// TODO Auto-generated method stub |
|
420 |
return null; |
|
421 |
} |
|
422 |
|
|
423 |
public String[] getDescriptions() { |
|
424 |
List<String> descriptions = new ArrayList<String>(); |
|
425 |
for (ComplexLegendItem legend : this.legends) { |
|
426 |
if (legend != null) { |
|
427 |
if (legend.getLegend() != null |
|
428 |
&& legend.getLegend() instanceof AbstractVectorialLegend) { |
|
429 |
if (legend.getLegend() instanceof IClassifiedLegend) { |
|
430 |
String[] classifiedDescriptions = ((IClassifiedLegend) legend.getLegend()).getDescriptions(); |
|
431 |
for (String description : classifiedDescriptions) { |
|
432 |
descriptions.add(description); |
|
433 |
} |
|
434 |
} else { |
|
435 |
descriptions.add(null); |
|
436 |
} |
|
437 |
} |
|
438 |
} |
|
439 |
} |
|
440 |
if (descriptions.isEmpty()) { |
|
441 |
descriptions.add(null); |
|
442 |
} |
|
443 |
return descriptions.toArray(new String[0]); |
|
444 |
|
|
445 |
} |
|
446 |
|
|
447 |
public ISymbol[] getSymbols() { |
|
448 |
|
|
449 |
List<ISymbol> symbols = new ArrayList<ISymbol>(); |
|
450 |
for (ComplexLegendItem legend : this.legends) { |
|
451 |
if (legend != null) { |
|
452 |
if (legend.getLegend() != null |
|
453 |
&& legend.getLegend() instanceof AbstractVectorialLegend) { |
|
454 |
if (legend.getLegend() instanceof IHasImageLegend) { |
|
455 |
symbols.add(new SimpleImageMarkerSymbol((IHasImageLegend) legend.getLegend())); |
|
456 |
} else if (legend.getLegend() instanceof IClassifiedLegend) { |
|
457 |
ISymbol[] classifiedSymbols = ((IClassifiedLegend) legend.getLegend()).getSymbols(); |
|
458 |
for (ISymbol classifiedSymbol : classifiedSymbols) { |
|
459 |
symbols.add(classifiedSymbol); |
|
460 |
} |
|
461 |
} else { |
|
462 |
symbols.add(((IVectorLegend) legend.getLegend()).getDefaultSymbol()); |
|
463 |
} |
|
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
if (symbols.isEmpty()) { |
|
468 |
if (getDefaultSymbol() != null) { |
|
469 |
symbols.add(getDefaultSymbol()); |
|
470 |
} else { |
|
471 |
SymbolManager manager = MapContextLocator.getSymbolManager(); |
|
472 |
symbols.add(manager.createSymbol(shapeType)); |
|
473 |
|
|
474 |
} |
|
475 |
} |
|
476 |
return symbols.toArray(new ISymbol[0]); |
|
477 |
} |
|
478 |
|
|
479 |
public Object[] getValues() { |
|
480 |
List<Object> values = new ArrayList<Object>(); |
|
481 |
for (ComplexLegendItem legend : this.legends) { |
|
482 |
if (legend != null) { |
|
483 |
if (legend.getLegend() != null |
|
484 |
&& legend.getLegend() instanceof AbstractVectorialLegend) { |
|
485 |
if (legend.getLegend() instanceof IClassifiedLegend) { |
|
486 |
Object[] classifiedValues = ((IClassifiedLegend) legend).getValues(); |
|
487 |
for (Object classifiedValue : classifiedValues) { |
|
488 |
values.add(classifiedValue); |
|
489 |
} |
|
490 |
} else { |
|
491 |
values.add(null); |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
if (values.isEmpty()) { |
|
497 |
values.add(null); |
|
498 |
} |
|
499 |
return values.toArray(new Object[0]); |
|
500 |
|
|
501 |
} |
|
502 |
|
|
503 |
private static class ComplexLegendChangedEvent extends SymbolLegendEvent { |
|
504 |
|
|
505 |
public ComplexLegendChangedEvent() { |
|
506 |
super(null, null); |
|
507 |
} |
|
508 |
|
|
509 |
@Override |
|
510 |
public int getEventType() { |
|
511 |
return SymbolLegendEvent.LEGEND_VALUE_CHANGED; |
|
512 |
} |
|
513 |
} |
|
514 |
|
|
515 |
private static class SimpleImageMarkerSymbol extends SimpleMarkerSymbol { |
|
516 |
|
|
517 |
private final IHasImageLegend legend; |
|
518 |
|
|
519 |
public SimpleImageMarkerSymbol(IHasImageLegend legend) { |
|
520 |
this.legend = legend; |
|
521 |
} |
|
522 |
|
|
523 |
@Override |
|
524 |
public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature feature, Cancellable cancel) { |
|
525 |
g.drawImage(this.legend.getImageLegend(), 0, 0, null); |
|
526 |
} |
|
527 |
|
|
528 |
@Override |
|
529 |
public double getSize() { |
|
530 |
return this.legend.getImageLegend().getWidth(null); |
|
531 |
} |
|
532 |
|
|
533 |
} |
|
534 |
|
|
535 |
} |
|
0 | 536 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/java/org/gvsig/complexlegend/impl/DefaultComplexLegendLibrary.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.complexlegend.impl; |
|
23 |
|
|
24 |
|
|
25 |
import org.gvsig.complexlabel.impl.ComplexLabelClassFactory; |
|
26 |
import org.gvsig.complexlabel.impl.DefaultComplexLabelClass; |
|
27 |
import org.gvsig.complexlegend.ComplexLegendLibrary; |
|
28 |
import org.gvsig.complexlegend.VectorComplexLegend; |
|
29 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
30 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
31 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
32 |
import org.gvsig.symbology.SymbologyLocator; |
|
33 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl.PersistenceBasedLegendWriter; |
|
34 |
import org.gvsig.tools.library.AbstractLibrary; |
|
35 |
import org.gvsig.tools.library.LibraryException; |
|
36 |
import org.gvsig.tools.util.Caller; |
|
37 |
import org.gvsig.tools.util.impl.DefaultCaller; |
|
38 |
|
|
39 |
/** |
|
40 |
* Library for default implementation initialization and configuration. |
|
41 |
* This default implementation will be based in JFreeChart library. |
|
42 |
* |
|
43 |
* @author gvSIG team |
|
44 |
* @version $Id$ |
|
45 |
*/ |
|
46 |
public class DefaultComplexLegendLibrary extends AbstractLibrary { |
|
47 |
|
|
48 |
@Override |
|
49 |
public void doRegistration() { |
|
50 |
registerAsImplementationOf(ComplexLegendLibrary.class); |
|
51 |
} |
|
52 |
|
|
53 |
|
|
54 |
@Override |
|
55 |
protected void doInitialize() throws LibraryException { |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
protected void doPostInitialize() throws LibraryException { |
|
60 |
Caller caller = new DefaultCaller(); |
|
61 |
caller.add(new DefaultVectorComplexLegend.RegisterLegend()); |
|
62 |
caller.add(new DefaultVectorComplexLegend.RegisterPersistence()); |
|
63 |
caller.add(new DefaultComplexLegendItem.RegisterPersistence()); |
|
64 |
caller.add(new DefaultComplexLabelClass.RegisterPersistence()); |
|
65 |
|
|
66 |
if( !caller.call() ) { |
|
67 |
throw new LibraryException(DefaultComplexLegendLibrary.class, caller.getExceptions()); |
|
68 |
} |
|
69 |
|
|
70 |
MapContextManager mcoman = MapContextLocator.getMapContextManager(); |
|
71 |
mcoman.registerLegendWriter( |
|
72 |
VectorComplexLegend.class, |
|
73 |
SymbolManager.LEGEND_FILE_EXTENSION.substring(1), |
|
74 |
PersistenceBasedLegendWriter.class); |
|
75 |
|
|
76 |
SymbologyLocator.getSymbologyManager().registerLabelClass(new ComplexLabelClassFactory()); |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
} |
|
0 | 81 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/java/org/gvsig/complexlabel/impl/DefaultComplexLabelClass.java | ||
---|---|---|
1 |
package org.gvsig.complexlabel.impl; |
|
2 |
|
|
3 |
|
|
4 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.LabelClass; |
|
5 |
import org.gvsig.tools.ToolsLocator; |
|
6 |
import org.gvsig.tools.dynobject.DynStruct; |
|
7 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
8 |
import org.gvsig.tools.persistence.Persistent; |
|
9 |
import org.gvsig.tools.persistence.PersistentState; |
|
10 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
11 |
import org.gvsig.tools.util.Callable; |
|
12 |
|
|
13 |
public class DefaultComplexLabelClass extends LabelClass implements Persistent{ |
|
14 |
|
|
15 |
public static final String COMPLEXLABELCLASS_PERSISTENCE_DEFINITION_NAME = "Complex.label.class"; |
|
16 |
|
|
17 |
private double minScale; |
|
18 |
private double maxScale; |
|
19 |
|
|
20 |
public double getMinScale() { |
|
21 |
return minScale; |
|
22 |
} |
|
23 |
|
|
24 |
public void setMinScale(double minScale) { |
|
25 |
this.minScale = minScale; |
|
26 |
} |
|
27 |
|
|
28 |
public double getMaxScale() { |
|
29 |
return maxScale; |
|
30 |
} |
|
31 |
|
|
32 |
public void setMaxScale(double maxScale) { |
|
33 |
this.maxScale = maxScale; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public boolean isVisible() { |
|
38 |
return super.isVisible(); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public boolean isVisible(double scale) { |
|
43 |
if(getMaxScale() > scale && getMinScale() < scale){ |
|
44 |
return true; |
|
45 |
} |
|
46 |
return false; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void loadFromState(PersistentState state) |
|
51 |
throws PersistenceException { |
|
52 |
super.loadFromState(state); |
|
53 |
setMinScale(state.getDouble("MinScale")); |
|
54 |
setMaxScale(state.getDouble("MaxScale")); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
59 |
super.saveToState(state); |
|
60 |
state.set("MinScale", getMinScale()); |
|
61 |
state.set("MaxScale", getMaxScale()); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public Object clone() throws CloneNotSupportedException { |
|
66 |
DefaultComplexLabelClass cloned = (DefaultComplexLabelClass) super.clone(); |
|
67 |
cloned.setMaxScale(this.getMaxScale()); |
|
68 |
cloned.setMinScale(this.getMinScale()); |
|
69 |
return cloned; |
|
70 |
} |
|
71 |
|
|
72 |
public static class RegisterPersistence implements Callable { |
|
73 |
|
|
74 |
public Object call() throws Exception { |
|
75 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
76 |
if( manager.getDefinition(COMPLEXLABELCLASS_PERSISTENCE_DEFINITION_NAME)==null ) { |
|
77 |
DynStruct definition = manager.addDefinition( |
|
78 |
DefaultComplexLabelClass.class, |
|
79 |
COMPLEXLABELCLASS_PERSISTENCE_DEFINITION_NAME, |
|
80 |
COMPLEXLABELCLASS_PERSISTENCE_DEFINITION_NAME+" Persistence definition", |
|
81 |
null, |
|
82 |
null |
|
83 |
); |
|
84 |
|
|
85 |
definition.extend(manager.getDefinition( |
|
86 |
"LabelClass")); |
|
87 |
|
|
88 |
definition.addDynFieldDouble("MaxScale").setMandatory(true); |
|
89 |
definition.addDynFieldDouble("MinScale").setMandatory(true); |
|
90 |
} |
|
91 |
return Boolean.TRUE; |
|
92 |
} |
|
93 |
|
|
94 |
} |
|
95 |
} |
|
0 | 96 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/main/java/org/gvsig/complexlabel/impl/ComplexLabelClassFactory.java | ||
---|---|---|
1 |
package org.gvsig.complexlabel.impl; |
|
2 |
|
|
3 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
|
4 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClassFactory; |
|
5 |
import org.gvsig.tools.ToolsLocator; |
|
6 |
import org.gvsig.tools.i18n.I18nManager; |
|
7 |
|
|
8 |
public class ComplexLabelClassFactory implements ILabelClassFactory { |
|
9 |
|
|
10 |
public static final String FACTORY_ID = "MultipleLabelByScale"; |
|
11 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
12 |
|
|
13 |
|
|
14 |
public ILabelClass create() { |
|
15 |
return new DefaultComplexLabelClass(); |
|
16 |
} |
|
17 |
|
|
18 |
public String getID() { |
|
19 |
return FACTORY_ID; |
|
20 |
} |
|
21 |
|
|
22 |
public String getName() { |
|
23 |
return i18nManager.getTranslation("multiple_label_by_scale"); |
|
24 |
} |
|
25 |
|
|
26 |
public String toString() { |
|
27 |
return this.getName(); |
|
28 |
} |
|
29 |
} |
|
0 | 30 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<!-- |
|
5 |
Log4J configuration file for unit tests execution. |
|
6 |
--> |
|
7 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
8 |
|
|
9 |
<!-- Appender configuration to show logging messages through the console --> |
|
10 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
11 |
<layout class="org.apache.log4j.PatternLayout"> |
|
12 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
13 |
</layout> |
|
14 |
</appender> |
|
15 |
|
|
16 |
<!-- |
|
17 |
Activate logging messages of DEBUG level of higher only for the |
|
18 |
org.gvsig.tools packages. |
|
19 |
You can put full classes names or packages instead, to configure |
|
20 |
logging for all the classes and subpackages of the package. |
|
21 |
--> |
|
22 |
<category name="org.gvsig.tools"> |
|
23 |
<priority value="DEBUG" /> |
|
24 |
</category> |
|
25 |
<category name="org.gvsig.chart"> |
|
26 |
<priority value="DEBUG" /> |
|
27 |
</category> |
|
28 |
|
|
29 |
<!-- |
|
30 |
By default, show only logging messages of INFO level or higher, |
|
31 |
through the previously configured CONSOLE appender. |
|
32 |
--> |
|
33 |
<root> |
|
34 |
<priority value="DEBUG" /> |
|
35 |
<appender-ref ref="CONSOLE" /> |
|
36 |
</root> |
|
37 |
</log4j:configuration> |
|
0 | 38 |
org.gvsig.complexlegend/tags/org.gvsig.complexlegend-1.0.255/org.gvsig.complexlegend/org.gvsig.complexlegend.lib/org.gvsig.complexlegend.lib.impl/src/test/resources/README.txt | ||
---|---|---|
1 |
Put into this folder the resources needed by your test classes. |
|
2 |
|
|
3 |
This folder is added to the Tests classpath, so you can load any resources |
|
4 |
through the ClassLoader. |
|
5 |
|
|
6 |
By default, in this folder you can find an example of log4j configuration, |
|
7 |
prepared to log messages through the console, so logging works when you |
|
8 |
run your tests classes. |
|
0 | 9 |
Also available in: Unified diff