/projects/geotools-9.2/modules/library/main/src/main/java/org/geotools/styling/PolygonSymbolizerImpl.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 241 lines · 145 code · 29 blank · 67 comment · 48 complexity · cc45b9625c15836fe508d76350519f78 MD5 · raw file

  1. /*
  2. * GeoTools - The Open Source Java GIS Toolkit
  3. * http://geotools.org
  4. *
  5. * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation;
  10. * version 2.1 of the License.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. */
  17. package org.geotools.styling;
  18. import javax.measure.quantity.Length;
  19. import javax.measure.unit.Unit;
  20. import org.opengis.filter.expression.Expression;
  21. import org.opengis.style.StyleVisitor;
  22. import org.opengis.util.Cloneable;
  23. /**
  24. * Provides a representation of a PolygonSymbolizer in an SLD Document. A
  25. * PolygonSymbolizer defines how a polygon geometry should be rendered.
  26. *
  27. * @author James Macgill, CCG
  28. * @author Johann Sorel (Geomatys)
  29. *
  30. *
  31. * @source $URL$
  32. * @version $Id$
  33. */
  34. public class PolygonSymbolizerImpl extends AbstractSymbolizer implements PolygonSymbolizer, Cloneable {
  35. private Expression offset;
  36. private DisplacementImpl disp;
  37. private Fill fill = new FillImpl();
  38. private StrokeImpl stroke = new StrokeImpl();
  39. /**
  40. * Creates a new instance of DefaultPolygonStyler
  41. */
  42. protected PolygonSymbolizerImpl() {
  43. this(null,null,null,null,null,null,null,null);
  44. }
  45. protected PolygonSymbolizerImpl(Stroke stroke,
  46. Fill fill,
  47. Displacement disp,
  48. Expression offset,
  49. Unit<Length> uom,
  50. String geom,
  51. String name,
  52. Description desc) {
  53. super(name, desc, geom, uom);
  54. this.stroke = StrokeImpl.cast( stroke );
  55. this.fill = fill;
  56. this.disp = DisplacementImpl.cast( disp );
  57. this.offset = offset;
  58. }
  59. public Expression getPerpendicularOffset() {
  60. return offset;
  61. }
  62. public void setPerpendicularOffset(Expression offset ) {
  63. this.offset = offset;
  64. }
  65. public Displacement getDisplacement() {
  66. return disp;
  67. }
  68. public void setDisplacement(org.opengis.style.Displacement displacement) {
  69. this.disp = DisplacementImpl.cast( displacement );
  70. }
  71. /**
  72. * Provides the graphical-symbolization parameter to use to fill the area
  73. * of the geometry.
  74. *
  75. * @return The Fill style to use when rendering the area.
  76. */
  77. public Fill getFill() {
  78. return fill;
  79. }
  80. /**
  81. * Sets the graphical-symbolization parameter to use to fill the area of
  82. * the geometry.
  83. *
  84. * @param fill The Fill style to use when rendering the area.
  85. */
  86. public void setFill(org.opengis.style.Fill fill) {
  87. if (this.fill == fill) {
  88. return;
  89. }
  90. this.fill = FillImpl.cast(fill);
  91. }
  92. /**
  93. * Provides the graphical-symbolization parameter to use for the outline of
  94. * the Polygon.
  95. *
  96. * @return The Stroke style to use when rendering lines.
  97. */
  98. public StrokeImpl getStroke() {
  99. return stroke;
  100. }
  101. /**
  102. * Sets the graphical-symbolization parameter to use for the outline of the
  103. * Polygon.
  104. *
  105. * @param stroke The Stroke style to use when rendering lines.
  106. */
  107. public void setStroke(org.opengis.style.Stroke stroke) {
  108. if (this.stroke == stroke) {
  109. return;
  110. }
  111. this.stroke = StrokeImpl.cast( stroke );
  112. }
  113. /**
  114. * Accepts a StyleVisitor to perform some operation on this LineSymbolizer.
  115. *
  116. * @param visitor The visitor to accept.
  117. */
  118. public Object accept(StyleVisitor visitor,Object data) {
  119. return visitor.visit(this,data);
  120. }
  121. public void accept(org.geotools.styling.StyleVisitor visitor) {
  122. visitor.visit(this);
  123. }
  124. /**
  125. * Creates a deep copy clone. TODO: Need to complete the deep copy,
  126. * currently only shallow copy.
  127. *
  128. * @return The deep copy clone.
  129. *
  130. * @throws RuntimeException DOCUMENT ME!
  131. */
  132. public Object clone() {
  133. PolygonSymbolizerImpl clone;
  134. try {
  135. clone = (PolygonSymbolizerImpl) super.clone();
  136. if (fill != null) {
  137. clone.fill = (Fill) ((Cloneable) fill).clone();
  138. }
  139. if (stroke != null) {
  140. clone.stroke = (StrokeImpl) ((Cloneable) stroke).clone();
  141. }
  142. } catch (CloneNotSupportedException e) {
  143. throw new RuntimeException(e); // this should never happen.
  144. }
  145. return clone;
  146. }
  147. @Override
  148. public int hashCode() {
  149. final int prime = 31;
  150. int result = super.hashCode();
  151. result = prime * result + ((disp == null) ? 0 : disp.hashCode());
  152. result = prime * result + ((fill == null) ? 0 : fill.hashCode());
  153. result = prime * result + ((offset == null) ? 0 : offset.hashCode());
  154. result = prime * result + ((stroke == null) ? 0 : stroke.hashCode());
  155. return result;
  156. }
  157. @Override
  158. public boolean equals(Object obj) {
  159. if (this == obj)
  160. return true;
  161. if (!super.equals(obj))
  162. return false;
  163. if (getClass() != obj.getClass())
  164. return false;
  165. PolygonSymbolizerImpl other = (PolygonSymbolizerImpl) obj;
  166. if (disp == null) {
  167. if (other.disp != null)
  168. return false;
  169. } else if (!disp.equals(other.disp))
  170. return false;
  171. if (fill == null) {
  172. if (other.fill != null)
  173. return false;
  174. } else if (!fill.equals(other.fill))
  175. return false;
  176. if (offset == null) {
  177. if (other.offset != null)
  178. return false;
  179. } else if (!offset.equals(other.offset))
  180. return false;
  181. if (stroke == null) {
  182. if (other.stroke != null)
  183. return false;
  184. } else if (!stroke.equals(other.stroke))
  185. return false;
  186. return true;
  187. }
  188. static PolygonSymbolizerImpl cast(org.opengis.style.Symbolizer symbolizer) {
  189. if( symbolizer == null ){
  190. return null;
  191. }
  192. else if (symbolizer instanceof PolygonSymbolizerImpl){
  193. return (PolygonSymbolizerImpl) symbolizer;
  194. }
  195. else if( symbolizer instanceof org.opengis.style.PolygonSymbolizer ){
  196. org.opengis.style.PolygonSymbolizer polygonSymbolizer = (org.opengis.style.PolygonSymbolizer) symbolizer;
  197. PolygonSymbolizerImpl copy = new PolygonSymbolizerImpl();
  198. copy.setStroke( StrokeImpl.cast(polygonSymbolizer.getStroke()));
  199. copy.setDescription( polygonSymbolizer.getDescription() );
  200. copy.setDisplacement( polygonSymbolizer.getDisplacement());
  201. copy.setFill(polygonSymbolizer.getFill());
  202. copy.setGeometryPropertyName( polygonSymbolizer.getGeometryPropertyName());
  203. copy.setName(polygonSymbolizer.getName());
  204. copy.setPerpendicularOffset(polygonSymbolizer.getPerpendicularOffset());
  205. copy.setUnitOfMeasure( polygonSymbolizer.getUnitOfMeasure());
  206. return copy;
  207. }
  208. else {
  209. return null; // not possible
  210. }
  211. }
  212. }