javax.swing.plaf.basic

Class BasicButtonUI

Known Direct Subclasses:
BasicToggleButtonUI, MetalButtonUI

public class BasicButtonUI
extends ButtonUI

Field Summary

protected int
defaultTextIconGap
A constant used to pad out elements in the button's layout and preferred size calculations.
protected int
defaultTextShiftOffset
A constant added to the defaultTextIconGap to adjust the text within this particular button.
protected BasicButtonListener
listener

Method Summary

protected void
clearTextShiftOffset()
protected BasicButtonListener
createButtonListener(AbstractButton b)
static ComponentUI
createUI(JComponent c)
Factory method to create an instance of BasicButtonUI for a given JComponent, which should be an AbstractButton.
int
getDefaultTextIconGap(AbstractButton b)
Dimension
getPreferredSize(JComponent c)
Calculate the preferred size of this component, by delegating to BasicGraphicsUtils.getPreferredButtonSize(AbstractButton,int).
protected String
getPropertyPrefix()
Returns the prefix for the UI defaults property for this UI class.
protected int
getTextShiftOffset()
protected void
installDefaults(AbstractButton b)
protected void
installKeyboardActions(AbstractButton b)
protected void
installListeners(AbstractButton b)
void
installUI(JComponent c)
Install the BasicButtonUI as the UI for a particular component.
void
paint(Graphics g, JComponent c)
Paint the component, which is an AbstractButton, according to its current state.
protected void
paintButtonPressed(Graphics g, AbstractButton b)
Paints the background area of an AbstractButton in the pressed state.
protected void
paintFocus(Graphics g, AbstractButton b, Rectangle vr, Rectangle tr, Rectangle ir)
Paint any focus decoration this JComponent might have.
protected void
paintIcon(Graphics g, JComponent c, Rectangle iconRect)
Paint the icon for this component.
protected void
paintText(Graphics g, AbstractButton b, Rectangle textRect, String text)
Paints the "text" property of an AbstractButton, using the textColor color.
protected void
paintText(Graphics g, JComponent c, Rectangle textRect, String text)
Paints the "text" property of an AbstractButton, using the textColor color.
protected void
setTextShiftOffset()
protected void
uninstallDefaults(AbstractButton b)
protected void
uninstallKeyboardActions(AbstractButton b)
protected void
uninstallListeners(AbstractButton b)

Methods inherited from class javax.swing.plaf.ComponentUI

contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

defaultTextIconGap

protected int defaultTextIconGap
A constant used to pad out elements in the button's layout and preferred size calculations.


defaultTextShiftOffset

protected int defaultTextShiftOffset
A constant added to the defaultTextIconGap to adjust the text within this particular button.


listener

protected BasicButtonListener listener

Method Details

clearTextShiftOffset

protected void clearTextShiftOffset()


createButtonListener

protected BasicButtonListener createButtonListener(AbstractButton b)


createUI

public static ComponentUI createUI(JComponent c)
Factory method to create an instance of BasicButtonUI for a given JComponent, which should be an AbstractButton.
Overrides:
createUI in interface ComponentUI

Parameters:
c - The component to create a UI got

Returns:
A new UI capable of drawing the component


getDefaultTextIconGap

public int getDefaultTextIconGap(AbstractButton b)


getPreferredSize

public Dimension getPreferredSize(JComponent c)
Calculate the preferred size of this component, by delegating to BasicGraphicsUtils.getPreferredButtonSize(AbstractButton,int).
Overrides:
getPreferredSize in interface ComponentUI

Parameters:
c - The component to measure

Returns:
The preferred dimensions of the component


getPropertyPrefix

protected String getPropertyPrefix()
Returns the prefix for the UI defaults property for this UI class. This is 'Button' for this class.

Returns:
the prefix for the UI defaults property


getTextShiftOffset

protected int getTextShiftOffset()


installDefaults

protected void installDefaults(AbstractButton b)


installKeyboardActions

protected void installKeyboardActions(AbstractButton b)


installListeners

protected void installListeners(AbstractButton b)


installUI

public void installUI(JComponent c)
Install the BasicButtonUI as the UI for a particular component. This means registering all the UI's listeners with the component, and setting any properties of the button which are particular to this look and feel.
Overrides:
installUI in interface ComponentUI

Parameters:
c - The component to install the UI into


paint

public void paint(Graphics g,
                  JComponent c)
Paint the component, which is an AbstractButton, according to its current state.
Overrides:
paint in interface ComponentUI

Parameters:
g - The graphics context to paint with
c - The component to paint the state of


paintButtonPressed

protected void paintButtonPressed(Graphics g,
                                  AbstractButton b)
Paints the background area of an AbstractButton in the pressed state. This means filling the supplied area with the pressedBackgroundColor.

Parameters:
g - The graphics context to paint with
b - The button to paint the state of


paintFocus

protected void paintFocus(Graphics g,
                          AbstractButton b,
                          Rectangle vr,
                          Rectangle tr,
                          Rectangle ir)
Paint any focus decoration this JComponent might have. The component, which in this case will be an AbstractButton, should only have focus decoration painted if it has the focus, and its "focusPainted" property is true.

Parameters:
g - Graphics context to paint with
b - Button to paint the focus of
vr - Visible rectangle, the area in which to paint
tr - Text rectangle, contained in visible rectangle
ir - Icon rectangle, contained in visible rectangle

See Also:
AbstractButton.isFocusPainted(), JComponent.hasFocus()


paintIcon

protected void paintIcon(Graphics g,
                         JComponent c,
                         Rectangle iconRect)
Paint the icon for this component. Depending on the state of the component and the availability of the button's various icon properties, this might mean painting one of several different icons.

Parameters:
g - Graphics context to paint with
c - Component to paint the icon of
iconRect - Rectangle in which the icon should be painted


paintText

protected void paintText(Graphics g,
                         AbstractButton b,
                         Rectangle textRect,
                         String text)
Paints the "text" property of an AbstractButton, using the textColor color.

Parameters:
g - The graphics context to paint with
b - The button to paint the state of
textRect - The area in which to paint the text
text - The text to paint

Since:
1.4


paintText

protected void paintText(Graphics g,
                         JComponent c,
                         Rectangle textRect,
                         String text)
Paints the "text" property of an AbstractButton, using the textColor color.

Parameters:
g - The graphics context to paint with
c - The component to paint the state of
textRect - The area in which to paint the text
text - The text to paint


setTextShiftOffset

protected void setTextShiftOffset()


uninstallDefaults

protected void uninstallDefaults(AbstractButton b)


uninstallKeyboardActions

protected void uninstallKeyboardActions(AbstractButton b)


uninstallListeners

protected void uninstallListeners(AbstractButton b)


BasicButtonUI.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.