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.api; 030 031import java.awt.geom.Rectangle2D; 032 033/** 034 * Used to indicate the edge of a rectangle. 035 */ 036public enum RectangleEdge { 037 038 /** Top. */ 039 TOP, 040 041 /** Bottom. */ 042 BOTTOM, 043 044 /** Left. */ 045 LEFT, 046 047 /** Right. */ 048 RIGHT; 049 050 /** 051 * Returns {@code true} if the edge is {@code TOP} or 052 * {@code BOTTOM}, and {@code false} otherwise. 053 * 054 * @param edge the edge. 055 * 056 * @return A boolean. 057 */ 058 public static boolean isTopOrBottom(RectangleEdge edge) { 059 return (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM); 060 } 061 062 /** 063 * Returns {@code true} if the edge is {@code LEFT} or 064 * {@code RIGHT}, and {@code false} otherwise. 065 * 066 * @param edge the edge. 067 * 068 * @return A boolean. 069 */ 070 public static boolean isLeftOrRight(RectangleEdge edge) { 071 return (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT); 072 } 073 074 /** 075 * Returns the opposite edge. 076 * 077 * @param edge an edge. 078 * 079 * @return The opposite edge. 080 */ 081 public static RectangleEdge opposite(RectangleEdge edge) { 082 switch (edge) { 083 case TOP: 084 return RectangleEdge.BOTTOM; 085 case BOTTOM: 086 return RectangleEdge.TOP; 087 case LEFT: 088 return RectangleEdge.RIGHT; 089 case RIGHT: 090 return RectangleEdge.LEFT; 091 default: 092 return null; 093 } 094 } 095 096 /** 097 * Returns the x or y coordinate of the specified edge. 098 * 099 * @param rectangle the rectangle. 100 * @param edge the edge. 101 * 102 * @return The coordinate. 103 */ 104 public static double coordinate(Rectangle2D rectangle, RectangleEdge edge) { 105 switch (edge) { 106 case TOP: 107 return rectangle.getMinY(); 108 case BOTTOM: 109 return rectangle.getMaxY(); 110 case LEFT: 111 return rectangle.getMinX(); 112 case RIGHT: 113 return rectangle.getMaxX(); 114 default: 115 return 0.0; 116 } 117 } 118 119}