1 package jimm.datavision.field; 2 import jimm.util.XMLWriter; 3 import java.util.Observable ; 4 5 12 public class BorderEdge extends Observable implements Cloneable { 13 14 15 public static final int STYLE_LINE = 0; 16 17 public static final int STYLE_DASH = 1; 18 19 public static final int STYLE_DOT = 2; 20 21 public static final int DEFAULT_STYLE = STYLE_LINE; 22 public static final int DEFAULT_NUMBER = 1; 23 public static final double DEFAULT_THICKNESS = 1.0; 24 25 protected int style; protected double thickness; protected int number; 28 29 39 public static int styleFromString(String styleStr) { 40 if (styleStr == null || styleStr.length() == 0) return DEFAULT_STYLE; 42 43 styleStr = styleStr.toLowerCase(); 44 int style = DEFAULT_STYLE; 45 if (styleStr.equals("line")) style = STYLE_LINE; 46 else if (styleStr.equals("dash")) style = STYLE_DASH; 47 else if (styleStr.equals("dot")) style = STYLE_DOT; 48 49 return style; 50 } 51 52 56 public BorderEdge() { 57 this(DEFAULT_STYLE, DEFAULT_THICKNESS, DEFAULT_NUMBER); 58 } 59 60 66 public BorderEdge(int style) { 67 this(style, DEFAULT_THICKNESS, DEFAULT_NUMBER); 68 } 69 70 77 public BorderEdge(int style, double thickness) { 78 this(style, thickness, DEFAULT_NUMBER); 79 } 80 81 89 public BorderEdge(int style, double thickness, int number) { 90 this.style = style; 91 this.thickness = thickness; 92 this.number = number; 93 } 94 95 98 public Object clone() { 99 BorderEdge be = new BorderEdge(style, thickness, number); 100 return be; 101 } 102 103 public boolean equals(Object obj) { 104 if (obj == null || !(obj instanceof BorderEdge)) return false; 105 if (obj == this) return true; 106 107 BorderEdge be = (BorderEdge)obj; 108 return number == be.number 109 && thickness == be.thickness 110 && style == be.style; 111 } 112 113 public int hashCode() { 114 return style + number * 10 + (int)(thickness * 1000); 115 } 116 117 122 public int getStyle() { return style; } 123 124 129 public void setStyle(int newStyle) { 130 if (style != newStyle) { 131 style = newStyle; 132 setChanged(); 133 notifyObservers(); 134 } 135 } 136 137 142 public double getThickness() { return thickness; } 143 144 149 public void setThickness(double newThickness) { 150 if (thickness != newThickness) { 151 thickness = newThickness; 152 setChanged(); 153 notifyObservers(); 154 } 155 } 156 157 162 public int getNumber() { return number; } 163 164 169 public void setNumber(int newNumber) { 170 if (number != newNumber) { 171 number = newNumber; 172 setChanged(); 173 notifyObservers(); 174 } 175 } 176 177 184 public void writeXML(XMLWriter out, String location) { 185 String styleStr = null; 186 if (style != DEFAULT_STYLE) { 187 switch (style) { 188 case STYLE_LINE: styleStr = "line"; break; 189 case STYLE_DASH: styleStr = "dash"; break; 190 case STYLE_DOT: styleStr = "dot"; break; 191 } 192 } 193 194 out.startElement("edge"); 195 out.attr("location", location); 196 if (number != DEFAULT_NUMBER) 197 out.attr("number", number); 198 if (thickness != DEFAULT_THICKNESS) 199 out.attr("thickness", thickness); 200 if (styleStr != null) 201 out.attr("style", styleStr); 202 out.endElement(); 203 } 204 205 public String toString() { 206 return "BorderEdge[style=" + style + ", thickness=" + thickness 207 + ", number=" + number + "]"; 208 } 209 210 } 211 | Popular Tags |