org.geotools.styling.DisplacementImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gt-main Show documentation
Show all versions of gt-main Show documentation
The main module contains the GeoTools public interfaces that are used by
other GeoTools modules (and GeoTools applications). Where possible we make
use industry standard terms as provided by OGC and ISO standards.
The formal GeoTools public api consists of gt-metadata, jts and the gt-main module.
The main module contains the default implementations that are available provided
to other GeoTools modules using our factory system. Factories are obtained from
an appropriate FactoryFinder, giving applications a chance configure the factory
used using the Factory Hints facilities.
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Expression expr = ff.add( expression1, expression2 );
If you find yourself using implementation specific classes chances are you doing it wrong:
Expression expr = new AddImpl( expression1, expressiom2 );
The newest version!
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.styling;
// OpenGIS dependencies
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.util.Utilities;
import org.geotools.util.factory.GeoTools;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.expression.Expression;
import org.opengis.style.StyleVisitor;
import org.opengis.util.Cloneable;
/**
* @author Ian Turton, CCG
* @version $Id$
*/
public class DisplacementImpl implements Displacement, Cloneable {
/** The logger for the default core module. */
private static final java.util.logging.Logger LOGGER =
org.geotools.util.logging.Logging.getLogger(DisplacementImpl.class);
private FilterFactory filterFactory;
private Expression displacementX = null;
private Expression displacementY = null;
public DisplacementImpl() {
this(CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()));
}
public DisplacementImpl(FilterFactory factory) {
filterFactory = factory;
try {
displacementX = filterFactory.literal(0);
displacementY = filterFactory.literal(0);
} catch (org.geotools.filter.IllegalFilterException ife) {
LOGGER.severe("Failed to build defaultDisplacement: " + ife);
}
}
public DisplacementImpl(Expression dx, Expression dy) {
filterFactory = CommonFactoryFinder.getFilterFactory2(null);
displacementX = dx;
displacementY = dy;
}
public void setFilterFactory(FilterFactory factory) {
filterFactory = factory;
try {
displacementX = filterFactory.literal(0);
displacementY = filterFactory.literal(0);
} catch (org.geotools.filter.IllegalFilterException ife) {
LOGGER.severe("Failed to build defaultDisplacement: " + ife);
}
}
/**
* Setter for property displacementX.
*
* @param displacementX New value of property displacementX.
*/
public void setDisplacementX(Expression displacementX) {
this.displacementX = displacementX;
}
/**
* Set displacement x to the provided literal.
*
* @param displacementX New value of property displacementX.
*/
public void setDisplacementX(double displacementX) {
this.displacementX = filterFactory.literal(displacementX);
}
/**
* Setter for property displacementY.
*
* @param displacementY New value of property displacementY.
*/
public void setDisplacementY(Expression displacementY) {
this.displacementY = displacementY;
}
/**
* Set displacement y to the provided literal.
*
* @param displacementY New value of property displacementX.
*/
public void setDisplacementY(double displacementY) {
this.displacementY = filterFactory.literal(displacementY);
}
/**
* Getter for property displacementX.
*
* @return Value of property displacementX.
*/
public Expression getDisplacementX() {
return displacementX;
}
/**
* Getter for property displacementY.
*
* @return Value of property displacementY.
*/
public Expression getDisplacementY() {
return displacementY;
}
public Object accept(StyleVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public void accept(org.geotools.styling.StyleVisitor visitor) {
visitor.visit(this);
}
/* (non-Javadoc)
* @see org.opengis.util.Cloneable#clone()
*/
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Will not happen");
}
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DisplacementImpl) {
DisplacementImpl other = (DisplacementImpl) obj;
return Utilities.equals(displacementX, other.displacementX)
&& Utilities.equals(displacementY, other.displacementY);
}
return false;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
final int PRIME = 37;
int result = 17;
if (displacementX != null) {
result = (result * PRIME) + displacementX.hashCode();
}
if (displacementY != null) {
result = (result * PRIME) + displacementY.hashCode();
}
return result;
}
static DisplacementImpl cast(org.opengis.style.Displacement displacement) {
if (displacement == null) {
return null;
} else if (displacement instanceof DisplacementImpl) {
return (DisplacementImpl) displacement;
} else {
DisplacementImpl copy = new DisplacementImpl();
copy.setDisplacementX(displacement.getDisplacementX());
copy.setDisplacementY(displacement.getDisplacementY());
return copy;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy