KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > motif > MotifButtonUI


1 /*
2  * @(#)MotifButtonUI.java 1.26 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7  
8 package com.sun.java.swing.plaf.motif;
9
10 import javax.swing.*;
11 import javax.swing.border.*;
12 import javax.swing.plaf.basic.*;
13 import java.awt.*;
14 import java.awt.event.*;
15 import javax.swing.plaf.*;
16
17 /**
18  * MotifButton implementation
19  * <p>
20  * <strong>Warning:</strong>
21  * Serialized objects of this class will not be compatible with
22  * future Swing releases. The current serialization support is appropriate
23  * for short term storage or RMI between applications running the same
24  * version of Swing. A future release of Swing will provide support for
25  * long term persistence.
26  *
27  * @version 1.26 12/19/03
28  * @author Rich Schiavi
29  */

30 public class MotifButtonUI extends BasicButtonUI {
31
32     private final static MotifButtonUI motifButtonUI = new MotifButtonUI();
33
34     protected Color selectColor;
35
36     private boolean defaults_initialized = false;
37     
38     // ********************************
39
// Create PLAF
40
// ********************************
41
public static ComponentUI createUI(JComponent c){
42     return motifButtonUI;
43     }
44     
45     // ********************************
46
// Create Listeners
47
// ********************************
48
protected BasicButtonListener createButtonListener(AbstractButton b){
49     return new MotifButtonListener(b);
50     }
51
52     // ********************************
53
// Install Defaults
54
// ********************************
55
public void installDefaults(AbstractButton b) {
56     super.installDefaults(b);
57     if(!defaults_initialized) {
58         selectColor = UIManager.getColor(getPropertyPrefix() + "select");
59         defaults_initialized = true;
60     }
61         LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
62     }
63
64     protected void uninstallDefaults(AbstractButton b) {
65     super.uninstallDefaults(b);
66     defaults_initialized = false;
67     }
68     
69     // ********************************
70
// Default Accessors
71
// ********************************
72

73     protected Color getSelectColor() {
74     return selectColor;
75     }
76     
77     // ********************************
78
// Paint Methods
79
// ********************************
80
public void paint(Graphics g, JComponent c) {
81         fillContentArea( g, (AbstractButton)c , c.getBackground() );
82     super.paint(g,c);
83     }
84
85     // Overridden to ensure we don't paint icon over button borders.
86
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
87         Shape oldClip = g.getClip();
88         Rectangle newClip =
89             AbstractBorder.getInteriorRectangle(c, c.getBorder(), 0, 0,
90                                                 c.getWidth(), c.getHeight());
91
92         Rectangle r = oldClip.getBounds();
93         newClip =
94             SwingUtilities.computeIntersection(r.x, r.y, r.width, r.height,
95                                                newClip);
96         g.setClip(newClip);
97         super.paintIcon(g, c, iconRect);
98         g.setClip(oldClip);
99     }
100
101     protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
102     // focus painting is handled by the border
103
}
104     
105     protected void paintButtonPressed(Graphics g, AbstractButton b) {
106
107         fillContentArea( g, b , selectColor );
108
109     }
110
111     protected void fillContentArea( Graphics g, AbstractButton b, Color fillColor) {
112
113         if (b.isContentAreaFilled()) {
114         Insets margin = b.getMargin();
115         Insets insets = b.getInsets();
116         Dimension size = b.getSize();
117         g.setColor(fillColor);
118         g.fillRect(insets.left - margin.left,
119                insets.top - margin.top,
120                size.width - (insets.left-margin.left) - (insets.right - margin.right),
121                size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
122     }
123     }
124 }
125
126
127
Popular Tags