1 44 45 package org.jfree.chart.axis; 46 47 import java.io.ObjectStreamException ; 48 import java.io.Serializable ; 49 50 54 public final class AxisLocation implements Serializable { 55 56 57 private static final long serialVersionUID = -3276922179323563410L; 58 59 60 public static final AxisLocation TOP_OR_LEFT = new AxisLocation( 61 "AxisLocation.TOP_OR_LEFT" 62 ); 63 64 65 public static final AxisLocation TOP_OR_RIGHT = new AxisLocation( 66 "AxisLocation.TOP_OR_RIGHT" 67 ); 68 69 70 public static final AxisLocation BOTTOM_OR_LEFT = new AxisLocation( 71 "AxisLocation.BOTTOM_OR_LEFT" 72 ); 73 74 75 public static final AxisLocation BOTTOM_OR_RIGHT = new AxisLocation( 76 "AxisLocation.BOTTOM_OR_RIGHT" 77 ); 78 79 80 private String name; 81 82 87 private AxisLocation(String name) { 88 this.name = name; 89 } 90 91 96 public String toString() { 97 return this.name; 98 } 99 100 108 public boolean equals(Object obj) { 109 110 if (this == obj) { 111 return true; 112 } 113 if (!(obj instanceof AxisLocation)) { 114 return false; 115 } 116 AxisLocation location = (AxisLocation) obj; 117 if (!this.name.equals(location.toString())) { 118 return false; 119 } 120 return true; 121 122 } 123 124 131 public static AxisLocation getOpposite(AxisLocation location) { 132 if (location == null) { 133 throw new IllegalArgumentException ("Null 'location' argument."); 134 } 135 AxisLocation result = null; 136 if (location == AxisLocation.TOP_OR_LEFT) { 137 result = AxisLocation.BOTTOM_OR_RIGHT; 138 } 139 else if (location == AxisLocation.TOP_OR_RIGHT) { 140 result = AxisLocation.BOTTOM_OR_LEFT; 141 } 142 else if (location == AxisLocation.BOTTOM_OR_LEFT) { 143 result = AxisLocation.TOP_OR_RIGHT; 144 } 145 else if (location == AxisLocation.BOTTOM_OR_RIGHT) { 146 result = AxisLocation.TOP_OR_LEFT; 147 } 148 else { 149 throw new IllegalStateException ("AxisLocation not recognised."); 150 } 151 return result; 152 } 153 154 161 private Object readResolve() throws ObjectStreamException { 162 if (this.equals(AxisLocation.TOP_OR_RIGHT)) { 163 return AxisLocation.TOP_OR_RIGHT; 164 } 165 else if (this.equals(AxisLocation.BOTTOM_OR_RIGHT)) { 166 return AxisLocation.BOTTOM_OR_RIGHT; 167 } 168 else if (this.equals(AxisLocation.TOP_OR_LEFT)) { 169 return AxisLocation.TOP_OR_LEFT; 170 } 171 else if (this.equals(AxisLocation.BOTTOM_OR_LEFT)) { 172 return AxisLocation.BOTTOM_OR_LEFT; 173 } 174 return null; 175 } 176 177 } 178 | Popular Tags |