1 18 package org.apache.batik.svggen; 19 20 import java.awt.*; 21 import java.awt.geom.*; 22 23 31 public class Gradient implements Painter { 32 public void paint(Graphics2D g) { 33 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 34 RenderingHints.VALUE_ANTIALIAS_ON); 35 36 java.awt.geom.AffineTransform defaultTransform = g.getTransform(); 37 Color labelColor = Color.black; 38 39 GeneralPath crossHair = new GeneralPath(); 43 crossHair.moveTo(-5, 0); 44 crossHair.lineTo(5, 0); 45 crossHair.moveTo(0, -5); 46 crossHair.lineTo(0, 5); 47 48 java.awt.GradientPaint gradient = new java.awt.GradientPaint (30, 40, Color.red, 53 30, 120, Color.yellow); 54 g.setPaint(labelColor); 55 g.drawString("Simple vertical gradient", 10, 20); 56 g.setPaint(gradient); 57 g.fillRect(10, 30, 100, 100); 58 g.setPaint(labelColor); 59 g.translate(30, 40); 60 g.draw(crossHair); 61 g.setTransform(defaultTransform); 62 g.translate(30, 120); 63 g.draw(crossHair); 64 65 g.setTransform(defaultTransform); 66 g.translate(0, 140); 67 68 java.awt.GradientPaint nonCyclicGradient = new java.awt.GradientPaint (0, 0, Color.red, 72 20, 0, Color.yellow); 73 java.awt.GradientPaint cyclicGradient = new java.awt.GradientPaint (0, 0, Color.red, 74 20, 0, Color.yellow, true); 75 76 g.setPaint(labelColor); 77 g.drawString("Non Cyclic / Cyclic Gradients", 10, 20); 78 79 g.translate(10, 30); 80 81 g.setPaint(nonCyclicGradient); 82 g.fillRect(0, 0, 100, 30); 83 84 g.translate(0, 30); 85 g.setPaint(cyclicGradient); 86 g.fillRect(0, 0, 100, 30); 87 88 g.setPaint(labelColor); 89 g.drawLine(0, 0, 100, 0); 90 91 g.setTransform(defaultTransform); 92 g.translate(0, 240); 93 94 g.setPaint(labelColor); 98 g.drawString("Sheared GradientPaint", 10, 20); 99 g.translate(10, 25); 100 101 java.awt.GradientPaint shearedGradient = new java.awt.GradientPaint (0, 0, Color.red, 102 100, 0, Color.yellow); 103 g.setPaint(shearedGradient); 104 g.shear(0.5, 0); 105 106 g.fillRect(0, 0, 100, 40); 107 108 g.setTransform(defaultTransform); 109 g.translate(0, 320); 110 111 g.setPaint(labelColor); 112 g.drawString("Opacity in stop color", 10, 20); 113 114 java.awt.GradientPaint transparentGradient = new java.awt.GradientPaint (10, 30, new Color(255, 0, 0, 0), 115 110, 30, Color.yellow); 116 117 g.setPaint(transparentGradient); 118 g.fillRect(10, 30, 100, 30); 119 } 120 } 121 | Popular Tags |