| <test title="BasicStroke Testing"> |
| <description> |
| This test validates convertion of BasicStroke |
| </description> |
| <description> |
| The test draws a a polygon with a sharp angle with different strokes |
| </description> |
| <javaCode> |
| <![CDATA[ |
| g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
| RenderingHints.VALUE_ANTIALIAS_ON); |
| |
| /* |
| * Strokes of varying width |
| */ |
| BasicStroke strokesWidth[] = { |
| new BasicStroke(2.f), |
| new BasicStroke(4.f), |
| new BasicStroke(8.f), |
| new BasicStroke(16.f) |
| }; |
| |
| |
| /* |
| * Strokes of varying termination styles |
| */ |
| BasicStroke strokesCap[] = { |
| new BasicStroke(15.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL), // No decoration |
| new BasicStroke(15.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL), // Square end |
| new BasicStroke(15.f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL), // Rounded end |
| }; |
| |
| /* |
| * Strokes of varying segment connection styles |
| */ |
| BasicStroke strokesJoin[] = { |
| new BasicStroke(10.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL), // Connected with a straight segment |
| new BasicStroke(10.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER), // Extend outlines until they meet |
| new BasicStroke(10.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND), // Round of corner. |
| }; |
| /* |
| * Strokes of varying miterlimits |
| */ |
| BasicStroke strokesMiter[] = { |
| new BasicStroke(6.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1), // Actually cuts of all angles |
| new BasicStroke(6.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 2f), // Cuts off angles less than 60degrees |
| new BasicStroke(6.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10f), // Cuts off angles less than 11 degrees |
| }; |
| |
| /* |
| * Srokes with varying dash styles |
| */ |
| BasicStroke strokesDash[] = { |
| new BasicStroke(8.f, |
| BasicStroke.CAP_BUTT, |
| BasicStroke.JOIN_BEVEL, |
| 8.f, |
| new float[]{ 6.f, 6.f }, |
| 0.f), |
| |
| new BasicStroke(8.f, |
| BasicStroke.CAP_BUTT, |
| BasicStroke.JOIN_BEVEL, |
| 8.f, |
| new float[]{ 10.f, 4.f }, |
| 0.f), |
| |
| new BasicStroke(8.f, |
| BasicStroke.CAP_BUTT, |
| BasicStroke.JOIN_BEVEL, |
| 8.f, |
| new float[]{ 4.f, 4.f, 10.f, 4.f }, |
| 0.f), |
| |
| new BasicStroke(8.f, |
| BasicStroke.CAP_BUTT, |
| BasicStroke.JOIN_BEVEL, |
| 8.f, |
| new float[]{ 4.f, 4.f, 10.f, 4.f }, |
| 4.f) |
| }; |
| |
| AffineTransform defaultTransform = g.getTransform(); |
| |
| // Varying width |
| g.setPaint(Color.black); |
| g.drawString("Varying width", 10, 10); |
| for(int i=0; i<strokesWidth.length; i++){ |
| g.setStroke(strokesWidth[i]); |
| g.drawLine(10, 30, 10, 80); |
| g.translate(20, 0); |
| } |
| |
| // Varying end caps |
| g.setTransform(defaultTransform); |
| g.translate(0, 120); |
| g.drawString("Varying end caps", 10, 10); |
| for(int i=0; i<strokesCap.length; i++){ |
| g.setStroke(strokesCap[i]); |
| g.drawLine(15, 30, 15, 80); |
| g.translate(30, 0); |
| } |
| |
| // Varying line joins |
| GeneralPath needle = new GeneralPath(); |
| needle.moveTo(0, 60); |
| needle.lineTo(10, 20); |
| needle.lineTo(20, 60); |
| g.setTransform(defaultTransform); |
| g.translate(0, 240); |
| g.drawString("Varying line joins", 10, 10); |
| g.translate(20, 20); |
| for(int i=0; i<strokesJoin.length; i++){ |
| g.setStroke(strokesJoin[i]); |
| g.draw(needle); |
| g.translate(35, 0); |
| } |
| |
| // Varying miter limit |
| g.setTransform(defaultTransform); |
| g.translate(150, 120); |
| GeneralPath miterShape = new GeneralPath(); |
| miterShape.moveTo(0, 0); |
| miterShape.lineTo(30, 0); |
| miterShape.lineTo(30, 60); // 90 degree elbow |
| miterShape.lineTo(0, 30); // 45 degree elbow. |
| g.drawString("Varying miter limit", 10, 10); |
| g.translate(10, 30); |
| for(int i=0; i<strokesMiter.length; i++){ |
| g.setStroke(strokesMiter[i]); |
| g.draw(miterShape); |
| g.translate(40, 0); |
| } |
| |
| // Varing dashing patterns |
| g.setTransform(defaultTransform); |
| g.translate(150, 0); |
| g.drawString("Varying dash patterns", 10, 10); |
| g.translate(20, 0); |
| for(int i=0; i<strokesDash.length; i++){ |
| g.setStroke(strokesDash[i]); |
| g.drawLine(10, 20, 10, 80); |
| g.translate(20, 0); |
| } |
| |
| |
| ]]> |
| </javaCode> |
| </test> |