KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)MotifToggleButtonUI.java 1.21 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 java.awt.*;
11 import java.awt.event.*;
12
13 import javax.swing.*;
14 import javax.swing.border.*;
15 import javax.swing.plaf.*;
16 import javax.swing.plaf.basic.*;
17
18
19 /**
20  * BasicToggleButton implementation
21  * <p>
22  * <strong>Warning:</strong>
23  * Serialized objects of this class will not be compatible with
24  * future Swing releases. The current serialization support is appropriate
25  * for short term storage or RMI between applications running the same
26  * version of Swing. A future release of Swing will provide support for
27  * long term persistence.
28  *
29  * @version 1.21 12/19/03
30  * @author Rich Schiavi
31  */

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

68     protected Color getSelectColor() {
69     return selectColor;
70     }
71     
72     // ********************************
73
// Paint Methods
74
// ********************************
75
protected void paintButtonPressed(Graphics g, AbstractButton b) {
76         if (b.isContentAreaFilled()) {
77         Color oldColor = g.getColor();
78         Dimension size = b.getSize();
79         Insets insets = b.getInsets();
80         Insets margin = b.getMargin();
81
82         if(b.getBackground() instanceof UIResource) {
83         g.setColor(getSelectColor());
84         }
85         g.fillRect(insets.left - margin.left,
86                insets.top - margin.top,
87                size.width - (insets.left-margin.left) - (insets.right - margin.right),
88                size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
89         g.setColor(oldColor);
90     }
91     }
92     
93     public Insets getInsets(JComponent c) {
94     Border border = c.getBorder();
95     Insets i = border != null? border.getBorderInsets(c) : new Insets(0,0,0,0);
96     return i;
97     }
98
99 }
100
101
102
Popular Tags