1 19 package jcckit.graphic; 20 21 import jcckit.util.ConfigParameters; 22 import jcckit.util.FactoryException; 23 24 43 public class Anchor { 44 45 public static final Anchor LEFT_BOTTOM = new Anchor(0), 46 CENTER = new Anchor(1), 47 RIGHT_TOP = new Anchor(2); 48 private static final String LEFT_VALUE = "left", 49 RIGHT_VALUE = "right", 50 CENTER_VALUE = "center", 51 TOP_VALUE = "top", 52 BOTTOM_VALUE = "bottom"; 53 54 68 public static Anchor getHorizontalAnchor(ConfigParameters config, String key, 69 Anchor defaultValue) { 70 Anchor result = defaultValue; 71 String anchor = config.get(key, null); 72 if (anchor != null) { 73 if (anchor.equals(LEFT_VALUE)) { 74 result = Anchor.LEFT_BOTTOM; 75 } else if (anchor.equals(CENTER_VALUE)) { 76 result = Anchor.CENTER; 77 } else if (anchor.equals(RIGHT_VALUE)) { 78 result = Anchor.RIGHT_TOP; 79 } else { 80 throw new FactoryException(config, key, "Invalid horizontal anchor."); 81 } 82 } 83 return result; 84 } 85 86 100 public static Anchor getVerticalAnchor(ConfigParameters config, String key, 101 Anchor defaultValue) { 102 Anchor result = defaultValue; 103 String anchor = config.get(key, null); 104 if (anchor != null) { 105 if (anchor.equals(BOTTOM_VALUE)) { 106 result = Anchor.LEFT_BOTTOM; 107 } else if (anchor.equals(CENTER_VALUE)) { 108 result = Anchor.CENTER; 109 } else if (anchor.equals(TOP_VALUE)) { 110 result = Anchor.RIGHT_TOP; 111 } else { 112 throw new FactoryException(config, key, "Invalid vertcal anchor."); 113 } 114 } 115 return result; 116 } 117 118 private final int _factor; 119 120 private Anchor(int factor) { 121 _factor = factor; 122 } 123 124 125 public int getFactor() { 126 return _factor; 127 } 128 } 129 130 | Popular Tags |