001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2022, by David Gilbert and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 */
028
029package org.jfree.chart.text;
030
031/**
032 * Used to indicate the position of an anchor point for a text string.  This is
033 * frequently used to align a string to a fixed point in some coordinate space.
034 */
035public enum TextAnchor {
036
037    /** Top/left. */
038    TOP_LEFT,
039
040    /** Top/center. */
041    TOP_CENTER,
042
043    /** Top/right. */
044    TOP_RIGHT,
045
046    /** Half-ascent/left. */
047    HALF_ASCENT_LEFT,
048
049    /** Half-ascent/center. */
050    HALF_ASCENT_CENTER,
051
052    /** Half-ascent/right. */
053    HALF_ASCENT_RIGHT,
054
055    /** Middle/left. */
056    CENTER_LEFT,
057
058    /** Middle/center. */
059    CENTER ,
060
061    /** Middle/right. */
062    CENTER_RIGHT,
063
064    /** Baseline/left. */
065    BASELINE_LEFT,
066
067    /** Baseline/center. */
068    BASELINE_CENTER,
069
070    /** Baseline/right. */
071    BASELINE_RIGHT,
072
073    /** Bottom/left. */
074    BOTTOM_LEFT,
075
076    /** Bottom/center. */
077    BOTTOM_CENTER,
078
079    /** Bottom/right. */
080    BOTTOM_RIGHT;
081
082    /** 
083     * Returns {@code true} if the anchor is a left-side anchor, and
084     * {@code false} otherwise.
085     * 
086     * @return A boolean.
087     */
088    public boolean isLeft() {
089        return this == BASELINE_LEFT || this == BOTTOM_LEFT 
090                || this == CENTER_LEFT || this == HALF_ASCENT_LEFT 
091                || this == TOP_LEFT;
092    }
093
094    /** 
095     * Returns {@code true} if the anchor is a right-side anchor, and
096     * {@code false} otherwise.
097     * 
098     * @return A boolean.
099     */
100    public boolean isRight() {
101        return this == BASELINE_RIGHT || this == BOTTOM_RIGHT 
102                || this == CENTER_RIGHT || this == HALF_ASCENT_RIGHT 
103                || this == TOP_RIGHT;
104    }
105
106    /** 
107     * Returns {@code true} if the anchor is a center anchor, and
108     * {@code false} otherwise.
109     * 
110     * @return A boolean.
111     */
112    public boolean isHorizontalCenter() {
113        return this == BASELINE_CENTER || this == BOTTOM_CENTER 
114                || this == CENTER || this == HALF_ASCENT_CENTER 
115                || this == TOP_CENTER;
116    }
117
118    /** 
119     * Returns {@code true} if the anchor is a top anchor, and
120     * {@code false} otherwise.
121     * 
122     * @return A boolean.
123     */
124    public boolean isTop() {
125        return this == TOP_LEFT || this == TOP_CENTER || this == TOP_RIGHT;
126    }
127
128    /** 
129     * Returns {@code true} if the anchor is a bottom anchor, and
130     * {@code false} otherwise.
131     * 
132     * @return A boolean.
133     */
134    public boolean isBottom() {
135        return this == BOTTOM_LEFT || this == BOTTOM_CENTER 
136                || this == BOTTOM_RIGHT;
137    }
138    
139    /** 
140     * Returns {@code true} if the anchor is a baseline anchor, and
141     * {@code false} otherwise.
142     * 
143     * @return A boolean.
144     */
145    public boolean isBaseline() {
146        return this == BASELINE_LEFT || this == BASELINE_CENTER 
147                || this == BASELINE_RIGHT;
148    }
149    
150    /** 
151     * Returns {@code true} if the anchor is a half-ascent anchor, and
152     * {@code false} otherwise.
153     * 
154     * @return A boolean.
155     */
156    public boolean isHalfAscent() {
157        return this == HALF_ASCENT_LEFT || this == HALF_ASCENT_CENTER 
158                || this == HALF_ASCENT_RIGHT;
159    }
160    
161    /** 
162     * Returns {@code true} if the anchor is a half-ascent anchor, and
163     * {@code false} otherwise.
164     * 
165     * @return A boolean.
166     */
167    public boolean isVerticalCenter() {
168        return this == CENTER_LEFT || this == CENTER  || this == CENTER_RIGHT;
169    }
170
171}