001: /*
002: * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.java.swing.plaf.motif;
027:
028: import javax.swing.*;
029: import javax.swing.border.*;
030: import javax.swing.plaf.basic.*;
031: import java.awt.*;
032: import java.awt.event.*;
033: import javax.swing.plaf.*;
034:
035: /**
036: * MotifButton implementation
037: * <p>
038: * <strong>Warning:</strong>
039: * Serialized objects of this class will not be compatible with
040: * future Swing releases. The current serialization support is appropriate
041: * for short term storage or RMI between applications running the same
042: * version of Swing. A future release of Swing will provide support for
043: * long term persistence.
044: *
045: * @version 1.33 05/05/07
046: * @author Rich Schiavi
047: */
048: public class MotifButtonUI extends BasicButtonUI {
049:
050: private final static MotifButtonUI motifButtonUI = new MotifButtonUI();
051:
052: protected Color selectColor;
053:
054: private boolean defaults_initialized = false;
055:
056: // ********************************
057: // Create PLAF
058: // ********************************
059: public static ComponentUI createUI(JComponent c) {
060: return motifButtonUI;
061: }
062:
063: // ********************************
064: // Create Listeners
065: // ********************************
066: protected BasicButtonListener createButtonListener(AbstractButton b) {
067: return new MotifButtonListener(b);
068: }
069:
070: // ********************************
071: // Install Defaults
072: // ********************************
073: public void installDefaults(AbstractButton b) {
074: super .installDefaults(b);
075: if (!defaults_initialized) {
076: selectColor = UIManager.getColor(getPropertyPrefix()
077: + "select");
078: defaults_initialized = true;
079: }
080: LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
081: }
082:
083: protected void uninstallDefaults(AbstractButton b) {
084: super .uninstallDefaults(b);
085: defaults_initialized = false;
086: }
087:
088: // ********************************
089: // Default Accessors
090: // ********************************
091:
092: protected Color getSelectColor() {
093: return selectColor;
094: }
095:
096: // ********************************
097: // Paint Methods
098: // ********************************
099: public void paint(Graphics g, JComponent c) {
100: fillContentArea(g, (AbstractButton) c, c.getBackground());
101: super .paint(g, c);
102: }
103:
104: // Overridden to ensure we don't paint icon over button borders.
105: protected void paintIcon(Graphics g, JComponent c,
106: Rectangle iconRect) {
107: Shape oldClip = g.getClip();
108: Rectangle newClip = AbstractBorder.getInteriorRectangle(c, c
109: .getBorder(), 0, 0, c.getWidth(), c.getHeight());
110:
111: Rectangle r = oldClip.getBounds();
112: newClip = SwingUtilities.computeIntersection(r.x, r.y, r.width,
113: r.height, newClip);
114: g.setClip(newClip);
115: super .paintIcon(g, c, iconRect);
116: g.setClip(oldClip);
117: }
118:
119: protected void paintFocus(Graphics g, AbstractButton b,
120: Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
121: // focus painting is handled by the border
122: }
123:
124: protected void paintButtonPressed(Graphics g, AbstractButton b) {
125:
126: fillContentArea(g, b, selectColor);
127:
128: }
129:
130: protected void fillContentArea(Graphics g, AbstractButton b,
131: Color fillColor) {
132:
133: if (b.isContentAreaFilled()) {
134: Insets margin = b.getMargin();
135: Insets insets = b.getInsets();
136: Dimension size = b.getSize();
137: g.setColor(fillColor);
138: g.fillRect(insets.left - margin.left, insets.top
139: - margin.top, size.width
140: - (insets.left - margin.left)
141: - (insets.right - margin.right), size.height
142: - (insets.top - margin.top)
143: - (insets.bottom - margin.bottom));
144: }
145: }
146: }
|