0N/A/*
2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing.plaf.basic;
0N/A
1859N/Aimport sun.awt.AppContext;
1859N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.swing.text.View;
0N/A
0N/A
0N/A
0N/A/**
0N/A * BasicToggleButton implementation
0N/A * <p>
0N/A *
0N/A * @author Jeff Dinkins
0N/A */
0N/Apublic class BasicToggleButtonUI extends BasicButtonUI {
0N/A
1859N/A private static final Object BASIC_TOGGLE_BUTTON_UI_KEY = new Object();
0N/A
0N/A private final static String propertyPrefix = "ToggleButton" + ".";
0N/A
0N/A // ********************************
0N/A // Create PLAF
0N/A // ********************************
0N/A public static ComponentUI createUI(JComponent b) {
1859N/A AppContext appContext = AppContext.getAppContext();
1859N/A BasicToggleButtonUI toggleButtonUI =
1859N/A (BasicToggleButtonUI) appContext.get(BASIC_TOGGLE_BUTTON_UI_KEY);
1859N/A if (toggleButtonUI == null) {
1859N/A toggleButtonUI = new BasicToggleButtonUI();
1859N/A appContext.put(BASIC_TOGGLE_BUTTON_UI_KEY, toggleButtonUI);
1859N/A }
0N/A return toggleButtonUI;
0N/A }
0N/A
0N/A protected String getPropertyPrefix() {
0N/A return propertyPrefix;
0N/A }
0N/A
0N/A
0N/A // ********************************
0N/A // Paint Methods
0N/A // ********************************
0N/A public void paint(Graphics g, JComponent c) {
0N/A AbstractButton b = (AbstractButton) c;
0N/A ButtonModel model = b.getModel();
0N/A
0N/A Dimension size = b.getSize();
0N/A FontMetrics fm = g.getFontMetrics();
0N/A
0N/A Insets i = c.getInsets();
0N/A
0N/A Rectangle viewRect = new Rectangle(size);
0N/A
0N/A viewRect.x += i.left;
0N/A viewRect.y += i.top;
0N/A viewRect.width -= (i.right + viewRect.x);
0N/A viewRect.height -= (i.bottom + viewRect.y);
0N/A
0N/A Rectangle iconRect = new Rectangle();
0N/A Rectangle textRect = new Rectangle();
0N/A
0N/A Font f = c.getFont();
0N/A g.setFont(f);
0N/A
0N/A // layout the text and icon
0N/A String text = SwingUtilities.layoutCompoundLabel(
0N/A c, fm, b.getText(), b.getIcon(),
0N/A b.getVerticalAlignment(), b.getHorizontalAlignment(),
0N/A b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
0N/A viewRect, iconRect, textRect,
0N/A b.getText() == null ? 0 : b.getIconTextGap());
0N/A
0N/A g.setColor(b.getBackground());
0N/A
0N/A if (model.isArmed() && model.isPressed() || model.isSelected()) {
0N/A paintButtonPressed(g,b);
0N/A }
0N/A
0N/A // Paint the Icon
0N/A if(b.getIcon() != null) {
0N/A paintIcon(g, b, iconRect);
0N/A }
0N/A
0N/A // Draw the Text
0N/A if(text != null && !text.equals("")) {
0N/A View v = (View) c.getClientProperty(BasicHTML.propertyKey);
0N/A if (v != null) {
0N/A v.paint(g, textRect);
0N/A } else {
0N/A paintText(g, b, textRect, text);
0N/A }
0N/A }
0N/A
0N/A // draw the dashed focus line.
0N/A if (b.isFocusPainted() && b.hasFocus()) {
0N/A paintFocus(g, b, viewRect, textRect, iconRect);
0N/A }
0N/A }
0N/A
0N/A protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
0N/A ButtonModel model = b.getModel();
0N/A Icon icon = null;
0N/A
0N/A if(!model.isEnabled()) {
0N/A if(model.isSelected()) {
614N/A icon = b.getDisabledSelectedIcon();
0N/A } else {
614N/A icon = b.getDisabledIcon();
0N/A }
0N/A } else if(model.isPressed() && model.isArmed()) {
614N/A icon = b.getPressedIcon();
0N/A if(icon == null) {
0N/A // Use selected icon
614N/A icon = b.getSelectedIcon();
0N/A }
0N/A } else if(model.isSelected()) {
0N/A if(b.isRolloverEnabled() && model.isRollover()) {
614N/A icon = b.getRolloverSelectedIcon();
0N/A if (icon == null) {
614N/A icon = b.getSelectedIcon();
0N/A }
0N/A } else {
614N/A icon = b.getSelectedIcon();
0N/A }
0N/A } else if(b.isRolloverEnabled() && model.isRollover()) {
614N/A icon = b.getRolloverIcon();
0N/A }
0N/A
0N/A if(icon == null) {
614N/A icon = b.getIcon();
0N/A }
0N/A
0N/A icon.paintIcon(b, g, iconRect.x, iconRect.y);
0N/A }
0N/A
0N/A /**
0N/A * Overriden so that the text will not be rendered as shifted for
0N/A * Toggle buttons and subclasses.
0N/A */
0N/A protected int getTextShiftOffset() {
0N/A return 0;
0N/A }
0N/A
0N/A}