1 package org.catacomb.graph.gui; 2 3 import org.catacomb.report.E; 4 5 import java.awt.BasicStroke; 6 7 public class DisplayStrokes { 8 9 10 String[] styleNames; 11 int nsn; 12 13 double[] widths; 14 int nw; 15 16 17 BasicStroke[][] strokes; 18 19 public DisplayStrokes(String[] sn, double[] w) { 20 styleNames = sn; 21 widths = w; 22 nsn = styleNames.length; 23 nw = widths.length; 24 strokes = new BasicStroke[nsn][nw]; 25 } 26 27 28 public BasicStroke getStroke(int ilin, int iwin) { 29 int il = ilin; 30 int iw = iwin; 31 if (il >= nsn) { 32 il = nsn-1; 33 } 34 if (iw >= nw) { 35 iw = nw-1; 36 } 37 38 BasicStroke ret = strokes[il][iw]; 39 if (ret == null) { 40 ret = makeStroke(styleNames[il], widths[iw]); 41 strokes[il][iw] = ret; 42 } 43 return ret; 44 } 45 46 47 48 private BasicStroke makeStroke(String snm, double w) { 49 float fw = (float)w; 50 BasicStroke ret = null; 51 52 if (snm.equals("solid")) { 53 ret = new BasicStroke(fw); 54 55 } else if (snm.equals("dotted")) { 56 float[] dashes= {2, 2, 2, 2}; 57 ret = new BasicStroke(fw, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 58 10.f, dashes, 0.f); 59 60 } else if (snm.equals("short dash")) { 61 float[] dashes= {6, 6, 6, 6}; 62 ret = new BasicStroke(fw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 63 10.f, dashes, 0.f); 64 65 } else if (snm.equals("long dash")) { 66 float[] dashes= {8, 4, 8, 4}; 67 ret = new BasicStroke(fw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 68 10.f, dashes, 0.f); 69 70 71 } else if (snm.equals("dot-dash")) { 72 float[] dashes= {2, 2, 8, 2}; 73 ret = new BasicStroke(fw, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 74 10.f, dashes, 0.f); 75 76 77 } else { 78 E.warning("unrecognized line stype " + snm); 79 ret = new BasicStroke(fw); 80 } 81 82 return ret; 83 } 84 85 86 }