public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable
Each of the ComponentUI
s 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 XMLEncoder
.
Constructor and Description |
---|
BasicLookAndFeel() |
Modifier and Type | Method and Description |
---|---|
protected Action |
createAudioAction(Object key)
Creates and returns an
Action used to play a sound. |
protected ActionMap |
getAudioActionMap()
Returns an
ActionMap containing the audio actions
for this look and feel. |
UIDefaults |
getDefaults()
Returns the look and feel defaults.
|
protected void |
initClassDefaults(UIDefaults table)
Populates
table with mappings from uiClassID to the
fully qualified name of the ui class. |
protected void |
initComponentDefaults(UIDefaults table)
Populates
table with the defaults for the basic look and
feel. |
void |
initialize()
Initializes the look and feel.
|
protected void |
initSystemColorDefaults(UIDefaults table)
Populates
table with system colors. |
protected void |
loadSystemColors(UIDefaults table,
String[] systemColors,
boolean useNative)
Populates
table with the name-color pairs in
systemColors . |
protected void |
playSound(Action audioAction)
If necessary, invokes
actionPerformed on
audioAction to play a sound. |
void |
uninitialize()
Uninitializes the look and feel.
|
getDescription, getDesktopPropertyValue, getDisabledIcon, getDisabledSelectedIcon, getID, getLayoutStyle, getName, getSupportsWindowDecorations, installBorder, installColors, installColorsAndFont, installProperty, isNativeLookAndFeel, isSupportedLookAndFeel, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, uninstallBorder
public UIDefaults getDefaults()
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.
getDefaults
in class LookAndFeel
initClassDefaults(javax.swing.UIDefaults)
,
initSystemColorDefaults(javax.swing.UIDefaults)
,
initComponentDefaults(javax.swing.UIDefaults)
public void initialize()
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
.initialize
in class LookAndFeel
LookAndFeel.uninitialize()
,
UIManager.setLookAndFeel(javax.swing.LookAndFeel)
public void uninitialize()
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.
uninitialize
in class LookAndFeel
LookAndFeel.initialize()
,
UIManager.setLookAndFeel(javax.swing.LookAndFeel)
protected void initClassDefaults(UIDefaults table)
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"
.table
- the UIDefaults
instance the entries are
added toNullPointerException
- if table
is null
LookAndFeel
,
getDefaults()
protected void initSystemColorDefaults(UIDefaults table)
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
.table
- the UIDefaults
object the values are added toNullPointerException
- if table
is null
SystemColor
,
getDefaults()
,
loadSystemColors(javax.swing.UIDefaults, java.lang.String[], boolean)
protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative)
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.
table
- the UIDefaults
object the values are added tosystemColors
- array of name-color
pairs as described
in initSystemColorDefaults(UIDefaults)
useNative
- whether the color is obtained from SystemColor
or Color.decode
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 oddinitSystemColorDefaults(javax.swing.UIDefaults)
,
SystemColor
,
Color.decode(String)
protected void initComponentDefaults(UIDefaults table)
table
with the defaults for the basic look and
feel.table
- the UIDefaults
to add the values toNullPointerException
- if table
is null
protected ActionMap getAudioActionMap()
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.
Actions
responsible for playing auditory cuesClassCastException
- if the value of the
default "AuditoryCues.actionMap"
is not an
ActionMap
, or the value of the default
"AuditoryCues.cueList"
is not an Object[]
createAudioAction(java.lang.Object)
,
playSound(Action)
protected Action createAudioAction(Object key)
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()
.
key
- the key identifying the audio actionAction
used to play the source, or null
if key
is null
playSound(Action)
protected void playSound(Action audioAction)
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
.audioAction
- an Action that knows how to render the audio
associated with the system or user activity
that is occurring; a value of null
, is
ignoredClassCastException
- if audioAction
is non-null
and the value of the default "AuditoryCues.playList"
is not an Object[]
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.