1 18 package org.apache.batik.svggen; 19 20 import java.awt.*; 21 import java.awt.geom.*; 22 23 30 public class BStroke implements Painter { 31 public void paint(Graphics2D g) { 32 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 33 RenderingHints.VALUE_ANTIALIAS_ON); 34 35 38 java.awt.BasicStroke strokesWidth[] = { 39 new java.awt.BasicStroke (2.f), 40 new java.awt.BasicStroke (4.f), 41 new java.awt.BasicStroke (8.f), 42 new java.awt.BasicStroke (16.f) 43 }; 44 45 46 49 java.awt.BasicStroke strokesCap[] = { 50 new java.awt.BasicStroke (15.f, java.awt.BasicStroke.CAP_BUTT, java.awt.BasicStroke.JOIN_BEVEL), new java.awt.BasicStroke (15.f, java.awt.BasicStroke.CAP_SQUARE, java.awt.BasicStroke.JOIN_BEVEL), new java.awt.BasicStroke (15.f, java.awt.BasicStroke.CAP_ROUND, java.awt.BasicStroke.JOIN_BEVEL), }; 54 55 58 java.awt.BasicStroke strokesJoin[] = { 59 new java.awt.BasicStroke (10.f, java.awt.BasicStroke.CAP_SQUARE, java.awt.BasicStroke.JOIN_BEVEL), new java.awt.BasicStroke (10.f, java.awt.BasicStroke.CAP_SQUARE, java.awt.BasicStroke.JOIN_MITER), new java.awt.BasicStroke (10.f, java.awt.BasicStroke.CAP_SQUARE, java.awt.BasicStroke.JOIN_ROUND), }; 63 66 java.awt.BasicStroke strokesMiter[] = { 67 new java.awt.BasicStroke (6.f, java.awt.BasicStroke.CAP_SQUARE, java.awt.BasicStroke.JOIN_MITER, 1), new java.awt.BasicStroke (6.f, java.awt.BasicStroke.CAP_SQUARE, java.awt.BasicStroke.JOIN_MITER, 2f), new java.awt.BasicStroke (6.f, java.awt.BasicStroke.CAP_SQUARE, java.awt.BasicStroke.JOIN_MITER, 10f), }; 71 72 75 java.awt.BasicStroke strokesDash[] = { 76 new java.awt.BasicStroke (8.f, 77 java.awt.BasicStroke.CAP_BUTT, 78 java.awt.BasicStroke.JOIN_BEVEL, 79 8.f, 80 new float[]{ 6.f, 6.f }, 81 0.f), 82 83 new java.awt.BasicStroke (8.f, 84 java.awt.BasicStroke.CAP_BUTT, 85 java.awt.BasicStroke.JOIN_BEVEL, 86 8.f, 87 new float[]{ 10.f, 4.f }, 88 0.f), 89 90 new java.awt.BasicStroke (8.f, 91 java.awt.BasicStroke.CAP_BUTT, 92 java.awt.BasicStroke.JOIN_BEVEL, 93 8.f, 94 new float[]{ 4.f, 4.f, 10.f, 4.f }, 95 0.f), 96 97 new java.awt.BasicStroke (8.f, 98 java.awt.BasicStroke.CAP_BUTT, 99 java.awt.BasicStroke.JOIN_BEVEL, 100 8.f, 101 new float[]{ 4.f, 4.f, 10.f, 4.f }, 102 4.f) 103 }; 104 105 java.awt.geom.AffineTransform defaultTransform = g.getTransform(); 106 107 g.setPaint(Color.black); 109 g.drawString("Varying width", 10, 10); 110 for(int i=0; i<strokesWidth.length; i++){ 111 g.setStroke(strokesWidth[i]); 112 g.drawLine(10, 30, 10, 80); 113 g.translate(20, 0); 114 } 115 116 g.setTransform(defaultTransform); 118 g.translate(0, 120); 119 g.drawString("Varying end caps", 10, 10); 120 for(int i=0; i<strokesCap.length; i++){ 121 g.setStroke(strokesCap[i]); 122 g.drawLine(15, 30, 15, 80); 123 g.translate(30, 0); 124 } 125 126 GeneralPath needle = new GeneralPath(); 128 needle.moveTo(0, 60); 129 needle.lineTo(10, 20); 130 needle.lineTo(20, 60); 131 g.setTransform(defaultTransform); 132 g.translate(0, 240); 133 g.drawString("Varying line joins", 10, 10); 134 g.translate(20, 20); 135 for(int i=0; i<strokesJoin.length; i++){ 136 g.setStroke(strokesJoin[i]); 137 g.draw(needle); 138 g.translate(35, 0); 139 } 140 141 g.setTransform(defaultTransform); 143 g.translate(150, 120); 144 GeneralPath miterShape = new GeneralPath(); 145 miterShape.moveTo(0, 0); 146 miterShape.lineTo(30, 0); 147 miterShape.lineTo(30, 60); miterShape.lineTo(0, 30); g.drawString("Varying miter limit", 10, 10); 150 g.translate(10, 30); 151 for(int i=0; i<strokesMiter.length; i++){ 152 g.setStroke(strokesMiter[i]); 153 g.draw(miterShape); 154 g.translate(40, 0); 155 } 156 157 g.setTransform(defaultTransform); 159 g.translate(150, 0); 160 g.drawString("Varying dash patterns", 10, 10); 161 g.translate(20, 0); 162 for(int i=0; i<strokesDash.length; i++){ 163 g.setStroke(strokesDash[i]); 164 g.drawLine(10, 20, 10, 80); 165 g.translate(20, 0); 166 } 167 168 } 169 } 170 | Popular Tags |