1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
30
* (C) Copyright 2000-2004, by Object Refinery Limited.
32
* Original Author: David Gilbert (for Object Refinery Limited);
35
* $Id: PaintSample.java,v 1.3 2005/10/18 13:18:34 mungady Exp $
37
* Changes (from 26-Oct-2001)
38
* --------------------------
39
* 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
40
* 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
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;
54
import javax.swing.JComponent;
57
* A panel that displays a paint sample.
59
* @author David Gilbert
61
public class PaintSample extends JComponent {
66
/** The preferred size of the component. */
67
private Dimension preferredSize;
70
* Standard constructor - builds a paint sample.
72
* @param paint the paint to display.
74
public PaintSample(final Paint paint) {
76
this.preferredSize = new Dimension(80, 12);
80
* Returns the current Paint object being displayed in the panel.
84
public Paint getPaint() {
89
* Sets the Paint object being displayed in the panel.
91
* @param paint the paint.
93
public void setPaint(final Paint paint) {
99
* Returns the preferred size of the component.
101
* @return the preferred size.
103
public Dimension getPreferredSize() {
104
return this.preferredSize;
108
* Fills the component with the current Paint.
110
* @param g the graphics device.
112
public void paintComponent(final Graphics g) {
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);
124
g2.setPaint(Color.black);