001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.styling;
017:
018: import org.opengis.filter.expression.Expression;
019: import org.geotools.event.GTComponent;
020: import org.geotools.event.GTConstant;
021: import org.geotools.filter.ConstantExpression;
022:
023: /**
024: * A Displacement gives X and Y offset displacements to use for rendering a
025: * text label near a point.
026: *
027: *
028: * @author Ian Turton, CCG
029: * @version $Id: Displacement.java 25459 2007-05-08 05:19:25Z jgarnett $
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/api/src/main/java/org/geotools/styling/Displacement.java $
031: */
032: public interface Displacement extends GTComponent {
033: /**
034: * Default Displacment instance.
035: */
036: static final Displacement DEFAULT = new ConstantDisplacement() {
037: public Expression getDisplacementX() {
038: return ConstantExpression.ZERO;
039: }
040:
041: public Expression getDisplacementY() {
042: return ConstantExpression.ZERO;
043: }
044: };
045:
046: /**
047: * Null Displacement instance.
048: */
049: static final Displacement NULL = new ConstantDisplacement() {
050: public Expression getDisplacementX() {
051: return ConstantExpression.NULL;
052: }
053:
054: public Expression getDisplacementY() {
055: return ConstantExpression.NULL;
056: }
057: };
058:
059: //TODO: add Displacement to GeoAPI
060: /**
061: * Returns an expression that computes a pixel offset from the geometry
062: * point. This offset point is where the text's anchor point gets
063: * located. If this expression is null, the default offset of zero is
064: * used.
065: *
066: * @return DOCUMENT ME!
067: */
068: Expression getDisplacementX();
069:
070: /**
071: * Sets the expression that computes a pixel offset from the geometry
072: * point.
073: *
074: * @param x DOCUMENT ME!
075: */
076: void setDisplacementX(Expression x);
077:
078: /**
079: * Returns an expression that computes a pixel offset from the geometry
080: * point. This offset point is where the text's anchor point gets
081: * located. If this expression is null, the default offset of zero is
082: * used.
083: *
084: * @return DOCUMENT ME!
085: */
086: Expression getDisplacementY();
087:
088: /**
089: * Sets the expression that computes a pixel offset from the geometry
090: * point.
091: *
092: * @param y DOCUMENT ME!
093: */
094: void setDisplacementY(Expression y);
095:
096: void accept(StyleVisitor visitor);
097: }
098:
099: abstract class ConstantDisplacement extends GTConstant implements
100: Displacement {
101: private void cannotModifyConstant() {
102: throw new UnsupportedOperationException(
103: "Constant Displacement may not be modified");
104: }
105:
106: public void setDisplacementX(Expression x) {
107: cannotModifyConstant();
108: }
109:
110: public void setDisplacementY(Expression y) {
111: cannotModifyConstant();
112: }
113:
114: public void accept(StyleVisitor visitor) {
115: cannotModifyConstant();
116: }
117: };
|