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 27.04.2005
021:
022: */package javax.swing.plaf.metal;
023:
024: import java.awt.Color;
025: import java.awt.Graphics;
026: import java.awt.Rectangle;
027:
028: import javax.swing.AbstractButton;
029: import javax.swing.JComponent;
030: import javax.swing.LookAndFeel;
031: import javax.swing.UIManager;
032: import javax.swing.plaf.ComponentUI;
033: import javax.swing.plaf.UIResource;
034: import javax.swing.plaf.basic.BasicToggleButtonUI;
035:
036: import org.apache.harmony.x.swing.ButtonCommons;
037:
038: public class MetalToggleButtonUI extends BasicToggleButtonUI {
039:
040: protected Color focusColor;
041: protected Color selectColor;
042: protected Color disabledTextColor;
043:
044: private static MetalToggleButtonUI metalToggleButtonUI;
045:
046: public static ComponentUI createUI(final JComponent b) {
047: if (metalToggleButtonUI == null) {
048: metalToggleButtonUI = new MetalToggleButtonUI();
049: }
050: return metalToggleButtonUI;
051: }
052:
053: public void installDefaults(final AbstractButton b) {
054: super .installDefaults(b);
055:
056: if ((selectColor == null)
057: || (selectColor instanceof UIResource)) {
058: selectColor = UIManager.getColor(getPropertyPrefix()
059: + "select");
060: }
061: if ((disabledTextColor == null)
062: || (disabledTextColor instanceof UIResource)) {
063: disabledTextColor = UIManager.getColor(getPropertyPrefix()
064: + "disabledText");
065: }
066: if ((focusColor == null) || (focusColor instanceof UIResource)) {
067: focusColor = UIManager.getColor(getPropertyPrefix()
068: + "focus");
069: }
070: }
071:
072: protected void uninstallDefaults(final AbstractButton b) {
073: LookAndFeel.uninstallBorder(b);
074: }
075:
076: protected Color getSelectColor() {
077: return selectColor;
078: }
079:
080: protected Color getDisabledTextColor() {
081: return disabledTextColor;
082: }
083:
084: protected Color getFocusColor() {
085: return focusColor;
086: }
087:
088: protected void paintButtonPressed(final Graphics g,
089: final AbstractButton button) {
090: if ((button.getModel().isArmed() || button.getModel()
091: .isSelected())
092: && button.isContentAreaFilled()) {
093: Color color = (getSelectColor() != null) ? getSelectColor()
094: : button.getBackground().darker();
095: ButtonCommons.paintPressed(g, button, color);
096: }
097: }
098:
099: protected void paintText(final Graphics g, final JComponent c,
100: final Rectangle textRect, final String text) {
101: AbstractButton b = (AbstractButton) c;
102: Color color = b.isEnabled() ? b.getForeground() : b
103: .isSelected() ? UIManager.getColor("Button.background")
104: .darker() : getDisabledTextColor();
105: ButtonCommons.paintText(g, b, textRect, text, color);
106: }
107:
108: protected void paintFocus(final Graphics g, final AbstractButton b,
109: final Rectangle viewRect, final Rectangle textRect,
110: final Rectangle iconRect) {
111: Color color = (getFocusColor() != null) ? getFocusColor()
112: : UIManager.getDefaults().getColor(
113: "activeCaptionBorder");
114: ButtonCommons.paintFocus(g, ButtonCommons.getFocusRect(
115: viewRect, textRect, iconRect), color);
116: }
117:
118: }
|