4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage com.apple.laf;
4632N/A
4632N/Aimport java.awt.*;
4632N/A
4632N/Aimport javax.swing.*;
4632N/Aimport javax.swing.plaf.*;
4632N/Aimport javax.swing.plaf.basic.*;
4632N/A
4632N/Aimport sun.swing.SwingUtilities2;
4632N/A
4632N/Aimport com.apple.laf.AquaUtils.RecyclableSingleton;
4632N/Aimport com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
4632N/A
4632N/Apublic class AquaLabelUI extends BasicLabelUI {
4632N/A protected static final RecyclableSingleton<AquaLabelUI> aquaLabelUI = new RecyclableSingletonFromDefaultConstructor<AquaLabelUI>(AquaLabelUI.class);
4632N/A
4632N/A public static ComponentUI createUI(final JComponent c) {
4632N/A return aquaLabelUI.get();
4632N/A }
4632N/A
4632N/A protected void installListeners(final JLabel c) {
4632N/A super.installListeners(c);
4632N/A AquaUtilControlSize.addSizePropertyListener(c);
4632N/A }
4632N/A
4632N/A protected void uninstallListeners(final JLabel c) {
4632N/A AquaUtilControlSize.removeSizePropertyListener(c);
4632N/A super.uninstallListeners(c);
4632N/A }
4632N/A
4632N/A protected void paintEnabledText(final JLabel l, final Graphics g, final String s, final int textX, final int textY) {
4632N/A int mnemIndex = l.getDisplayedMnemonicIndex();
4632N/A if (AquaMnemonicHandler.isMnemonicHidden()) {
4632N/A mnemIndex = -1;
4632N/A }
4632N/A
4632N/A g.setColor(l.getForeground());
4632N/A SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex, textX, textY);
4632N/A }
4632N/A
4632N/A /**
4632N/A * Paint clippedText at textX, textY with background.lighter() and then
4632N/A * shifted down and to the right by one pixel with background.darker().
4632N/A *
4632N/A * @see #paint
4632N/A * @see #paintEnabledText
4632N/A */
4632N/A protected void paintDisabledText(final JLabel l, final Graphics g, final String s, final int textX, final int textY) {
4632N/A int accChar = l.getDisplayedMnemonicIndex();
4632N/A if (AquaMnemonicHandler.isMnemonicHidden()) {
4632N/A accChar = -1;
4632N/A }
4632N/A
4632N/A final Color background = l.getBackground();
4632N/A
4632N/A // if our background is still something we set then we can use our happy background color.
4632N/A if (background instanceof UIResource) {
4632N/A g.setColor(getDisabledLabelColor(l));
4632N/A SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar, textX, textY);
4632N/A } else {
4632N/A super.paintDisabledText(l, g, s, textX, textY);
4632N/A }
4632N/A }
4632N/A
4632N/A static final String DISABLED_COLOR_KEY = "Label.disabledForegroundColor";
4632N/A protected Color getDisabledLabelColor(final JLabel label) {
4632N/A final Color fg = label.getForeground();
4632N/A
4632N/A final Object colorProperty = label.getClientProperty(DISABLED_COLOR_KEY);
4632N/A if (colorProperty instanceof Color) {
4632N/A final Color disabledColor = (Color)colorProperty;
4632N/A if ((fg.getRGB() << 8) == (disabledColor.getRGB() << 8)) return disabledColor;
4632N/A }
4632N/A
4632N/A final Color newDisabledColor = new Color(fg.getRed(), fg.getGreen(), fg.getBlue(), fg.getAlpha() / 2);
4632N/A label.putClientProperty(DISABLED_COLOR_KEY, newDisabledColor);
4632N/A return newDisabledColor;
4632N/A }
4632N/A}