J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 26 | package com.sun.java.swing.plaf.motif; |
| 27 | |
| 28 | import javax.swing.*; |
| 29 | import javax.swing.border.*; |
| 30 | import javax.swing.plaf.basic.*; |
| 31 | import java.awt.*; |
| 32 | import java.awt.event.*; |
| 33 | import javax.swing.plaf.*; |
| 34 | |
| 35 | /** |
| 36 | * MotifButton implementation |
| 37 | * <p> |
| 38 | * <strong>Warning:</strong> |
| 39 | * Serialized objects of this class will not be compatible with |
| 40 | * future Swing releases. The current serialization support is appropriate |
| 41 | * for short term storage or RMI between applications running the same |
| 42 | * version of Swing. A future release of Swing will provide support for |
| 43 | * long term persistence. |
| 44 | * |
| 45 | * @author Rich Schiavi |
| 46 | */ |
| 47 | public class MotifButtonUI extends BasicButtonUI { |
| 48 | |
| 49 | private final static MotifButtonUI motifButtonUI = new MotifButtonUI(); |
| 50 | |
| 51 | protected Color selectColor; |
| 52 | |
| 53 | private boolean defaults_initialized = false; |
| 54 | |
| 55 | // ******************************** |
| 56 | // Create PLAF |
| 57 | // ******************************** |
| 58 | public static ComponentUI createUI(JComponent c){ |
| 59 | return motifButtonUI; |
| 60 | } |
| 61 | |
| 62 | // ******************************** |
| 63 | // Create Listeners |
| 64 | // ******************************** |
| 65 | protected BasicButtonListener createButtonListener(AbstractButton b){ |
| 66 | return new MotifButtonListener(b); |
| 67 | } |
| 68 | |
| 69 | // ******************************** |
| 70 | // Install Defaults |
| 71 | // ******************************** |
| 72 | public void installDefaults(AbstractButton b) { |
| 73 | super.installDefaults(b); |
| 74 | if(!defaults_initialized) { |
| 75 | selectColor = UIManager.getColor(getPropertyPrefix() + "select"); |
| 76 | defaults_initialized = true; |
| 77 | } |
| 78 | LookAndFeel.installProperty(b, "opaque", Boolean.FALSE); |
| 79 | } |
| 80 | |
| 81 | protected void uninstallDefaults(AbstractButton b) { |
| 82 | super.uninstallDefaults(b); |
| 83 | defaults_initialized = false; |
| 84 | } |
| 85 | |
| 86 | // ******************************** |
| 87 | // Default Accessors |
| 88 | // ******************************** |
| 89 | |
| 90 | protected Color getSelectColor() { |
| 91 | return selectColor; |
| 92 | } |
| 93 | |
| 94 | // ******************************** |
| 95 | // Paint Methods |
| 96 | // ******************************** |
| 97 | public void paint(Graphics g, JComponent c) { |
| 98 | fillContentArea( g, (AbstractButton)c , c.getBackground() ); |
| 99 | super.paint(g,c); |
| 100 | } |
| 101 | |
| 102 | // Overridden to ensure we don't paint icon over button borders. |
| 103 | protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { |
| 104 | Shape oldClip = g.getClip(); |
| 105 | Rectangle newClip = |
| 106 | AbstractBorder.getInteriorRectangle(c, c.getBorder(), 0, 0, |
| 107 | c.getWidth(), c.getHeight()); |
| 108 | |
| 109 | Rectangle r = oldClip.getBounds(); |
| 110 | newClip = |
| 111 | SwingUtilities.computeIntersection(r.x, r.y, r.width, r.height, |
| 112 | newClip); |
| 113 | g.setClip(newClip); |
| 114 | super.paintIcon(g, c, iconRect); |
| 115 | g.setClip(oldClip); |
| 116 | } |
| 117 | |
| 118 | protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){ |
| 119 | // focus painting is handled by the border |
| 120 | } |
| 121 | |
| 122 | protected void paintButtonPressed(Graphics g, AbstractButton b) { |
| 123 | |
| 124 | fillContentArea( g, b , selectColor ); |
| 125 | |
| 126 | } |
| 127 | |
| 128 | protected void fillContentArea( Graphics g, AbstractButton b, Color fillColor) { |
| 129 | |
| 130 | if (b.isContentAreaFilled()) { |
| 131 | Insets margin = b.getMargin(); |
| 132 | Insets insets = b.getInsets(); |
| 133 | Dimension size = b.getSize(); |
| 134 | g.setColor(fillColor); |
| 135 | g.fillRect(insets.left - margin.left, |
| 136 | insets.top - margin.top, |
| 137 | size.width - (insets.left-margin.left) - (insets.right - margin.right), |
| 138 | size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom)); |
| 139 | } |
| 140 | } |
| 141 | } |