1 11 package org.eclipse.ui.internal.menus; 12 13 import org.eclipse.jface.util.Util; 14 15 36 public final class SLocation { 37 38 41 public static final char MNEMONIC_NONE = 0; 42 43 47 private final String imageStyle; 48 49 52 private final char mnemonic; 53 54 58 private final SOrder ordering; 59 60 64 private final LocationElement path; 65 66 71 public SLocation() { 72 this(new SBar()); 73 } 74 75 82 public SLocation(final LocationElement path) { 83 this(path, MNEMONIC_NONE); 84 } 85 86 99 public SLocation(final SLocation parent, final String id) { 100 this(parent, id, MNEMONIC_NONE); 101 } 102 103 118 public SLocation(final SLocation parent, final String id, final char mnemonic) { 119 120 if (parent == null) { 121 throw new NullPointerException ("The parent cannot be null"); } 123 124 if (id == null) { 125 throw new NullPointerException ("The id cannot be null"); } 127 128 final LocationElement parentPath = parent.getPath(); 129 final LocationElement childPath = parentPath.createChild(id); 130 131 this.imageStyle = null; 132 this.mnemonic = mnemonic; 133 this.ordering = null; 134 this.path = childPath; 135 } 136 137 148 public SLocation(final LocationElement path, final char mnemonic) { 149 this(path, null, mnemonic); 150 } 151 152 162 public SLocation(final LocationElement path, final SOrder ordering) { 163 this(path, ordering, MNEMONIC_NONE); 164 } 165 166 180 public SLocation(final LocationElement path, final SOrder ordering, 181 final char mnemonic) { 182 this(path, ordering, mnemonic, null); 183 184 } 185 186 203 public SLocation(final LocationElement path, final SOrder ordering, 204 final char mnemonic, String imageStyle) { 205 if ((imageStyle != null) && (imageStyle.length() == 0)) { 206 imageStyle = null; 207 } 208 209 if (path == null) { 210 throw new NullPointerException ( 211 "The path for a location must not be null"); } 213 214 this.mnemonic = mnemonic; 215 this.imageStyle = imageStyle; 216 this.ordering = ordering; 217 this.path = path; 218 } 219 220 226 public final String getImageStyle() { 227 return imageStyle; 228 } 229 230 236 public final char getMnemonic() { 237 return mnemonic; 238 } 239 240 245 public final SOrder getOrdering() { 246 return ordering; 247 } 248 249 254 public final LocationElement getPath() { 255 return path; 256 } 257 258 public final String toString() { 259 final StringBuffer buffer = new StringBuffer (); 260 buffer.append("SLocation("); buffer.append(path); 262 buffer.append(','); 263 if (mnemonic != MNEMONIC_NONE) { 264 buffer.append(mnemonic); 265 buffer.append(','); 266 } 267 buffer.append(imageStyle); 268 buffer.append(','); 269 buffer.append(ordering); 270 buffer.append(')'); 271 return buffer.toString(); 272 } 273 274 277 public boolean equals(Object obj) { 278 if (this == obj) { 279 return true; 280 } 281 if (obj instanceof SLocation) { 282 SLocation loc = (SLocation) obj; 283 return path.equals(loc.path) && mnemonic == loc.mnemonic 284 && Util.equals(ordering, loc.ordering) 285 && Util.equals(imageStyle, loc.imageStyle); 286 } 287 return false; 288 } 289 290 293 public int hashCode() { 294 return path.hashCode() + Util.hashCode(imageStyle) 295 + Util.hashCode(ordering); 296 } 297 } 298 | Popular Tags |