    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.graphics3d;
    034
    035import java.awt.Color;
    036import java.awt.Font;
    037import com.orsoncharts.util.ArgChecks;
    038
    039/**
    040 * A face that carries a label (and is itself invisible).
    041 *
    042 * @since 1.3
    043 */
    044public class LabelFace extends Face {
    045
    046    /** A transparent color. */
    047    private static final Color TRANSPARENT = new Color(0, 0, 0, 0);
    048
    049    /** The label. */
    050    private String label;
    051
    052    /** The font for the label. */
    053    private Font font;
    054
    055    /** The foreground color for the text. */
    056    private Color textColor;
    057
    058    /** The background color. */
    059    private Color backgroundColor;
    060
    061    /**
    062     * Creates a new instance.
    063     *
    064     * @param owner  the object that this face belongs to ({@code null}
    065     *     not permitted).
    066     * @param vertices  the vertices that define the face ({@code null}
    067     *     not permitted).
    068     * @param label  the label ({@code null} not permitted).
    069     * @param font  the font ({@code null} not permitted).
    070     * @param textColor  the foreground color ({@code null} not permitted).
    071     * @param backgroundColor   the background color for the label
    072     *     ({@code null} not permitted).
    073     */
    074    public LabelFace(Object3D owner, int[] vertices, String label, Font font,
    075            Color textColor, Color backgroundColor) {
    076        super(owner, vertices);
    077        ArgChecks.nullNotPermitted(label, "label");
    078        ArgChecks.nullNotPermitted(font, "font");
    079        ArgChecks.nullNotPermitted(textColor, "textColor");
    080        ArgChecks.nullNotPermitted(backgroundColor, "backgroundColor");
    081        this.label = label;
    082        this.font = font;
    083        this.textColor = textColor;
    084        this.backgroundColor = backgroundColor;
    085    }
    086
    087    /**
    088     * Returns a transparent color, so that the face is not visible.
    089     *
    090     * @return A transparent color.
    091     */
    092    @Override
    093    public Color getColor() {
    094        return TRANSPARENT;
    095    }
    096
    097    /**
    098     * Returns the label.
    099     *
    100     * @return The label (never {@code null}).
    101     */
    102    public String getLabel() {
    103        return this.label;
    104    }
    105
    106    /**
    107     * Sets the label.
    108     *
    109     * @param label  the new label ({@code null} not permitted).
    110     */
    111    public void setLabel(String label) {
    112        ArgChecks.nullNotPermitted(label, "label");
    113        this.label = label;
    114    }
    115
    116    /**
    117     * Returns the font.
    118     *
    119     * @return The font (never {@code null}).
    120     */
    121    public Font getFont() {
    122        return this.font;
    123    }
    124
    125    /**
    126     * Sets the font.
    127     *
    128     * @param font  the font ({@code null} not permitted).
    129     */
    130    public void setFont(Font font) {
    131        ArgChecks.nullNotPermitted(font, "font");
    132        this.font = font;
    133    }
    134
    135    /**
    136     * Returns the foreground color for the label text.
    137     *
    138     * @return The foreground color (never {@code null}).
    139     */
    140    public Color getTextColor() {
    141        return this.textColor;
    142    }
    143
    144    /**
    145     * Sets the foreground color for the label text.
    146     *
    147     * @param color  the color ({@code null} not permitted).
    148     */
    149    public void setTextColor(Color color) {
    150        this.textColor = color;
    151    }
    152
    153    /**
    154     * Returns the background color.  The default value is a fully transparent
    155     * color.
    156     *
    157     * @return The background color (never {@code null}).
    158     */
    159    public Color getBackgroundColor() {
    160        return this.backgroundColor;
    161    }
    162
    163    /**
    164     * Sets the background color.
    165     *
    166     * @param color  the color ({@code null} not permitted).
    167     */
    168    public void setBackgroundColor(Color color) {
    169        this.backgroundColor = color;
    170    }
    171
    172}