001: /*
002: * $Id: JGraphpadGradientPanel.java,v 1.1.1.1 2005/08/04 11:21:58 gaudenz Exp $
003: * Copyright (c) 2001-2005, Gaudenz Alder
004: *
005: * All rights reserved.
006: *
007: * See LICENSE file for license details. If you are unable to locate
008: * this file please contact info (at) jgraph (dot) com.
009: */
010: package com.jgraph.pad.dialog;
011:
012: import java.awt.Color;
013: import java.awt.GradientPaint;
014: import java.awt.Graphics;
015: import java.awt.Graphics2D;
016:
017: import javax.swing.JPanel;
018:
019: /**
020: * Panel with a gradient background.
021: */
022: public class JGraphpadGradientPanel extends JPanel {
023:
024: /**
025: * Start- and endcolor of the gradient fill.
026: */
027: protected Color startColor, endColor;
028:
029: /**
030: * Constructs a new gradient panel with no gradient.
031: */
032: public JGraphpadGradientPanel() {
033: this (null);
034: }
035:
036: /**
037: * Constructs a new gradient panel with the specified start- and no end
038: * color (background is used).
039: *
040: * @param startColor
041: * The start color to use for the gradient.
042: */
043: public JGraphpadGradientPanel(Color startColor) {
044: this (startColor, null);
045: }
046:
047: /**
048: * Constructs a new gradient panel with the specified start color and end
049: * colors. If start or end color is <code>null</code>, then the
050: * component's background color is used.
051: *
052: * @param startColor
053: * The start color to use for the gradient.
054: * @param endColor
055: * The end color to use for the gradient.
056: */
057: public JGraphpadGradientPanel(Color startColor, Color endColor) {
058: setOpaque(false);
059: if (startColor == null)
060: startColor = getBackground();
061: if (endColor == null)
062: endColor = getBackground();
063: this .startColor = startColor;
064: this .endColor = endColor;
065: }
066:
067: /**
068: * Paints a gradient background on <code>g</code>.
069: */
070: public void paint(Graphics g) {
071: Graphics2D g2d = (Graphics2D) g;
072: g2d.setPaint(new GradientPaint(0, 0, getStartColor(),
073: getWidth(), getHeight(), getEndColor(), true));
074: g2d.fillRect(0, 0, getWidth(), getHeight());
075: super .paint(g);
076: }
077:
078: /**
079: * Returns the endcolor for the gradient fill.
080: *
081: * @return Returns the end color.
082: */
083: public Color getEndColor() {
084: return endColor;
085: }
086:
087: /**
088: * Sets the endcolor for the gradient fill.
089: *
090: * @param endColor
091: * The end color of the gradient.
092: */
093: public void setEndColor(Color endColor) {
094: this .endColor = endColor;
095: }
096:
097: /**
098: * Returns the startcolor for the gradient fill.
099: *
100: * @return Returns the start color.
101: */
102: public Color getStartColor() {
103: return startColor;
104: }
105:
106: /**
107: * Sets the startcolor for the gradient fill.
108: *
109: * @param startColor
110: * The start color of the gradient.
111: */
112: public void setStartColor(Color startColor) {
113: this.startColor = startColor;
114: }
115:
116: }
|