001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: * Created on 29.04.2005
021:
022: */package javax.swing.plaf.metal;
023:
024: import java.awt.Color;
025: import java.awt.Dimension;
026: import java.awt.Graphics;
027: import java.awt.Rectangle;
028:
029: import javax.swing.AbstractButton;
030: import javax.swing.Icon;
031: import javax.swing.JComponent;
032: import javax.swing.UIManager;
033: import javax.swing.plaf.ComponentUI;
034: import javax.swing.plaf.UIResource;
035: import javax.swing.plaf.basic.BasicRadioButtonUI;
036:
037: import org.apache.harmony.x.swing.ButtonCommons;
038:
039: public class MetalRadioButtonUI extends BasicRadioButtonUI {
040:
041: protected Color focusColor;
042: protected Color selectColor;
043: protected Color disabledTextColor;
044: private static Color defaultFocusColor;
045:
046: private static MetalRadioButtonUI metalRadioButtonUI;
047:
048: public static ComponentUI createUI(final JComponent c) {
049: if (metalRadioButtonUI == null) {
050: metalRadioButtonUI = new MetalRadioButtonUI();
051: }
052: return metalRadioButtonUI;
053: }
054:
055: public void installDefaults(final AbstractButton b) {
056: super .installDefaults(b);
057:
058: if ((disabledTextColor == null)
059: || (disabledTextColor instanceof UIResource)) {
060: disabledTextColor = UIManager.getColor(getPropertyPrefix()
061: + "disabledText");
062: }
063: if ((focusColor == null) || (focusColor instanceof UIResource)) {
064: focusColor = UIManager.getColor(getPropertyPrefix()
065: + "focus");
066: }
067: if ((selectColor == null)
068: || (selectColor instanceof UIResource)) {
069: selectColor = UIManager.getColor(getPropertyPrefix()
070: + "select");
071: }
072: if (defaultFocusColor == null) {
073: defaultFocusColor = UIManager.getDefaults().getColor(
074: "activeCaptionBorder");
075: }
076: }
077:
078: protected Color getSelectColor() {
079: return selectColor;
080: }
081:
082: protected Color getDisabledTextColor() {
083: return disabledTextColor;
084: }
085:
086: protected Color getFocusColor() {
087: return focusColor;
088: }
089:
090: public void paint(final Graphics g, final JComponent c) {
091: AbstractButton button = (AbstractButton) c;
092: Rectangle viewR = new Rectangle();
093: Rectangle iconR = new Rectangle();
094: Rectangle textR = new Rectangle();
095: Icon icon = ButtonCommons.getCurrentIcon(button);
096: if (icon == null) {
097: icon = getDefaultIcon();
098: }
099:
100: String clippedText = ButtonCommons.getPaintingParameters(
101: button, viewR, iconR, textR, icon);
102: if (icon != null) {
103: icon.paintIcon(button, g, iconR.x, iconR.y);
104: }
105: textR.x += getTextShiftOffset();
106: textR.y += getTextShiftOffset();
107: paintText(g, button, textR, clippedText, getDisabledTextColor());
108: if (button.isEnabled() && button.isFocusPainted()
109: && button.isFocusOwner()) {
110: paintFocus(g, ButtonCommons.getFocusRect(textR, viewR,
111: iconR), null);
112: }
113: }
114:
115: protected void paintFocus(final Graphics g, final Rectangle t,
116: final Dimension d) {
117: Color color = (focusColor != null) ? focusColor
118: : defaultFocusColor;
119: ButtonCommons.paintFocus(g, t, color);
120: }
121:
122: private void paintText(final Graphics g, final AbstractButton b,
123: final Rectangle textRect, final String text,
124: final Color disabledTextColor) {
125: Color color = b.isEnabled() ? b.getForeground()
126: : disabledTextColor;
127: ButtonCommons.paintText(g, b, textRect, text, color);
128: }
129:
130: }
|