1 43 44 package org.jfree.ui; 45 46 import java.awt.Color ; 47 import java.awt.Dimension ; 48 import java.awt.Graphics ; 49 import java.awt.Graphics2D ; 50 import java.awt.Insets ; 51 import java.awt.Paint ; 52 import java.awt.geom.Rectangle2D ; 53 54 import javax.swing.JComponent ; 55 56 61 public class PaintSample extends JComponent { 62 63 64 private Paint paint; 65 66 67 private Dimension preferredSize; 68 69 74 public PaintSample(final Paint paint) { 75 this.paint = paint; 76 this.preferredSize = new Dimension (80, 12); 77 } 78 79 84 public Paint getPaint() { 85 return this.paint; 86 } 87 88 93 public void setPaint(final Paint paint) { 94 this.paint = paint; 95 repaint(); 96 } 97 98 103 public Dimension getPreferredSize() { 104 return this.preferredSize; 105 } 106 107 112 public void paintComponent(final Graphics g) { 113 114 final Graphics2D g2 = (Graphics2D ) g; 115 final Dimension size = getSize(); 116 final Insets insets = getInsets(); 117 final double xx = insets.left; 118 final double yy = insets.top; 119 final double ww = size.getWidth() - insets.left - insets.right - 1; 120 final double hh = size.getHeight() - insets.top - insets.bottom - 1; 121 final Rectangle2D area = new Rectangle2D.Double (xx, yy, ww, hh); 122 g2.setPaint(this.paint); 123 g2.fill(area); 124 g2.setPaint(Color.black); 125 g2.draw(area); 126 127 } 128 129 } 130 | Popular Tags |