    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.util;
    034
    035/**
    036 * Used to indicate the position of an anchor point for a text string.  This is
    037 * frequently used to align a string to a fixed point in some coordinate space.
    038 */
    039public enum TextAnchor {
    040
    041    /** Top/left. */
    042    TOP_LEFT("TextAnchor.TOP_LEFT"),
    043
    044    /** Top/center. */
    045    TOP_CENTER("TextAnchor.TOP_CENTER"),
    046
    047    /** Top/right. */
    048    TOP_RIGHT("TextAnchor.TOP_RIGHT"),
    049
    050    /** Half-ascent/left. */
    051    HALF_ASCENT_LEFT("TextAnchor.HALF_ASCENT_LEFT"),
    052
    053    /** Half-ascent/center. */
    054    HALF_ASCENT_CENTER("TextAnchor.HALF_ASCENT_CENTER"),
    055
    056    /** Half-ascent/right. */
    057    HALF_ASCENT_RIGHT("TextAnchor.HALF_ASCENT_RIGHT"),
    058
    059    /** Middle/left. */
    060    CENTER_LEFT("TextAnchor.CENTER_LEFT"),
    061
    062    /** Middle/center. */
    063    CENTER("TextAnchor.CENTER"),
    064
    065    /** Middle/right. */
    066    CENTER_RIGHT("TextAnchor.CENTER_RIGHT"),
    067
    068    /** Baseline/left. */
    069    BASELINE_LEFT("TextAnchor.BASELINE_LEFT"),
    070
    071    /** Baseline/center. */
    072    BASELINE_CENTER("TextAnchor.BASELINE_CENTER"),
    073
    074    /** Baseline/right. */
    075    BASELINE_RIGHT("TextAnchor.BASELINE_RIGHT"),
    076
    077    /** Bottom/left. */
    078    BOTTOM_LEFT("TextAnchor.BOTTOM_LEFT"),
    079
    080    /** Bottom/center. */
    081    BOTTOM_CENTER("TextAnchor.BOTTOM_CENTER"),
    082
    083    /** Bottom/right. */
    084    BOTTOM_RIGHT("TextAnchor.BOTTOM_RIGHT");
    085
    086    /** The name. */
    087    private String name;
    088
    089    /**
    090     * Private constructor.
    091     *
    092     * @param name  the name.
    093     */
    094    private TextAnchor(String name) {
    095        this.name = name;
    096    }
    097
    098    /**
    099     * Returns {@code true} if this anchor is at the left side of the
    100     * text bounds, and {@code false} otherwise.
    101     *
    102     * @return A boolean.
    103     */
    104    public boolean isLeft() {
    105        return this == TOP_LEFT || this == CENTER_LEFT
    106                || this == HALF_ASCENT_LEFT || this == BASELINE_LEFT
    107                || this == BOTTOM_LEFT;
    108    }
    109
    110    /**
    111     * Returns {@code true} if this anchor is horizontally at the center
    112     * of the text bounds, and {@code false} otherwise.
    113     *
    114     * @return A boolean.
    115     */
    116    public boolean isHorizontalCenter() {
    117        return this == TOP_CENTER || this == CENTER
    118                || this == HALF_ASCENT_CENTER || this == BASELINE_CENTER
    119                || this == BOTTOM_CENTER;
    120    }
    121
    122    /**
    123     * Returns {@code true} if this anchor is at the right side of the
    124     * text bounds, and {@code false} otherwise.
    125     *
    126     * @return A boolean.
    127     */
    128    public boolean isRight() {
    129        return this == TOP_RIGHT || this == CENTER_RIGHT
    130                || this == HALF_ASCENT_RIGHT || this == BASELINE_RIGHT
    131                || this == BOTTOM_RIGHT;
    132    }
    133
    134    /**
    135     * Returns {@code true} if this anchor is at the top of the
    136     * text bounds, and {@code false} otherwise.
    137     *
    138     * @return A boolean.
    139     */
    140    public boolean isTop() {
    141        return this == TOP_LEFT || this == TOP_CENTER || this == TOP_RIGHT;
    142    }
    143
    144    /**
    145     * Returns {@code true} if this anchor is at the half-ascent level of
    146     * the text bounds, and {@code false} otherwise.
    147     *
    148     * @return A boolean.
    149     */
    150    public boolean isHalfAscent() {
    151        return this == HALF_ASCENT_LEFT || this == HALF_ASCENT_CENTER
    152                || this == HALF_ASCENT_RIGHT;
    153    }
    154
    155    /**
    156     * Returns {@code true} if this anchor is at the half-height level of
    157     * the text bounds, and {@code false} otherwise.
    158     *
    159     * @return A boolean.
    160     */
    161    public boolean isHalfHeight() {
    162        return this == CENTER_LEFT || this == CENTER || this == CENTER_RIGHT;
    163    }
    164
    165    /**
    166     * Returns {@code true} if this anchor is at the baseline level of
    167     * the text bounds, and {@code false} otherwise.
    168     *
    169     * @return A boolean.
    170     */
    171    public boolean isBaseline() {
    172        return this == BASELINE_LEFT || this == BASELINE_CENTER
    173                || this == BASELINE_RIGHT;
    174    }
    175
    176    /**
    177     * Returns {@code true} if this anchor is at the bottom of
    178     * the text bounds, and {@code false} otherwise.
    179     *
    180     * @return A boolean.
    181     */
    182    public boolean isBottom() {
    183        return this == BOTTOM_LEFT || this == BOTTOM_CENTER
    184                || this == BOTTOM_RIGHT;
    185    }
    186
    187    /**
    188     * Returns a string representing the object.
    189     *
    190     * @return The string.
    191     */
    192    @Override
    193    public String toString() {
    194        return this.name;
    195    }
    196
    197}