2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.java.swing.plaf.motif;
|
|
27 |
|
4225
|
28 |
import sun.awt.AppContext;
|
|
29 |
|
2
|
30 |
import java.awt.*;
|
|
31 |
import java.awt.event.*;
|
|
32 |
|
|
33 |
import javax.swing.*;
|
|
34 |
import javax.swing.border.*;
|
|
35 |
import javax.swing.plaf.*;
|
|
36 |
import javax.swing.plaf.basic.*;
|
|
37 |
|
|
38 |
|
|
39 |
/**
|
|
40 |
* BasicToggleButton implementation
|
|
41 |
* <p>
|
|
42 |
* <strong>Warning:</strong>
|
|
43 |
* Serialized objects of this class will not be compatible with
|
|
44 |
* future Swing releases. The current serialization support is appropriate
|
|
45 |
* for short term storage or RMI between applications running the same
|
|
46 |
* version of Swing. A future release of Swing will provide support for
|
|
47 |
* long term persistence.
|
|
48 |
*
|
|
49 |
* @author Rich Schiavi
|
|
50 |
*/
|
|
51 |
public class MotifToggleButtonUI extends BasicToggleButtonUI
|
|
52 |
{
|
4225
|
53 |
private static final Object MOTIF_TOGGLE_BUTTON_UI_KEY = new Object();
|
2
|
54 |
|
|
55 |
protected Color selectColor;
|
|
56 |
|
|
57 |
private boolean defaults_initialized = false;
|
|
58 |
|
|
59 |
// ********************************
|
|
60 |
// Create PLAF
|
|
61 |
// ********************************
|
|
62 |
public static ComponentUI createUI(JComponent b) {
|
4225
|
63 |
AppContext appContext = AppContext.getAppContext();
|
|
64 |
MotifToggleButtonUI motifToggleButtonUI =
|
|
65 |
(MotifToggleButtonUI) appContext.get(MOTIF_TOGGLE_BUTTON_UI_KEY);
|
|
66 |
if (motifToggleButtonUI == null) {
|
|
67 |
motifToggleButtonUI = new MotifToggleButtonUI();
|
|
68 |
appContext.put(MOTIF_TOGGLE_BUTTON_UI_KEY, motifToggleButtonUI);
|
|
69 |
}
|
2
|
70 |
return motifToggleButtonUI;
|
|
71 |
}
|
|
72 |
|
|
73 |
// ********************************
|
|
74 |
// Install Defaults
|
|
75 |
// ********************************
|
|
76 |
public void installDefaults(AbstractButton b) {
|
|
77 |
super.installDefaults(b);
|
|
78 |
if(!defaults_initialized) {
|
|
79 |
selectColor = UIManager.getColor(getPropertyPrefix() + "select");
|
|
80 |
defaults_initialized = true;
|
|
81 |
}
|
|
82 |
LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
|
|
83 |
}
|
|
84 |
|
|
85 |
protected void uninstallDefaults(AbstractButton b) {
|
|
86 |
super.uninstallDefaults(b);
|
|
87 |
defaults_initialized = false;
|
|
88 |
}
|
|
89 |
|
|
90 |
// ********************************
|
|
91 |
// Default Accessors
|
|
92 |
// ********************************
|
|
93 |
|
|
94 |
protected Color getSelectColor() {
|
|
95 |
return selectColor;
|
|
96 |
}
|
|
97 |
|
|
98 |
// ********************************
|
|
99 |
// Paint Methods
|
|
100 |
// ********************************
|
|
101 |
protected void paintButtonPressed(Graphics g, AbstractButton b) {
|
|
102 |
if (b.isContentAreaFilled()) {
|
|
103 |
Color oldColor = g.getColor();
|
|
104 |
Dimension size = b.getSize();
|
|
105 |
Insets insets = b.getInsets();
|
|
106 |
Insets margin = b.getMargin();
|
|
107 |
|
|
108 |
if(b.getBackground() instanceof UIResource) {
|
|
109 |
g.setColor(getSelectColor());
|
|
110 |
}
|
|
111 |
g.fillRect(insets.left - margin.left,
|
|
112 |
insets.top - margin.top,
|
|
113 |
size.width - (insets.left-margin.left) - (insets.right - margin.right),
|
|
114 |
size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
|
|
115 |
g.setColor(oldColor);
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
public Insets getInsets(JComponent c) {
|
|
120 |
Border border = c.getBorder();
|
|
121 |
Insets i = border != null? border.getBorderInsets(c) : new Insets(0,0,0,0);
|
|
122 |
return i;
|
|
123 |
}
|
|
124 |
|
|
125 |
}
|