1 18 package org.apache.batik.svggen; 19 20 import java.awt.Graphics2D ; 21 import java.awt.RenderingHints ; 22 import java.awt.Font ; 23 24 32 public class Color1 implements Painter { 33 public void paint(Graphics2D g) { 34 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 35 RenderingHints.VALUE_ANTIALIAS_ON); 36 37 java.awt.geom.AffineTransform defaultTransform = g.getTransform(); 38 39 java.awt.Color labelColor = java.awt.Color.black; 41 42 java.awt.Color colorConstants[] = { java.awt.Color.black, 43 java.awt.Color.blue, 44 java.awt.Color.cyan, 45 java.awt.Color.darkGray, 46 java.awt.Color.gray, 47 java.awt.Color.green, 48 java.awt.Color.lightGray, 49 java.awt.Color.magenta, 50 java.awt.Color.orange, 51 java.awt.Color.pink, 52 java.awt.Color.red, 53 java.awt.Color.white, 54 java.awt.Color.yellow }; 55 56 String colorConstantStrings[] = { "black", 57 "blue", 58 "cyan", 59 "darkGray", 60 "gray", 61 "green", 62 "lightGray", 63 "magenta", 64 "orange", 65 "pink", 66 "red", 67 "white", 68 "yellow" }; 69 70 71 g.translate(20, 20); 72 g.setPaint(labelColor); 73 g.drawString("Color Constants", -5, 0); 74 g.translate(0, 20); 75 76 for(int i=0; i<colorConstants.length; i++){ 77 g.setPaint(labelColor); 78 g.drawString(colorConstantStrings[i], 10, 3); 79 g.setPaint(colorConstants[i]); 80 g.fillRect(-5, -5, 10, 10); 81 g.setPaint(labelColor); 82 g.drawRect(-5, -5, 10, 10); 83 g.translate(0, 20); 84 } 85 86 g.setTransform(defaultTransform); 87 g.translate(150, 20); 88 g.setColor(labelColor); 89 g.drawString("Various opacities", 0, 0); 90 g.translate(0, 10); 91 92 int opacitySteps = 20; 96 g.setPaint(new java.awt.Color (80, 255, 80)); 97 g.fillRect(0, 0, 40, 260); 98 int stepHeight = 260/opacitySteps; 99 Font defaultFont = g.getFont(); 100 Font opacityFont = new Font (defaultFont.getFamily(), 101 defaultFont.getStyle(), 102 (int)(defaultFont.getSize()*0.8)); 103 g.setFont(opacityFont); 104 105 for(int i=0; i<opacitySteps; i++){ 106 int opacity = ((i + 1)*255)/opacitySteps; 107 java.awt.Color color = new java.awt.Color (0, 0, 0, opacity); 108 g.setPaint(color); 109 g.fillRect(0, 0, 40, stepHeight); 110 111 g.setPaint(labelColor); 112 g.drawString("" + opacity, 50, stepHeight/2); 113 g.translate(0, stepHeight); 114 } 115 } 116 } 117 | Popular Tags |