    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.renderer;
    034
    035import java.awt.Color;
    036import java.io.Serializable;
    037
    038import com.orsoncharts.Range;
    039import com.orsoncharts.renderer.xyz.SurfaceRenderer;
    040import com.orsoncharts.util.ArgChecks;
    041
    042/**
    043 * A {@link ColorScale} that returns the same color for every value on the
    044 * scale.  This is used by the {@link SurfaceRenderer} when there is no need
    045 * to represent different value levels by color.
    046 * <br><br>
    047 * NOTE: This class is serializable, but the serialization format is subject
    048 * to change in future releases and should not be relied upon for persisting
    049 * instances of this class.
    050 *
    051 * @since 1.1
    052 */
    053@SuppressWarnings("serial")
    054public class FixedColorScale implements ColorScale, Serializable {
    055
    056    /** The fixed color. */
    057    private Color color;
    058
    059    /**
    060     * The range (in fact this is here just to have something to return in the
    061     * getRange() method, it is not used by this implementation since we
    062     * always return the same color for all values).
    063     */
    064    private Range range;
    065
    066    /**
    067     * Creates a new {@code FixedColorScale} instance.
    068     *
    069     * @param color  the color ({@code null} not permitted).
    070     */
    071    public FixedColorScale(Color color) {
    072        ArgChecks.nullNotPermitted(color, "color");
    073        this.color = color;
    074        this.range = new Range(0, 1);
    075    }
    076
    077    /**
    078     * Returns the range {@code 0.0} to {@code 1.0} always.
    079     *
    080     * @return The range (never {@code null}).
    081     */
    082    @Override
    083    public Range getRange() {
    084        return this.range;
    085    }
    086
    087    /**
    088     * Returns a single color (as specified in the constructor) for all values.
    089     *
    090     * @param value  the value.
    091     *
    092     * @return The fixed color.
    093     */
    094    @Override
    095    public Color valueToColor(double value) {
    096        return this.color;
    097    }
    098
    099    /**
    100     * Tests this instance for equality with an arbitrary object.
    101     *
    102     * @param obj  the object ({@code null} permitted).
    103     *
    104     * @return A boolean.
    105     */
    106    @Override
    107    public boolean equals(Object obj) {
    108        if (obj == this) {
    109            return true;
    110        }
    111        if (!(obj instanceof FixedColorScale)) {
    112            return false;
    113        }
    114        FixedColorScale that = (FixedColorScale) obj;
    115        if (!this.color.equals(that.color)) {
    116            return false;
    117        }
    118        return true;
    119    }
    120}