    001/* ===========================================================
    002 * Orson Charts : a 3D chart library for the Java(tm) platform
    003 * ===========================================================
    004 *
    005 * (C)opyright 2013-2016, by Object Refinery Limited.  All rights reserved.
    006 *
    007 * http://www.object-refinery.com/orsoncharts/index.html
    008 *
    009 * This program is free software: you can redistribute it and/or modify
    010 * it under the terms of the GNU General Public License as published by
    011 * the Free Software Foundation, either version 3 of the License, or
    012 * (at your option) any later version.
    013 *
    014 * This program is distributed in the hope that it will be useful,
    015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    017 * GNU General Public License for more details.
    018 *
    019 * You should have received a copy of the GNU General Public License
    020 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    021 *
    022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    023 * Other names may be trademarks of their respective owners.]
    024 *
    025 * If you do not wish to be bound by the terms of the GPL, an alternative
    026 * commercial license can be purchased.  For details, please see visit the
    027 * Orson Charts home page:
    028 *
    029 * http://www.object-refinery.com/orsoncharts/index.html
    030 *
    031 */
    032
    033package com.orsoncharts.table;
    034
    035import java.awt.geom.Dimension2D;
    036import java.io.Serializable;
    037
    038/**
    039 * An element dimension (in fact a simple implementation of the
    040 * {@code Dimension2D} interface).
    041 * <br><br>
    042 * NOTE: This class is serializable, but the serialization format is subject
    043 * to change in future releases and should not be relied upon for persisting
    044 * instances of this class.
    045 */
    046@SuppressWarnings("serial")
    047public final class ElementDimension extends Dimension2D
    048        implements Serializable {
    049
    050    /** The width (in Java2D units). */
    051    private double width;
    052
    053    /** The height (in Java2D units). */
    054    private double height;
    055
    056    /**
    057     * Creates a new dimension object.
    058     *
    059     * @param width  the width.
    060     * @param height  the height.
    061     */
    062    public ElementDimension(double width, double height) {
    063        super();
    064        this.width = width;
    065        this.height = height;
    066    }
    067
    068    /**
    069     * Returns the width.
    070     *
    071     * @return The width.
    072     */
    073    @Override
    074    public double getWidth() {
    075        return this.width;
    076    }
    077
    078    /**
    079     * Returns the height.
    080     *
    081     * @return The height.
    082     */
    083    @Override
    084    public double getHeight() {
    085        return this.height;
    086    }
    087
    088    /**
    089     * Sets the size.
    090     *
    091     * @param width  the width.
    092     * @param height  the height.
    093     */
    094    @Override
    095    public void setSize(double width, double height) {
    096        this.width = width;
    097        this.height = height;
    098    }
    099
    100    /**
    101     * Tests this dimension for equality with an arbitrary object.
    102     *
    103     * @param obj  the object ({@code null} permitted).
    104     *
    105     * @return A boolean.
    106     */
    107    @Override
    108    public boolean equals(Object obj) {
    109        if (obj == this) {
    110            return true;
    111        }
    112        if (!(obj instanceof ElementDimension)) {
    113            return false;
    114        }
    115        ElementDimension that = (ElementDimension) obj;
    116        if (this.width != that.width) {
    117            return false;
    118        }
    119        if (this.height != that.height) {
    120            return false;
    121        }
    122        return true;
    123    }
    124
    125    /**
    126     * Returns a string representation of this dimension, primarily for
    127     * debugging purposes.
    128     *
    129     * @return A string.
    130     */
    131    @Override
    132    public String toString() {
    133        return "ElementDimension(" + this.width + ", " + this.height + ")";
    134    }
    135}