blob: 43af4139dccb77579925c468aefcc6deb1a95ff0 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
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
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
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 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.java.swing.plaf.motif;
27
28import java.awt.*;
29import java.awt.event.*;
30
31import javax.swing.*;
32import javax.swing.border.*;
33import javax.swing.plaf.*;
34import javax.swing.plaf.basic.*;
35
36
37/**
38 * BasicToggleButton implementation
39 * <p>
40 * <strong>Warning:</strong>
41 * Serialized objects of this class will not be compatible with
42 * future Swing releases. The current serialization support is appropriate
43 * for short term storage or RMI between applications running the same
44 * version of Swing. A future release of Swing will provide support for
45 * long term persistence.
46 *
47 * @author Rich Schiavi
48 */
49public class MotifToggleButtonUI extends BasicToggleButtonUI
50{
51 private final static MotifToggleButtonUI motifToggleButtonUI = new MotifToggleButtonUI();
52
53 protected Color selectColor;
54
55 private boolean defaults_initialized = false;
56
57 // ********************************
58 // Create PLAF
59 // ********************************
60 public static ComponentUI createUI(JComponent b) {
61 return motifToggleButtonUI;
62 }
63
64 // ********************************
65 // Install Defaults
66 // ********************************
67 public void installDefaults(AbstractButton b) {
68 super.installDefaults(b);
69 if(!defaults_initialized) {
70 selectColor = UIManager.getColor(getPropertyPrefix() + "select");
71 defaults_initialized = true;
72 }
73 LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
74 }
75
76 protected void uninstallDefaults(AbstractButton b) {
77 super.uninstallDefaults(b);
78 defaults_initialized = false;
79 }
80
81 // ********************************
82 // Default Accessors
83 // ********************************
84
85 protected Color getSelectColor() {
86 return selectColor;
87 }
88
89 // ********************************
90 // Paint Methods
91 // ********************************
92 protected void paintButtonPressed(Graphics g, AbstractButton b) {
93 if (b.isContentAreaFilled()) {
94 Color oldColor = g.getColor();
95 Dimension size = b.getSize();
96 Insets insets = b.getInsets();
97 Insets margin = b.getMargin();
98
99 if(b.getBackground() instanceof UIResource) {
100 g.setColor(getSelectColor());
101 }
102 g.fillRect(insets.left - margin.left,
103 insets.top - margin.top,
104 size.width - (insets.left-margin.left) - (insets.right - margin.right),
105 size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
106 g.setColor(oldColor);
107 }
108 }
109
110 public Insets getInsets(JComponent c) {
111 Border border = c.getBorder();
112 Insets i = border != null? border.getBorderInsets(c) : new Insets(0,0,0,0);
113 return i;
114 }
115
116}