javax.swing.plaf.basic

Class BasicLabelUI

Implemented Interfaces:
EventListener, PropertyChangeListener
Known Direct Subclasses:
MetalLabelUI

public class BasicLabelUI
extends LabelUI
implements PropertyChangeListener

This is the Basic Look and Feel class for the JLabel. One BasicLabelUI object is used to paint all JLabels that utilize the Basic Look and Feel.

Field Summary

protected static BasicLabelUI
labelUI
The labelUI that is shared by all labels.

Constructor Summary

BasicLabelUI()
Creates a new BasicLabelUI object.

Method Summary

static ComponentUI
createUI(JComponent c)
Creates and returns a UI for the label.
Dimension
getMaximumSize(JComponent c)
This method returns the maximum size of the JComponent given.
Dimension
getMinimumSize(JComponent c)
This method returns the minimum size of the JComponent given.
Dimension
getPreferredSize(JComponent c)
Returns the preferred size of this component as calculated by the layoutCL(JLabel,FontMetrics,String,Icon,Rectangle,Rectangle,Rectangle) method.
protected void
installComponents(JLabel c)
This method installs the components for this JLabel.
protected void
installDefaults(JLabel c)
This method installs the defaults that are defined in the Basic look and feel for this JLabel.
protected void
installKeyboardActions(JLabel l)
Installs the keyboard actions for the given JLabel.
protected void
installListeners(JLabel c)
This method installs the listeners for the given JLabel.
void
installUI(JComponent c)
This method installs the UI for the given JComponent.
protected String
layoutCL(JLabel label, FontMetrics fontMetrics, String text, Icon icon, Rectangle viewR, Rectangle iconR, Rectangle textR)
This method is simply calls SwingUtilities's layoutCompoundLabel.
void
paint(Graphics g, JComponent c)
The method that paints the label according to its current state.
protected void
paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
Paints the text if the label is disabled.
protected void
paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY)
Paints the text if the label is enabled.
void
propertyChange(PropertyChangeEvent e)
This method is called whenever any JLabel's that use this UI has one of their properties change.
protected void
uninstallComponents(JLabel c)
This method uninstalls the components for this JLabel.
protected void
uninstallDefaults(JLabel c)
This method uninstalls the defaults that are defined in the Basic look and feel for this JLabel.
protected void
uninstallKeyboardActions(JLabel l)
This method uninstalls the keyboard actions for the given JLabel.
protected void
uninstallListeners(JLabel c)
This method uninstalls the listeners for the given JLabel.
void
uninstallUI(JComponent c)
This method uninstalls the UI for the given JComponent.

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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

labelUI

protected static BasicLabelUI labelUI
The labelUI that is shared by all labels.

Constructor Details

BasicLabelUI

public BasicLabelUI()
Creates a new BasicLabelUI object.

Method Details

createUI

public static ComponentUI createUI(JComponent c)
Creates and returns a UI for the label. Since one UI is shared by all labels, this means creating only if necessary and returning the shared UI.
Overrides:
createUI in interface ComponentUI
Parameters:
c - The JComponent that a UI is being created for.
Returns:
A label UI for the Basic Look and Feel.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
This method returns the maximum size of the JComponent given. If this method returns null, then it is up to the Layout Manager to give this component a maximum size.
Overrides:
getMaximumSize in interface ComponentUI
Parameters:
c - The JComponent to get a maximum size for.
Returns:
The maximum size.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
This method returns the minimum size of the JComponent given. If this method returns null, then it is up to the Layout Manager to give this component a minimum size.
Overrides:
getMinimumSize in interface ComponentUI
Parameters:
c - The JComponent to get a minimum size for.
Returns:
The minimum size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns the preferred size of this component as calculated by the layoutCL(JLabel,FontMetrics,String,Icon,Rectangle,Rectangle,Rectangle) method.
Overrides:
getPreferredSize in interface ComponentUI
Parameters:
c - This JComponent to get a preferred size for.
Returns:
The preferred size.

installComponents

protected void installComponents(JLabel c)
This method installs the components for this JLabel.
Parameters:
c - The JLabel to install components for.

installDefaults

protected void installDefaults(JLabel c)
This method installs the defaults that are defined in the Basic look and feel for this JLabel.
Parameters:
c - The JLabel to install defaults for.

installKeyboardActions

protected void installKeyboardActions(JLabel l)
Installs the keyboard actions for the given JLabel.
Parameters:
l - The JLabel to install keyboard actions for.

installListeners

protected void installListeners(JLabel c)
This method installs the listeners for the given JLabel. The UI delegate only listens to the label.
Parameters:
c - The JLabel to install listeners for.

installUI

public void installUI(JComponent c)
This method installs the UI for the given JComponent. This method will install the component, defaults, listeners, and keyboard actions.
Overrides:
installUI in interface ComponentUI
Parameters:
c - The JComponent that this UI is being installed on.

layoutCL

protected String layoutCL(JLabel label,
                          FontMetrics fontMetrics,
                          String text,
                          Icon icon,
                          Rectangle viewR,
                          Rectangle iconR,
                          Rectangle textR)
This method is simply calls SwingUtilities's layoutCompoundLabel.
Parameters:
label - The label to lay out.
fontMetrics - The FontMetrics for the font used.
text - The text to paint.
icon - The icon to draw.
viewR - The entire viewable rectangle.
iconR - The icon bounds rectangle.
textR - The text bounds rectangle.
Returns:
A possibly clipped version of the text.

paint

public void paint(Graphics g,
                  JComponent c)
The method that paints the label according to its current state.
Overrides:
paint in interface ComponentUI
Parameters:
g - The Graphics object to paint with.
c - The JComponent to paint.

paintDisabledText

protected void paintDisabledText(JLabel l,
                                 Graphics g,
                                 String s,
                                 int textX,
                                 int textY)
Paints the text if the label is disabled. By default, this paints the clipped text returned by layoutCompoundLabel using the background.brighter() color. It also paints the same text using the background.darker() color one pixel to the right and one pixel down.
Parameters:
l - The JLabel being painted.
g - The Graphics object to paint with.
s - The String to paint.
textX - The x coordinate of the start of the baseline.
textY - The y coordinate of the start of the baseline.

paintEnabledText

protected void paintEnabledText(JLabel l,
                                Graphics g,
                                String s,
                                int textX,
                                int textY)
Paints the text if the label is enabled. The text is painted using the foreground color.
Parameters:
l - The JLabel being painted.
g - The Graphics object to paint with.
s - The String to paint.
textX - The x coordinate of the start of the baseline.
textY - The y coordinate of the start of the baseline.

propertyChange

public void propertyChange(PropertyChangeEvent e)
This method is called whenever any JLabel's that use this UI has one of their properties change.
Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
e - The PropertyChangeEvent that describes the change.

uninstallComponents

protected void uninstallComponents(JLabel c)
This method uninstalls the components for this JLabel.
Parameters:
c - The JLabel to uninstall components for.

uninstallDefaults

protected void uninstallDefaults(JLabel c)
This method uninstalls the defaults that are defined in the Basic look and feel for this JLabel.
Parameters:
c - The JLabel to uninstall defaults for.

uninstallKeyboardActions

protected void uninstallKeyboardActions(JLabel l)
This method uninstalls the keyboard actions for the given JLabel.
Parameters:
l - The JLabel to uninstall keyboard actions for.

uninstallListeners

protected void uninstallListeners(JLabel c)
This method uninstalls the listeners for the given JLabel. The UI delegate only listens to the label.
Parameters:
c - The JLabel to uninstall listeners for.

uninstallUI

public void uninstallUI(JComponent c)
This method uninstalls the UI for the given JComponent. This method will uninstall the component, defaults, listeners, and keyboard actions.
Overrides:
uninstallUI in interface ComponentUI
Parameters:
c - The JComponent that this UI is being installed on.

BasicLabelUI.java Copyright (C) 2002, 2004, 2006, 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.