01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.soapui.support.swing;
14:
15: import java.awt.Color;
16: import java.awt.GradientPaint;
17: import java.awt.Graphics;
18: import java.awt.Graphics2D;
19: import java.awt.Paint;
20:
21: import javax.swing.JLabel;
22:
23: public class GradientLabel extends JLabel {
24: // ------------------------------ FIELDS ------------------------------
25:
26: private Color start;
27: private Color end;
28:
29: // --------------------------- CONSTRUCTORS ---------------------------
30:
31: public GradientLabel(String text) {
32: super (text);
33:
34: start = Color.LIGHT_GRAY;
35: end = getBackground();
36: }
37:
38: public GradientLabel(String text, Color start, Color end) {
39: super (text);
40: this .start = start;
41: this .end = end;
42: }
43:
44: // -------------------------- OTHER METHODS --------------------------
45:
46: public void paint(Graphics g) {
47: int width = getWidth();
48: int height = getHeight();
49:
50: // Create the gradient paint
51: GradientPaint paint = new GradientPaint(0, 0, start, width,
52: height, end, true);
53:
54: // we need to cast to Graphics2D for this operation
55: Graphics2D g2d = (Graphics2D) g;
56:
57: // save the old paint
58: Paint oldPaint = g2d.getPaint();
59:
60: // set the paint to use for this operation
61: g2d.setPaint(paint);
62:
63: // fill the background using the paint
64: g2d.fillRect(0, 0, width, height);
65:
66: // restore the original paint
67: g2d.setPaint(oldPaint);
68:
69: super.paint(g);
70: }
71: }
|