01: /*
02: * @(#)QuaquaColorPreviewPanel.java 1.2 2005-12-18
03: *
04: * Copyright (c) 2005 Werner Randelshofer
05: * Staldenmattweg 2, Immensee, CH-6405, Switzerland.
06: * All rights reserved.
07: *
08: * This software is the confidential and proprietary information of
09: * Werner Randelshofer. ("Confidential Information"). You shall not
10: * disclose such Confidential Information and shall use it only in
11: * accordance with the terms of the license agreement you entered into
12: * with Werner Randelshofer.
13: */
14:
15: package contrib.ch.randelshofer.quaqua.colorchooser;
16:
17: import java.awt.*;
18: import java.awt.event.*;
19: import javax.swing.*;
20: import javax.swing.plaf.*;
21:
22: import contrib.ch.randelshofer.quaqua.*;
23:
24: /**
25: * QuaquaColorPreviewPanel.
26: *
27: * @author Werner Randelshofer
28: * @version 1.2 2005-12-18 Tweaked insets.
29: * <br>1.1 2005-09-20 Added tooltip. This is not what the native
30: * NSColorPicker does, but it is very useful.
31: * <br>1.0 30 March 2005 Created.
32: */
33: public class QuaquaColorPreviewPanel extends JPanel implements
34: UIResource {
35: private final static Color previewBorderColor = new Color(0x949494);
36: private final static Color previewBackgroundColor = new Color(
37: 0xffffff);
38:
39: /** Creates new form. */
40: public QuaquaColorPreviewPanel() {
41: initComponents();
42: setBorder(new VisualMargin(3, 0, 3, 0));
43: setToolTipText("on"); // set dummy text, to switch tooltip on
44: }
45:
46: public void paintComponent(Graphics g) {
47: Insets insets = getInsets();
48: int x = insets.left;
49: int y = insets.top;
50: int w = getWidth() - insets.left - insets.right;
51: int h = getHeight() - insets.top - insets.bottom;
52: g.setColor(previewBackgroundColor);
53: g.fillRect(x + 1, y + 1, w - 2, h - 2);
54: g.setColor(previewBorderColor);
55: g.drawRect(x, y, w - 1, h - 1);
56: g.setColor(getForeground());
57: g.fillRect(x + 2, y + 2, w - 4, h - 4);
58: }
59:
60: public String getToolTipText(MouseEvent evt) {
61: Color color = getForeground();
62: return (color == null) ? null : color.getRed() + ", "
63: + color.getGreen() + ", " + color.getBlue();
64: }
65:
66: /** This method is called from within the constructor to
67: * initialize the form.
68: * WARNING: Do NOT modify this code. The content of this method is
69: * always regenerated by the Form Editor.
70: */
71: private void initComponents() {//GEN-BEGIN:initComponents
72:
73: setLayout(new java.awt.BorderLayout());
74:
75: setPreferredSize(new java.awt.Dimension(26, 26));
76: }//GEN-END:initComponents
77:
78: // Variables declaration - do not modify//GEN-BEGIN:variables
79: // End of variables declaration//GEN-END:variables
80:
81: }
|