SourceForge: gwt-openlayers/gwt-openlayers: changeset 193:65fe5fab807b
generalized vectorfeature attributes to attributes object
authorEdwin Commandeur <commandeur.edwin@gmail.com>
Thu Oct 22 08:10:14 2009 +0200 (4 weeks ago)
changeset 19365fe5fab807b
parent 183c898ff90e045
child 19409138277ac4f
generalized vectorfeature attributes to attributes object
showcase/readme.txt
src/main/java/org/gwtopenmaps/openlayers/client/Style.java
src/main/java/org/gwtopenmaps/openlayers/client/feature/VectorFeature.java
src/main/java/org/gwtopenmaps/openlayers/client/feature/VectorFeatureAttributes.java
src/main/java/org/gwtopenmaps/openlayers/client/util/Attributes.java
src/main/test/org/gwtopenmaps/test/openlayers/client/GwtOpenLayersTestSuite.java
src/main/test/org/gwtopenmaps/test/openlayers/client/util/AttributesTest.java
     1.1 --- a/showcase/readme.txt	Wed Oct 07 10:23:51 2009 +0200
     1.2 +++ b/showcase/readme.txt	Thu Oct 22 08:10:14 2009 +0200
     1.3 @@ -1,1 +1,1 @@
     1.4 -The showcase is:
     1.5   - set up according to the 'war' project structure (GWT 1.6 and up)
     1.6   - set up as an eclipse project
     1.7 
     1.8 To run the showcase you need to:
     1.9 
    1.10 1) Get the Java EE download of Eclipse 3.4 or 3.5. The latest version of Eclipse can be obtained from:
    1.11 http://www.eclipse.org/downloads/
    1.12 For older versions check:
    1.13 http://wiki.eclipse.org/Older_Versions_Of_Eclipse
    1.14 
    1.15 2) Install the Google Eclipse plugin in Eclipse:
    1.16 http://code.google.com/intl/nl/eclipse/docs/getting_started.html
    1.17 
    1.18 3) Import the showcase in Eclipse as an existing project
    1.19 >File >Import >Existing Projects into Workspace
    1.20 
    1.21 4) Download 'openlayers_gwt-0.4.jar' and copy it to the lib directory
    1.22 
    1.23 5) Right click the project and select >Run As >Web application
    1.24 
    1.25 By default OpenLayers is included from the Version API URL (see http://trac.openlayers.org/wiki/HowToDownload).
    1.26 If you want to run against a local version of OpenLayers, for example a debug version you compiled yourself, then you need to adjust 'GwtOpenLayersShowcase.html'. Change the following line in that html file:
    1.27 
    1.28 <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
    1.29 
    1.30 into:
    1.31 
    1.32 <script src="YOUR_PATH_TO_OPENLAYERS"></script>
    1.33 
    1.34 For example:
    1.35 <script src="js/OpenLayers-2.8/OpenLayers.js"></script>
    1.36 
    1.37 Finally, you have to be online to run the showcase (or invest some effort into running your own WMS server, for example with GeoServer, and point your examples at that WMS server).
    1.38 
    1.39 Enjoy,
    1.40 The GWT-Openlayers team
    1.41 
    1.42 
    1.43 
    1.44 
    1.45 
    1.46 \ No newline at end of file
    1.47 +The showcase is:
    1.48   - set up according to the 'war' project structure (GWT 1.6 and up)
    1.49   - set up as an eclipse project
    1.50 
    1.51 To run the showcase you need to:
    1.52 
    1.53 1) Get the Java EE download of Eclipse 3.4 or 3.5. The latest version of Eclipse can be obtained from:
    1.54 http://www.eclipse.org/downloads/
    1.55 For older versions check:
    1.56 http://wiki.eclipse.org/Older_Versions_Of_Eclipse
    1.57 
    1.58 2) Install the Google Eclipse plugin in Eclipse:
    1.59 http://code.google.com/intl/nl/eclipse/docs/getting_started.html
    1.60 
    1.61 3) Import the showcase in Eclipse as an existing project
    1.62 >File >Import >Existing Projects into Workspace
    1.63 
    1.64 4) Download 'openlayers_gwt-0.4.jar' and copy it to the lib directory
    1.65 OR
    1.66 If you are using the showcase from trunk, copy a build of the source code to the lib directory.
    1.67 
    1.68 5) Right click the project and select >Run As >Web application
    1.69 
    1.70 By default OpenLayers is included from the Version API URL (see http://trac.openlayers.org/wiki/HowToDownload).
    1.71 If you want to run against a local version of OpenLayers, for example a debug version you compiled yourself, then you need to adjust 'GwtOpenLayersShowcase.html'. Change the following line in that html file:
    1.72 
    1.73 <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
    1.74 
    1.75 into:
    1.76 
    1.77 <script src="YOUR_PATH_TO_OPENLAYERS"></script>
    1.78 
    1.79 For example:
    1.80 <script src="js/OpenLayers-2.8/OpenLayers.js"></script>
    1.81 
    1.82 Finally, you have to be online to run the showcase (or invest some effort into running your own WMS server, for example with GeoServer, and point your examples at that WMS server).
    1.83 
    1.84 Enjoy,
    1.85 The GWT-Openlayers team
    1.86 
    1.87 
    1.88 
    1.89 
    1.90 
    1.91 \ No newline at end of file
     2.1 --- a/src/main/java/org/gwtopenmaps/openlayers/client/Style.java	Wed Oct 07 10:23:51 2009 +0200
     2.2 +++ b/src/main/java/org/gwtopenmaps/openlayers/client/Style.java	Thu Oct 22 08:10:14 2009 +0200
     2.3 @@ -1,6 +1,5 @@
     2.4  package org.gwtopenmaps.openlayers.client;
     2.5  
     2.6 -import org.gwtopenmaps.openlayers.client.feature.VectorFeatureAttributes;
     2.7  import org.gwtopenmaps.openlayers.client.util.JSObject;
     2.8  
     2.9  /**
    2.10 @@ -249,11 +248,11 @@
    2.11  	 * <p>
    2.12  	 * Note: you can set a custom label for each feature added to a layer by
    2.13  	 * using tags in the label, and setting attributes using
    2.14 -	 * {@link VectorFeatureAttributes}. For example, set the style.label to
    2.15 +	 * {@link org.gwtopenmaps.openlayers.client.util.Attributes}. For example, set the style.label to
    2.16  	 * "${customLabel}", then, for each feature added to the layer, add an
    2.17  	 * "customLabel" attribute with
    2.18  	 * <p>
    2.19 -	 * <code>VectorFeatureAttributes.setAttribute("customLabel","myLabel for this specific feature")</code>
    2.20 +	 * <code>attributes.setAttribute("customLabel","myLabel for this specific feature")</code>
    2.21  	 * <p>
    2.22  	 * Note: this can also be used in any style field of type String, such as
    2.23  	 * fillColor, fontColor, etc
     3.1 --- a/src/main/java/org/gwtopenmaps/openlayers/client/feature/VectorFeature.java	Wed Oct 07 10:23:51 2009 +0200
     3.2 +++ b/src/main/java/org/gwtopenmaps/openlayers/client/feature/VectorFeature.java	Thu Oct 22 08:10:14 2009 +0200
     3.3 @@ -4,6 +4,7 @@
     3.4  import org.gwtopenmaps.openlayers.client.StyleMap;
     3.5  import org.gwtopenmaps.openlayers.client.geometry.Geometry;
     3.6  import org.gwtopenmaps.openlayers.client.layer.VectorOptions;
     3.7 +import org.gwtopenmaps.openlayers.client.util.Attributes;
     3.8  import org.gwtopenmaps.openlayers.client.util.JSObject;
     3.9  
    3.10  /**
    3.11 @@ -59,12 +60,12 @@
    3.12  	 * @param vectorFeatureAttributes
    3.13  	 *            The attributes to set
    3.14  	 */
    3.15 -	public void setAttributes(VectorFeatureAttributes attributes) {
    3.16 +	public void setAttributes(Attributes attributes) {
    3.17  		getJSObject().setProperty("attributes", attributes.getJSObject());
    3.18  	}
    3.19  
    3.20 -	public VectorFeatureAttributes getAttributes(VectorFeature attributes){
    3.21 -		return VectorFeatureAttributes.narrowToVectorFeatureAttributes(getJSObject().getProperty("attributes"));
    3.22 +	public Attributes getAttributes(VectorFeature attributes){
    3.23 +		return Attributes.narrowToAttributes(getJSObject().getProperty("attributes"));
    3.24  	}
    3.25  
    3.26  }
     4.1 --- a/src/main/java/org/gwtopenmaps/openlayers/client/feature/VectorFeatureAttributes.java	Wed Oct 07 10:23:51 2009 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,85 +0,0 @@
     4.4 -package org.gwtopenmaps.openlayers.client.feature;
     4.5 -
     4.6 -import org.gwtopenmaps.openlayers.client.util.JSObject;
     4.7 -import org.gwtopenmaps.openlayers.client.util.JSObjectWrapper;
     4.8 -
     4.9 -/**
    4.10 - * Class to holds arbitrary properties that describe the feature.
    4.11 - *
    4.12 - * @author Rafael Ceravolo - LOGANN
    4.13 - */
    4.14 -public class VectorFeatureAttributes extends JSObjectWrapper {
    4.15 -
    4.16 -	public VectorFeatureAttributes() {
    4.17 -	this(JSObject.createJSObject());
    4.18 -	}
    4.19 -
    4.20 -	protected VectorFeatureAttributes(JSObject jsObject) {
    4.21 -		super(jsObject);
    4.22 -	}
    4.23 -
    4.24 -	public static VectorFeatureAttributes narrowToVectorFeatureAttributes(JSObject attributes){
    4.25 -		return (attributes == null) ? null : new VectorFeatureAttributes(attributes);
    4.26 -	}
    4.27 -
    4.28 -	/**
    4.29 -	 * Sets an value to the arbitrary attribute.
    4.30 -	 *
    4.31 -	 * @param name
    4.32 -	 *            Name of the attribute
    4.33 -	 * @param value
    4.34 -	 *            Value of the attribute
    4.35 -	 */
    4.36 -	public void setAttribute(String name, String value) {
    4.37 -	this.getJSObject().setProperty(name, value);
    4.38 -	}
    4.39 -
    4.40 -	/**
    4.41 -	 * Sets an value to the arbitrary attribute.
    4.42 -	 *
    4.43 -	 * @param name
    4.44 -	 *            Name of the attribute
    4.45 -	 * @param value
    4.46 -	 *            Value of the attribute
    4.47 -	 */
    4.48 -	public final void setAttribute(String name, int value) {
    4.49 -	this.getJSObject().setProperty(name, value);
    4.50 -	}
    4.51 -
    4.52 -	/**
    4.53 -	 * Sets an value to the arbitrary attribute.
    4.54 -	 *
    4.55 -	 * @param name
    4.56 -	 *            Name of the attribute
    4.57 -	 * @param value
    4.58 -	 *            Value of the attribute
    4.59 -	 */
    4.60 -	public final void setAttribute(String name, boolean value) {
    4.61 -	this.getJSObject().setProperty(name, value);
    4.62 -	}
    4.63 -
    4.64 -	/**
    4.65 -	 * Sets an value to the arbitrary attribute.
    4.66 -	 *
    4.67 -	 * @param name
    4.68 -	 *            Name of the attribute
    4.69 -	 * @param value
    4.70 -	 *            Value of the attribute
    4.71 -	 */
    4.72 -	public final void setAttribute(String name, float value) {
    4.73 -	this.getJSObject().setProperty(name, value);
    4.74 -	}
    4.75 -
    4.76 -	/**
    4.77 -	 * Sets an value to the arbitrary attribute.
    4.78 -	 *
    4.79 -	 * @param name
    4.80 -	 *            Name of the attribute
    4.81 -	 * @param value
    4.82 -	 *            Value of the attribute
    4.83 -	 */
    4.84 -	public final void setAttribute(String name, double value) {
    4.85 -	this.getJSObject().setProperty(name, value);
    4.86 -	}
    4.87 -
    4.88 -}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/main/java/org/gwtopenmaps/openlayers/client/util/Attributes.java	Thu Oct 22 08:10:14 2009 +0200
     5.3 @@ -0,0 +1,146 @@
     5.4 +package org.gwtopenmaps.openlayers.client.util;
     5.5 +
     5.6 +import org.gwtopenmaps.openlayers.client.util.JSObject;
     5.7 +import org.gwtopenmaps.openlayers.client.util.JSObjectWrapper;
     5.8 +
     5.9 +/**
    5.10 + * Class to hold arbitrary attributes. More constrained than JSObject.
    5.11 + *
    5.12 + * @author Rafael Ceravolo - LOGANN
    5.13 + */
    5.14 +public class Attributes extends JSObjectWrapper {
    5.15 +
    5.16 +	public Attributes() {
    5.17 +		this(JSObject.createJSObject());
    5.18 +	}
    5.19 +
    5.20 +	protected Attributes(JSObject jsObject) {
    5.21 +		super(jsObject);
    5.22 +	}
    5.23 +
    5.24 +	public static Attributes narrowToAttributes(JSObject attributes){
    5.25 +		return (attributes == null) ? null : new Attributes(attributes);
    5.26 +	}
    5.27 +
    5.28 +	/**
    5.29 +	 * Sets a String value to the arbitrary attribute.
    5.30 +	 *
    5.31 +	 * @param name - Name of the attribute
    5.32 +	 * @param value - String value of the attribute
    5.33 +	 */
    5.34 +	public void setAttribute(String name, String value) {
    5.35 +		this.getJSObject().setProperty(name, value);
    5.36 +	}
    5.37 +
    5.38 +	/**
    5.39 +	 * Sets an integer value to the arbitrary attribute.
    5.40 +	 *
    5.41 +	 * @param name - Name of the attribute
    5.42 +	 * @param value - Integer value of the attribute
    5.43 +	 */
    5.44 +	public void setAttribute(String name, int value) {
    5.45 +		this.getJSObject().setProperty(name, value);
    5.46 +	}
    5.47 +
    5.48 +	/**
    5.49 +	 * Sets a boolean value to the arbitrary attribute.
    5.50 +	 *
    5.51 +	 * @param name
    5.52 +	 *            Name of the attribute
    5.53 +	 * @param value
    5.54 +	 *            Value of the attribute
    5.55 +	 */
    5.56 +	public void setAttribute(String name, boolean value) {
    5.57 +		this.getJSObject().setProperty(name, value);
    5.58 +	}
    5.59 +
    5.60 +	/**
    5.61 +	 * Sets a float value to the arbitrary attribute.
    5.62 +	 *
    5.63 +	 * @param name - Name of the attribute
    5.64 +	 * @param value - Value of the attribute
    5.65 +	 */
    5.66 +	public void setAttribute(String name, float value) {
    5.67 +		this.getJSObject().setProperty(name, value);
    5.68 +	}
    5.69 +
    5.70 +	/**
    5.71 +	 * Sets a double value to the arbitrary attribute.
    5.72 +	 *
    5.73 +	 * @param name - Name of the attribute
    5.74 +	 * @param value - Value of the attribute
    5.75 +	 */
    5.76 +	public void setAttribute(String name, double value) {
    5.77 +		this.getJSObject().setProperty(name, value);
    5.78 +	}
    5.79 +
    5.80 +	/**
    5.81 +	 * Allows nesting attribute objects.
    5.82 +	 *
    5.83 +	 */
    5.84 +	public void setAttribute(String name, Attributes attributes){
    5.85 +		this.getJSObject().setProperty(name, attributes.getJSObject());
    5.86 +	}
    5.87 +
    5.88 +	/**
    5.89 +	 * Get the value of an attribute as a String
    5.90 +	 *
    5.91 +	 * @param name - name of the attribute
    5.92 +	 * @return the attribute as String
    5.93 +	 */
    5.94 +	public String getAttributeAsString(String name){
    5.95 +		return this.getJSObject().getPropertyAsString(name);
    5.96 +	}
    5.97 +
    5.98 +	/**
    5.99 +	 * Get the value of an attribute as an integer.
   5.100 +	 *
   5.101 +	 * @param name - name of the attribute
   5.102 +	 * @return the attribute as integer
   5.103 +	 */
   5.104 +	public int getAttributeAsInt(String name){
   5.105 +		return this.getJSObject().getPropertyAsInt(name);
   5.106 +	}
   5.107 +
   5.108 +	/**
   5.109 +	 * Get the value of an attribute as an integer.
   5.110 +	 *
   5.111 +	 * @param name - name of the attribute
   5.112 +	 * @return the attribute as integer
   5.113 +	 */
   5.114 +
   5.115 +	public boolean getAttributeAsBoolean(String name){
   5.116 +		return this.getJSObject().getPropertyAsBoolean(name);
   5.117 +	}
   5.118 +
   5.119 +	/**
   5.120 +	 * Get the value of an attribute as an float.
   5.121 +	 *
   5.122 +	 * @param name - name of the attribute
   5.123 +	 * @return the attribute as float
   5.124 +	 */
   5.125 +	public float getAttributeAsFloat(String name){
   5.126 +		return this.getJSObject().getPropertyAsFloat(name);
   5.127 +	}
   5.128 +
   5.129 +	/**
   5.130 +	 * Get the value of an attribute as a double.
   5.131 +	 *
   5.132 +	 * @param name - name of the attribute
   5.133 +	 * @return the attribute as double
   5.134 +	 */
   5.135 +	public double getAttributeAsDouble(String name){
   5.136 +		return this.getJSObject().getPropertyAsInt(name);
   5.137 +	}
   5.138 +
   5.139 +	/**
   5.140 +	 * Get a nested attribute object.
   5.141 +	 *
   5.142 +	 * @param name - name of the attribute holding the attributes object
   5.143 +	 * @return nested attributes object
   5.144 +	 */
   5.145 +	public Attributes getAttributes(String name){
   5.146 +		return Attributes.narrowToAttributes(this.getJSObject().getProperty(name));
   5.147 +	}
   5.148 +
   5.149 +}
     6.1 --- a/src/main/test/org/gwtopenmaps/test/openlayers/client/GwtOpenLayersTestSuite.java	Wed Oct 07 10:23:51 2009 +0200
     6.2 +++ b/src/main/test/org/gwtopenmaps/test/openlayers/client/GwtOpenLayersTestSuite.java	Thu Oct 22 08:10:14 2009 +0200
     6.3 @@ -10,6 +10,7 @@
     6.4  import org.gwtopenmaps.test.openlayers.client.format.WKTTest;
     6.5  import org.gwtopenmaps.test.openlayers.client.geometry.PointTest;
     6.6  import org.gwtopenmaps.test.openlayers.client.map.MapOptionsTest;
     6.7 +import org.gwtopenmaps.test.openlayers.client.util.AttributesTest;
     6.8  import org.gwtopenmaps.test.openlayers.client.util.JSObjectTest;
     6.9  
    6.10  import com.google.gwt.junit.tools.GWTTestSuite;
    6.11 @@ -33,6 +34,7 @@
    6.12  
    6.13  		//Tests for Util
    6.14  		suite.addTestSuite(MapOptionsTest.class);
    6.15 +		suite.addTestSuite(AttributesTest.class);
    6.16  
    6.17  		//Tests for Util
    6.18  		suite.addTestSuite(JSObjectTest.class);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/main/test/org/gwtopenmaps/test/openlayers/client/util/AttributesTest.java	Thu Oct 22 08:10:14 2009 +0200
     7.3 @@ -0,0 +1,24 @@
     7.4 +package org.gwtopenmaps.test.openlayers.client.util;
     7.5 +
     7.6 +import org.gwtopenmaps.openlayers.client.util.Attributes;
     7.7 +import org.gwtopenmaps.test.openlayers.client.BaseTestCase;
     7.8 +
     7.9 +public class AttributesTest extends BaseTestCase{
    7.10 +
    7.11 +	public void testAttributes(){
    7.12 +		Attributes attributes = new Attributes();
    7.13 +		attributes.setAttribute("testInt", 1);
    7.14 +		assertEquals(1, attributes.getAttributeAsInt("testInt"));
    7.15 +		attributes.setAttribute("testFloat", 1.0f);
    7.16 +		assertEquals(1.0f, attributes.getAttributeAsFloat("testFloat"));
    7.17 +		attributes.setAttribute("testDouble", 1.0);
    7.18 +		assertEquals(1.0, attributes.getAttributeAsDouble("testDouble"));
    7.19 +		attributes.setAttribute("testBoolean", false);
    7.20 +		assertEquals(false, attributes.getAttributeAsBoolean("testBoolean"));
    7.21 +		attributes.setAttribute("testString", "test");
    7.22 +		assertEquals("test", attributes.getAttributeAsString("testString"));
    7.23 +//		assertEquals("testInt,testFloat,testDouble,testBoolean,testString",
    7.24 +//				attributes.getJSObject().getPropertyNames());
    7.25 +	}
    7.26 +
    7.27 +}