Top Description Inners Fields Constructors Methods
javax.swing.plaf.basic

public abstract Class BasicLookAndFeel

extends LookAndFeel
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
javax.swing.plaf.metal.MetalLookAndFeel, javax.swing.plaf.synth.SynthLookAndFeel, com.sun.java.swing.plaf.motif.MotifLookAndFeel
Annotations
@SuppressWarnings:serial
Imports
java.awt.AWTEvent, .Color, .Component, .Dimension, .Font, .Point, .SystemColor, .Toolkit, .Window, java.awt.event.AWTEventListener, .ActionEvent, .MouseEvent, java.beans.PropertyChangeEvent, .PropertyChangeListener, .PropertyVetoException, java.io.BufferedInputStream, .ByteArrayInputStream, .IOException, .InputStream, .Serializable, java.security.AccessController, .PrivilegedAction, java.util.HashSet, .Locale, javax.sound.sampled.AudioInputStream, .AudioSystem, .Clip, .DataLine, .LineEvent, .LineListener, javax.swing.AbstractAction, .Action, .ActionMap, .DefaultListCellRenderer, .JComponent, .JInternalFrame, .JPopupMenu, .JTextField, .LookAndFeel, .MenuElement, .MenuSelectionManager, .SwingUtilities, .UIDefaults, .UIManager, javax.swing.border.BevelBorder, javax.swing.plaf.ActionMapUIResource, .BorderUIResource, .ColorUIResource, .ComponentUI, .DimensionUIResource, .FontUIResource, .InsetsUIResource, javax.swing.text.DefaultEditorKit, sun.awt.AppContext, .SunToolkit, sun.swing.SwingAccessor, .SwingUtilities2, sun.swing.icon.SortArrowIcon

A base class to use in creating a look and feel for Swing.

Each of the ComponentUIs provided by BasicLookAndFeel derives its behavior from the defaults table. Unless otherwise noted each of the ComponentUI implementations in this package document the set of defaults they use. Unless otherwise noted the defaults are installed at the time installUI is invoked, and follow the recommendations outlined in LookAndFeel for installing defaults.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
BasicLookAndFeel.AudioAction

Pass the name String to the super constructor.

pack-priv class
BasicLookAndFeel.AWTEventHelper

This class contains listener that watches for all the mouse events that can possibly invoke popup on the component

Field Summary

Modifier and TypeField and Description
private transient Object
audioLock

Lock used when manipulating clipPlaying.

private Clip
clipPlaying

The Clip that is currently playing (set in AudioAction).

private PropertyChangeListener
pack-priv BasicLookAndFeel.AWTEventHelper
pack-priv static boolean
needsEventHelper

Whether or not the developer has created a JPopupMenu.

Constructor Summary

AccessConstructor and Description
protected
BasicLookAndFeel()

Constructor for subclasses to call.

Method Summary

Modifier and TypeMethod and Description
protected Action

Returns:

an Action used to play the source, or null if key is null
createAudioAction
(Object
the key identifying the audio action
key
)

Creates and returns an Action used to play a sound.

protected ActionMap

Returns:

an ActionMap containing Actions responsible for playing auditory cues
getAudioActionMap
()

Returns an ActionMap containing the audio actions for this look and feel.

public UIDefaults

Returns:

the look and feel defaults
getDefaults
()

Overrides javax.swing.LookAndFeel.getDefaults.

Returns the look and feel defaults.
pack-priv static int
pack-priv static Object
getUIOfType(ComponentUI ui, Class<?> klass)

Returns the ui that is of type klass, or null if one can not be found.

protected void
initClassDefaults(UIDefaults
the UIDefaults instance the entries are added to
table
)

Populates table with mappings from uiClassID to the fully qualified name of the ui class.

protected void
initComponentDefaults(UIDefaults
the UIDefaults to add the values to
table
)

Populates table with the defaults for the basic look and feel.

public void
initialize()

Overrides javax.swing.LookAndFeel.initialize.

Initializes the look and feel.
private void
initResourceBundle(UIDefaults table)

Initialize the defaults table with the name of the ResourceBundle used for getting localized defaults.

protected void
initSystemColorDefaults(UIDefaults
the UIDefaults object the values are added to
table
)

Populates table with system colors.

pack-priv static void
installAudioActionMap(ActionMap map)

Sets the parent of the passed in ActionMap to be the audio action map.

pack-priv void
private byte[]

Returns:

A byte[] with audio data or null
loadAudioData
(final String
the name of the audio file to be retrieved from disk
soundFile
)

Utility method that loads audio bits for the specified soundFile filename.

protected void
loadSystemColors(UIDefaults
the UIDefaults object the values are added to
table
,
String[]
array of name-color pairs as described in initSystemColorDefaults(UIDefaults)
systemColors
,
boolean
whether the color is obtained from SystemColor or Color.decode
useNative
)

Populates table with the name-color pairs in systemColors.

protected void
playSound(Action
an Action that knows how to render the audio associated with the system or user activity that is occurring; a value of null, is ignored
audioAction
)

If necessary, invokes actionPerformed on audioAction to play a sound.

pack-priv static void
playSound(JComponent
JComponent to play the sound for.
c
,
Object
Key for the sound.
actionKey
)

Helper method to play a named sound.

public void
uninitialize()

Overrides javax.swing.LookAndFeel.uninitialize.

Uninitializes the look and feel.
Inherited from javax.swing.LookAndFeel:
getDescriptiongetDesktopPropertyValuegetDisabledIcongetDisabledSelectedIcongetIDgetLayoutStylegetNamegetSupportsWindowDecorationsinstallBorderinstallColorsinstallColorsAndFontinstallPropertyisNativeLookAndFeelisSupportedLookAndFeelloadKeyBindingsmakeComponentInputMapmakeIconmakeInputMapmakeKeyBindingsprovideErrorFeedbacktoStringuninstallBorder

Field Detail

audioLockback to summary
private transient Object audioLock

Lock used when manipulating clipPlaying.

clipPlayingback to summary
private Clip clipPlaying

The Clip that is currently playing (set in AudioAction).

disposerback to summary
private PropertyChangeListener disposer
invocatorback to summary
pack-priv BasicLookAndFeel.AWTEventHelper invocator
needsEventHelperback to summary
pack-priv static boolean needsEventHelper

Whether or not the developer has created a JPopupMenu.

Constructor Detail

BasicLookAndFeelback to summary
protected BasicLookAndFeel()

Constructor for subclasses to call.

Method Detail

createAudioActionback to summary
protected Action createAudioAction(Object key)

Creates and returns an Action used to play a sound.

If key is non-null, an Action is created using the value from the defaults with key key. The value identifies the sound resource to load when actionPerformed is invoked on the Action. The sound resource is loaded into a byte[] by way of getClass().getResourceAsStream().

Parameters
key:Object

the key identifying the audio action

Returns:Action

an Action used to play the source, or null if key is null

Since
1.4
See Also
playSound(Action)
getAudioActionMapback to summary
protected ActionMap getAudioActionMap()

Returns an ActionMap containing the audio actions for this look and feel.

The returned ActionMap contains Actions that embody the ability to render an auditory cue. These auditory cues map onto user and system activities that may be useful for an end user to know about (such as a dialog box appearing).

At the appropriate time, the ComponentUI is responsible for obtaining an Action out of the ActionMap and passing it to playSound.

This method first looks up the ActionMap from the defaults using the key "AuditoryCues.actionMap".

If the value is non-null, it is returned. If the value of the default "AuditoryCues.actionMap" is null and the value of the default "AuditoryCues.cueList" is non-null, an ActionMapUIResource is created and populated. Population is done by iterating over each of the elements of the "AuditoryCues.cueList" array, and invoking createAudioAction() to create an Action for each element. The resulting Action is placed in the ActionMapUIResource, using the array element as the key. For example, if the "AuditoryCues.cueList" array contains a single-element, "audioKey", the ActionMapUIResource is created, then populated by way of actionMap.put(cueList[0], createAudioAction(cueList[0])).

If the value of the default "AuditoryCues.actionMap" is null and the value of the default "AuditoryCues.cueList" is null, an empty ActionMapUIResource is created.

Returns:ActionMap

an ActionMap containing Actions responsible for playing auditory cues

Exceptions
ClassCastException:
if the value of the default "AuditoryCues.actionMap" is not an ActionMap, or the value of the default "AuditoryCues.cueList" is not an Object[]
Since
1.4
See Also
createAudioAction, playSound(Action)
getDefaultsback to summary
public UIDefaults getDefaults()

Overrides javax.swing.LookAndFeel.getDefaults.

Returns the look and feel defaults. The returned UIDefaults is populated by invoking, in order, initClassDefaults, initSystemColorDefaults and initComponentDefaults.

While this method is public, it should only be invoked by the UIManager when the look and feel is set as the current look and feel and after initialize has been invoked.

Returns:UIDefaults

the look and feel defaults

See Also
initClassDefaults, initSystemColorDefaults, initComponentDefaults
getFocusAcceleratorKeyMaskback to summary
pack-priv static int getFocusAcceleratorKeyMask()
getUIOfTypeback to summary
pack-priv static Object getUIOfType(ComponentUI ui, Class<?> klass)

Returns the ui that is of type klass, or null if one can not be found.

initClassDefaultsback to summary
protected void initClassDefaults(UIDefaults table)

Populates table with mappings from uiClassID to the fully qualified name of the ui class. The value for a particular uiClassID is "javax.swing.plaf.basic.Basic + uiClassID". For example, the value for the uiClassID TreeUI is "javax.swing.plaf.basic.BasicTreeUI".

Parameters
table:UIDefaults

the UIDefaults instance the entries are added to

Exceptions
NullPointerException:
if table is null
See Also
javax.swing.LookAndFeel, getDefaults
initComponentDefaultsback to summary
protected void initComponentDefaults(UIDefaults table)

Populates table with the defaults for the basic look and feel.

Parameters
table:UIDefaults

the UIDefaults to add the values to

Exceptions
NullPointerException:
if table is null
initializeback to summary
public void initialize()

Overrides javax.swing.LookAndFeel.initialize.

Doc from javax.swing.LookAndFeel.initialize.

Initializes the look and feel. While this method is public, it should only be invoked by the UIManager when a look and feel is installed as the current look and feel. This method is invoked before the UIManager invokes getDefaults. This method is intended to perform any initialization for the look and feel. Subclasses should do any one-time setup they need here, rather than in a static initializer, because look and feel class objects may be loaded just to discover that isSupportedLookAndFeel() returns false.

initResourceBundleback to summary
private void initResourceBundle(UIDefaults table)

Initialize the defaults table with the name of the ResourceBundle used for getting localized defaults. Also initialize the default locale used when no locale is passed into UIDefaults.get(). The default locale should generally not be relied upon. It is here for compatibility with releases prior to 1.4.

initSystemColorDefaultsback to summary
protected void initSystemColorDefaults(UIDefaults table)

Populates table with system colors. This creates an array of name-color pairs and invokes loadSystemColors.

The name is a String that corresponds to the name of one of the static SystemColor fields in the SystemColor class. A name-color pair is created for every such SystemColor field.

The color corresponds to a hex String as understood by Color.decode. For example, one of the name-color pairs is "desktop"-"#005C5C". This corresponds to the SystemColor field desktop, with a color value of new Color(0x005C5C).

The following shows two of the name-color pairs:

  String[] nameColorPairs = new String[] {
         "desktop", "#005C5C",
   "activeCaption", "#000080" };
  loadSystemColors(table, nameColorPairs, isNativeLookAndFeel());
As previously stated, this invokes loadSystemColors with the supplied table and name-color pair array. The last argument to loadSystemColors indicates whether the value of the field in SystemColor should be used. This method passes the value of isNativeLookAndFeel() as the last argument to loadSystemColors.
Parameters
table:UIDefaults

the UIDefaults object the values are added to

Exceptions
NullPointerException:
if table is null
See Also
java.awt.SystemColor, getDefaults, loadSystemColors
installAudioActionMapback to summary
pack-priv static void installAudioActionMap(ActionMap map)

Sets the parent of the passed in ActionMap to be the audio action map.

installAWTEventListenerback to summary
pack-priv void installAWTEventListener()
loadAudioDataback to summary
private byte[] loadAudioData(final String soundFile)

Utility method that loads audio bits for the specified soundFile filename. If this method is unable to build a viable path name from the baseClass and soundFile passed into this method, it will return null.

Parameters
soundFile:String

the name of the audio file to be retrieved from disk

Returns:byte[]

A byte[] with audio data or null

Since
1.4
loadSystemColorsback to summary
protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative)

Populates table with the name-color pairs in systemColors. Refer to initSystemColorDefaults(UIDefaults) for details on the format of systemColors.

An entry is added to table for each of the name-color pairs in systemColors. The entry key is the name of the name-color pair.

The value of the entry corresponds to the color of the name-color pair. The value of the entry is calculated in one of two ways. With either approach the value is always a ColorUIResource.

If useNative is false, the color is created by using Color.decode to convert the String into a Color. If decode can not convert the String into a Color (NumberFormatException is thrown) then a ColorUIResource of black is used.

If useNative is true, the color is the value of the field in SystemColor with the same name as the name of the name-color pair. If the field is not valid, a ColorUIResource of black is used.

Parameters
table:UIDefaults

the UIDefaults object the values are added to

systemColors:String[]

array of name-color pairs as described in initSystemColorDefaults(UIDefaults)

useNative:boolean

whether the color is obtained from SystemColor or Color.decode

Exceptions
NullPointerException:
if systemColors is null; or systemColors is not empty, and table is null; or one of the names of the name-color pairs is null; or useNative is false and one of the colors of the name-color pairs is null
ArrayIndexOutOfBoundsException:
if useNative is false and systemColors.length is odd
See Also
initSystemColorDefaults(javax.swing.UIDefaults), java.awt.SystemColor, java.awt.Color#decode(String)
playSoundback to summary
protected void playSound(Action audioAction)

If necessary, invokes actionPerformed on audioAction to play a sound. The actionPerformed method is invoked if the value of the "AuditoryCues.playList" default is a non-null Object[] containing a String entry equal to the name of the audioAction.

Parameters
audioAction:Action

an Action that knows how to render the audio associated with the system or user activity that is occurring; a value of null, is ignored

Exceptions
ClassCastException:
if audioAction is non-null and the value of the default "AuditoryCues.playList" is not an Object[]
Since
1.4
playSoundback to summary
pack-priv static void playSound(JComponent c, Object actionKey)

Helper method to play a named sound.

Parameters
c:JComponent

JComponent to play the sound for.

actionKey:Object

Key for the sound.

uninitializeback to summary
public void uninitialize()

Overrides javax.swing.LookAndFeel.uninitialize.

Doc from javax.swing.LookAndFeel.uninitialize.

Uninitializes the look and feel. While this method is public, it should only be invoked by the UIManager when the look and feel is uninstalled. For example, UIManager.setLookAndFeel invokes this when the look and feel is changed.

Subclasses may choose to free up some resources here.

Annotations
@SuppressWarnings:removal
javax.swing.plaf.basic back to summary

private Class BasicLookAndFeel.AudioAction

extends AbstractAction
implements LineListener
Class Inheritance
All Implemented Interfaces
javax.sound.sampled.LineListener, java.util.EventListener

Pass the name String to the super constructor. This is used later to identify the Action and decide whether to play it or not. Store the resource String. I is used to get the audio resource. In this case, the resource is an audio file.
Since
1.4

Field Summary

Modifier and TypeField and Description
private byte[]
private String
Inherited from javax.swing.AbstractAction:
changeSupportenabled

Constructor Summary

AccessConstructor and Description
public
AudioAction(String name, String resource)

The String is the name of the Action and points to the audio resource.

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent
the event to be processed
e
)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.
private void
cancelCurrentSound(Clip clip)

If the parameter is null, or equal to the currently playing sound, then cancel the currently playing sound.

public void
update(LineEvent
a line event that describes the change
event
)

Implements javax.sound.sampled.LineListener.update.

Informs the listener that a line's state has changed.
Inherited from javax.swing.AbstractAction:
addPropertyChangeListenerclonefirePropertyChangegetKeysgetPropertyChangeListenersgetValueisEnabledputValueremovePropertyChangeListenersetEnabled

Field Detail

audioBufferback to summary
private byte[] audioBuffer
audioResourceback to summary
private String audioResource

Constructor Detail

AudioActionback to summary
public AudioAction(String name, String resource)

The String is the name of the Action and points to the audio resource. The byte[] is a buffer of the audio bits.

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Parameters
e:ActionEvent

the event to be processed

cancelCurrentSoundback to summary
private void cancelCurrentSound(Clip clip)

If the parameter is null, or equal to the currently playing sound, then cancel the currently playing sound.

updateback to summary
public void update(LineEvent event)

Implements javax.sound.sampled.LineListener.update.

Doc from javax.sound.sampled.LineListener.update.

Informs the listener that a line's state has changed. The listener can then invoke LineEvent methods to obtain information about the event.

Parameters
event:LineEvent

a line event that describes the change

javax.swing.plaf.basic back to summary

pack-priv Class BasicLookAndFeel.AWTEventHelper

extends Object
implements AWTEventListener, PrivilegedAction<Object>
Class Inheritance
All Implemented Interfaces
java.security.PrivilegedAction, java.awt.event.AWTEventListener, java.util.EventListener

This class contains listener that watches for all the mouse events that can possibly invoke popup on the component

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
eventDispatched(AWTEvent
the event to be processed
ev
)

Implements java.awt.event.AWTEventListener.eventDispatched.

Invoked when an event is dispatched in the AWT.
public Object
run()

Implements java.security.PrivilegedAction.run.

Performs the computation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AWTEventHelperback to summary
pack-priv AWTEventHelper()
Annotations
@SuppressWarnings:removal

Method Detail

eventDispatchedback to summary
public void eventDispatched(AWTEvent ev)

Implements java.awt.event.AWTEventListener.eventDispatched.

Doc from java.awt.event.AWTEventListener.eventDispatched.

Invoked when an event is dispatched in the AWT.

Parameters
ev:AWTEvent

the event to be processed

runback to summary
public Object run()

Implements java.security.PrivilegedAction.run.

Doc from java.security.PrivilegedAction.run.

Performs the computation. This method will be called by AccessController.doPrivileged after enabling privileges.

Returns:Object

a class-dependent value that may represent the results of the computation. Each class that implements PrivilegedAction should document what (if anything) this value represents.