01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexander T. Simbirtsev
19: * @version $Revision$
20: */package javax.swing.plaf.metal;
21:
22: import java.awt.Color;
23: import java.awt.Graphics;
24: import java.awt.Rectangle;
25:
26: import javax.swing.AbstractButton;
27: import javax.swing.JComponent;
28: import javax.swing.UIManager;
29: import javax.swing.plaf.ComponentUI;
30: import javax.swing.plaf.basic.BasicButtonUI;
31:
32: import org.apache.harmony.x.swing.ButtonCommons;
33:
34: public class MetalButtonUI extends BasicButtonUI {
35:
36: protected Color disabledTextColor;
37: protected Color focusColor;
38: protected Color selectColor;
39:
40: private static MetalButtonUI commonMetalButtonUI;
41:
42: public static ComponentUI createUI(final JComponent component) {
43: if (commonMetalButtonUI == null) {
44: commonMetalButtonUI = new MetalButtonUI();
45: }
46: return commonMetalButtonUI;
47: }
48:
49: public void installDefaults(final AbstractButton button) {
50: super .installDefaults(button);
51: }
52:
53: public void uninstallDefaults(final AbstractButton button) {
54: super .uninstallDefaults(button);
55: }
56:
57: protected Color getDisabledTextColor() {
58: disabledTextColor = UIManager.getColor(getPropertyPrefix()
59: + "disabledText");
60: return disabledTextColor;
61: }
62:
63: protected Color getFocusColor() {
64: focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
65: return focusColor;
66: }
67:
68: protected Color getSelectColor() {
69: selectColor = UIManager
70: .getColor(getPropertyPrefix() + "select");
71: return selectColor;
72: }
73:
74: protected void paintButtonPressed(final Graphics g,
75: final AbstractButton button) {
76: if (button.getModel().isArmed() && button.isContentAreaFilled()) {
77: ButtonCommons.paintPressed(g, button, getSelectColor());
78: }
79: }
80:
81: protected void paintFocus(final Graphics g, final AbstractButton b,
82: final Rectangle viewRect, final Rectangle textRect,
83: final Rectangle iconRect) {
84: ButtonCommons.paintFocus(g, ButtonCommons.getFocusRect(
85: viewRect, textRect, iconRect), getFocusColor());
86: }
87:
88: protected void paintText(final Graphics g, final JComponent c,
89: final Rectangle textRect, final String text) {
90: final Color color = c.isEnabled() ? c.getForeground()
91: : getDisabledTextColor();
92: final int offset = getTextShiftOffset();
93: textRect.translate(offset, offset);
94: ButtonCommons.paintText(g, (AbstractButton) c, textRect, text,
95: color);
96: }
97: }
|