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.windows; |
| 27 | |
| 28 | import javax.swing.plaf.basic.*; |
| 29 | import javax.swing.*; |
| 30 | import javax.swing.plaf.*; |
| 31 | |
| 32 | import java.awt.*; |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Windows rendition of the component. |
| 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 | public class WindowsRadioButtonUI extends BasicRadioButtonUI |
| 46 | { |
| 47 | private static final WindowsRadioButtonUI windowsRadioButtonUI = new WindowsRadioButtonUI(); |
| 48 | |
| 49 | protected int dashedRectGapX; |
| 50 | protected int dashedRectGapY; |
| 51 | protected int dashedRectGapWidth; |
| 52 | protected int dashedRectGapHeight; |
| 53 | |
| 54 | protected Color focusColor; |
| 55 | |
| 56 | private boolean initialized = false; |
| 57 | |
| 58 | // ******************************** |
| 59 | // Create PLAF |
| 60 | // ******************************** |
| 61 | public static ComponentUI createUI(JComponent c) { |
| 62 | return windowsRadioButtonUI; |
| 63 | } |
| 64 | |
| 65 | // ******************************** |
| 66 | // Defaults |
| 67 | // ******************************** |
| 68 | public void installDefaults(AbstractButton b) { |
| 69 | super.installDefaults(b); |
| 70 | if(!initialized) { |
| 71 | dashedRectGapX = ((Integer)UIManager.get("Button.dashedRectGapX")).intValue(); |
| 72 | dashedRectGapY = ((Integer)UIManager.get("Button.dashedRectGapY")).intValue(); |
| 73 | dashedRectGapWidth = ((Integer)UIManager.get("Button.dashedRectGapWidth")).intValue(); |
| 74 | dashedRectGapHeight = ((Integer)UIManager.get("Button.dashedRectGapHeight")).intValue(); |
| 75 | focusColor = UIManager.getColor(getPropertyPrefix() + "focus"); |
| 76 | initialized = true; |
| 77 | } |
| 78 | if (XPStyle.getXP() != null) { |
| 79 | LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | protected Color getFocusColor() { |
| 84 | return focusColor; |
| 85 | } |
| 86 | |
| 87 | // ******************************** |
| 88 | // Paint Methods |
| 89 | // ******************************** |
| 90 | |
| 91 | /** |
| 92 | * Overridden method to render the text without the mnemonic |
| 93 | */ |
| 94 | protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) { |
| 95 | WindowsGraphicsUtils.paintText(g, b, textRect, text, getTextShiftOffset()); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | protected void paintFocus(Graphics g, Rectangle textRect, Dimension d){ |
| 100 | g.setColor(getFocusColor()); |
| 101 | BasicGraphicsUtils.drawDashedRect(g, textRect.x, textRect.y, textRect.width, textRect.height); |
| 102 | } |
| 103 | |
| 104 | // ******************************** |
| 105 | // Layout Methods |
| 106 | // ******************************** |
| 107 | public Dimension getPreferredSize(JComponent c) { |
| 108 | Dimension d = super.getPreferredSize(c); |
| 109 | |
| 110 | /* Ensure that the width and height of the button is odd, |
| 111 | * to allow for the focus line if focus is painted |
| 112 | */ |
| 113 | AbstractButton b = (AbstractButton)c; |
| 114 | if (d != null && b.isFocusPainted()) { |
| 115 | if(d.width % 2 == 0) { d.width += 1; } |
| 116 | if(d.height % 2 == 0) { d.height += 1; } |
| 117 | } |
| 118 | return d; |
| 119 | } |
| 120 | |
| 121 | } |