1 /*
2 * soapUI, copyright (C) 2004-2007 eviware.com
3 *
4 * soapUI is free software; you can redistribute it and/or modify it under the
5 * terms of version 2.1 of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
7 *
8 * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 * 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 {
25 // ------------------------------ FIELDS ------------------------------
26
27 private Color start;
28 private Color end;
29
30 // --------------------------- CONSTRUCTORS ---------------------------
31
32 public GradientLabel( String text )
33 {
34 super( text );
35
36 start = Color.LIGHT_GRAY;
37 end = getBackground();
38 }
39
40 public GradientLabel( String text, Color start, Color end )
41 {
42 super( text );
43 this.start = start;
44 this.end = end;
45 }
46
47 // -------------------------- OTHER METHODS --------------------------
48
49 public void paint( Graphics g )
50 {
51 int width = getWidth();
52 int height = getHeight();
53
54 // Create the gradient paint
55 GradientPaint paint = new GradientPaint( 0, 0, start, width, height, end, true );
56
57 // we need to cast to Graphics2D for this operation
58 Graphics2D g2d = (Graphics2D) g;
59
60 // save the old paint
61 Paint oldPaint = g2d.getPaint();
62
63 // set the paint to use for this operation
64 g2d.setPaint( paint );
65
66 // fill the background using the paint
67 g2d.fillRect( 0, 0, width, height );
68
69 // restore the original paint
70 g2d.setPaint( oldPaint );
71
72 super.paint( g );
73 }
74 }
75