01: import java.awt.*; 02: import java.io.*; 03: 04: /** 05: This class defines line styles of various shapes. 06: */ 07: public class LineStyle implements Serializable 08: { 09: private LineStyle(String name) { this.name = name; } 10: 11: /** 12: Gets a stroke with which to draw this line style. 13: @return the stroke object that strokes this line style 14: */ 15: public Stroke getStroke() 16: { 17: if (this == DOTTED) return DOTTED_STROKE; 18: if (this == SOLID) return SOLID_STROKE; 19: return null; 20: } 21: 22: protected Object readResolve() throws ObjectStreamException 23: { 24: if (name.equals("SOLID")) return LineStyle.SOLID; 25: else if (name.equals("DOTTED")) return LineStyle.DOTTED; 26: else return null; 27: } 28: 29: private String name; 30: 31: private static Stroke SOLID_STROKE = new BasicStroke(); 32: private static Stroke DOTTED_STROKE = new BasicStroke( 33: 1.0f, 34: BasicStroke.CAP_SQUARE, 35: BasicStroke.JOIN_MITER, 36: 10.0f, 37: new float[] { 3.0f, 3.0f }, 38: 0.0f); 39: 40: public static final LineStyle SOLID 41: = new LineStyle("SOLID"); 42: public static final LineStyle DOTTED 43: = new LineStyle("DOTTED"); 44: }