1 42 43 package org.jfree.ui; 44 45 import java.awt.geom.Rectangle2D ; 46 import java.io.ObjectStreamException ; 47 import java.io.Serializable ; 48 49 54 public final class RectangleEdge implements Serializable { 55 56 57 private static final long serialVersionUID = -7400988293691093548L; 58 59 60 public static final RectangleEdge TOP 61 = new RectangleEdge("RectangleEdge.TOP"); 62 63 64 public static final RectangleEdge BOTTOM 65 = new RectangleEdge("RectangleEdge.BOTTOM"); 66 67 68 public static final RectangleEdge LEFT 69 = new RectangleEdge("RectangleEdge.LEFT"); 70 71 72 public static final RectangleEdge RIGHT 73 = new RectangleEdge("RectangleEdge.RIGHT"); 74 75 76 private String name; 77 78 83 private RectangleEdge(final String name) { 84 this.name = name; 85 } 86 87 92 public String toString() { 93 return this.name; 94 } 95 96 104 public boolean equals(final Object o) { 105 106 if (this == o) { 107 return true; 108 } 109 if (!(o instanceof RectangleEdge)) { 110 return false; 111 } 112 113 final RectangleEdge order = (RectangleEdge) o; 114 if (!this.name.equals(order.name)) { 115 return false; 116 } 117 118 return true; 119 120 } 121 122 127 public int hashCode() { 128 return this.name.hashCode(); 129 } 130 131 139 public static boolean isTopOrBottom(final RectangleEdge edge) { 140 return (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM); 141 } 142 143 151 public static boolean isLeftOrRight(final RectangleEdge edge) { 152 return (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT); 153 } 154 155 162 public static RectangleEdge opposite(final RectangleEdge edge) { 163 RectangleEdge result = null; 164 if (edge == RectangleEdge.TOP) { 165 result = RectangleEdge.BOTTOM; 166 } 167 else if (edge == RectangleEdge.BOTTOM) { 168 result = RectangleEdge.TOP; 169 } 170 else if (edge == RectangleEdge.LEFT) { 171 result = RectangleEdge.RIGHT; 172 } 173 else if (edge == RectangleEdge.RIGHT) { 174 result = RectangleEdge.LEFT; 175 } 176 return result; 177 } 178 179 187 public static double coordinate(final Rectangle2D rectangle, 188 final RectangleEdge edge) { 189 double result = 0.0; 190 if (edge == RectangleEdge.TOP) { 191 result = rectangle.getMinY(); 192 } 193 else if (edge == RectangleEdge.BOTTOM) { 194 result = rectangle.getMaxY(); 195 } 196 else if (edge == RectangleEdge.LEFT) { 197 result = rectangle.getMinX(); 198 } 199 else if (edge == RectangleEdge.RIGHT) { 200 result = rectangle.getMaxX(); 201 } 202 return result; 203 } 204 205 212 private Object readResolve() throws ObjectStreamException { 213 RectangleEdge result = null; 214 if (this.equals(RectangleEdge.TOP)) { 215 result = RectangleEdge.TOP; 216 } 217 else if (this.equals(RectangleEdge.BOTTOM)) { 218 result = RectangleEdge.BOTTOM; 219 } 220 else if (this.equals(RectangleEdge.LEFT)) { 221 result = RectangleEdge.LEFT; 222 } 223 else if (this.equals(RectangleEdge.RIGHT)) { 224 result = RectangleEdge.RIGHT; 225 } 226 return result; 227 } 228 229 } 230 | Popular Tags |