01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.ui.laf;
24:
25: import java.awt.Color;
26: import java.awt.Component;
27: import java.awt.Dimension;
28: import java.awt.GradientPaint;
29: import java.awt.Graphics;
30: import java.awt.Graphics2D;
31: import java.awt.Rectangle;
32: import java.awt.RenderingHints;
33: import java.awt.geom.Ellipse2D;
34:
35: import javax.swing.Icon;
36:
37: /**
38: * Simple 3-D Color LED Icon that is rendered at runtime.
39: * <p>
40: *
41: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
42: * @version 1.0
43: */
44: public class ColorLedIcon implements Icon {
45:
46: private Color color = null;
47: private int xMargin = 0;
48: private int yMargin = 0;
49:
50: public ColorLedIcon(Color color, int xMargin, int yMargin) {
51:
52: this .color = color;
53: this .xMargin = xMargin;
54: this .yMargin = yMargin;
55: }
56:
57: public int getIconHeight() {
58:
59: return 16;
60: }
61:
62: public int getIconWidth() {
63:
64: return 16;
65: }
66:
67: public void paintIcon(Component c, Graphics g1, int x, int y) {
68:
69: Graphics2D g = (Graphics2D) g1;
70:
71: Dimension size = new Dimension(getIconWidth(), getIconHeight());
72: int sphereSize = size.width <= size.height ? size.width
73: : size.height;
74: Ellipse2D sphere = new Ellipse2D.Float(0, 0, sphereSize,
75: sphereSize);
76: Rectangle gradientRect = new Rectangle(-sphereSize / 2,
77: -sphereSize / 2, 3 * sphereSize / 2, 3 * sphereSize / 2);
78: float x1 = gradientRect.width / 2f;
79: float y1 = gradientRect.height / 2f;
80: GradientPaint sphereFilling = new GradientPaint(0f, y1, color,
81: x1, 0f, Color.WHITE);
82: g.translate(xMargin, yMargin);
83: g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
84: RenderingHints.VALUE_ANTIALIAS_ON);
85: g.setPaint(sphereFilling);
86: g.fill(sphere);
87: }
88: }
|