All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geotools.styling.AnchorPointImpl Maven / Gradle / Ivy

Go to download

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.util.Cloneable;

/**
 * Direct implementation of AnchorPoint.
 *
 * @author Ian Turton, CCG
 * @version $Id$
 */
public class AnchorPointImpl implements AnchorPoint, Cloneable {

    /** The logger for the default core module. */
    private static final java.util.logging.Logger LOGGER =
            org.geotools.util.logging.Logging.getLogger(AnchorPointImpl.class);

    private FilterFactory filterFactory;
    private Expression anchorPointX = null;
    private Expression anchorPointY = null;

    static AnchorPointImpl cast(org.opengis.style.AnchorPoint anchor) {
        if (anchor == null) {
            return null;
        } else if (anchor instanceof AnchorPointImpl) {
            return (AnchorPointImpl) anchor;
        } else {
            AnchorPointImpl copy = new AnchorPointImpl();
            copy.setAnchorPointX(anchor.getAnchorPointX());
            copy.setAnchorPointY(anchor.getAnchorPointY());
            return copy;
        }
    }

    public AnchorPointImpl() {
        this(CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()));
    }
    /** Creates a new instance of DefaultAnchorPoint */
    public AnchorPointImpl(FilterFactory filterFactory) {
        this.filterFactory = filterFactory;
        try {
            anchorPointX = filterFactory.literal(0.0);
            anchorPointY = filterFactory.literal(0.5);
        } catch (org.geotools.filter.IllegalFilterException ife) {
            LOGGER.severe("Failed to build defaultAnchorPoint: " + ife);
        }
    }

    public AnchorPointImpl(FilterFactory filterFactory, Expression x, Expression y) {
        this.filterFactory = filterFactory;
        anchorPointX = x;
        anchorPointY = y;
    }
    /**
     * Getter for property anchorPointX.
     *
     * @return Value of property anchorPointX.
     */
    public Expression getAnchorPointX() {
        return anchorPointX;
    }

    /**
     * Setter for property anchorPointX.
     *
     * @param anchorPointX New value of property anchorPointX.
     */
    public void setAnchorPointX(Expression anchorPointX) {
        this.anchorPointX = anchorPointX;
    }
    /**
     * Define the anchor point.
     *
     * @param x Literal value of property anchorPointX
     */
    public void setAnchorPointX(double x) {
        this.anchorPointX = filterFactory.literal(x);
    }

    /**
     * Getter for property anchorPointY.
     *
     * @return Value of property anchorPointY.
     */
    public Expression getAnchorPointY() {
        return anchorPointY;
    }

    /**
     * Setter for property anchorPointY.
     *
     * @param anchorPointY New value of property anchorPointY.
     */
    public void setAnchorPointY(Expression anchorPointY) {
        this.anchorPointY = anchorPointY;
    }

    /**
     * Define the anchor point.
     *
     * @param x Literal value of property anchorPointX
     */
    public void getAnchorPointY(double x) {
        this.anchorPointY = filterFactory.literal(x);
    }

    public void accept(StyleVisitor visitor) {
        visitor.visit(this);
    }

    public Object accept(org.opengis.style.StyleVisitor visitor, Object data) {
        return visitor.visit(this, data);
    }

    /* (non-Javadoc)
     * @see Cloneable#clone()
     */
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException("Never happen");
        }
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj instanceof AnchorPointImpl) {
            AnchorPointImpl other = (AnchorPointImpl) obj;

            return Utilities.equals(this.anchorPointX, other.anchorPointX)
                    && Utilities.equals(this.anchorPointY, other.anchorPointY);
        }

        return false;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        final int PRIME = 37;
        int result = 17;

        if (anchorPointX != null) {
            result = (result * PRIME) + anchorPointX.hashCode();
        }

        if (anchorPointY != null) {
            result = (result * PRIME) + anchorPointY.hashCode();
        }

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy