- java.lang.Object
-
- javax.swing.LookAndFeel
-
- javax.swing.plaf.basic.BasicLookAndFeel
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MetalLookAndFeel
,SynthLookAndFeel
public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable
A base class to use in creating a look and feel for Swing.Each of the
ComponentUI
s provided byBasicLookAndFeel
derives its behavior from the defaults table. Unless otherwise noted each of theComponentUI
implementations in this package document the set of defaults they use. Unless otherwise noted the defaults are installed at the timeinstallUI
is invoked, and follow the recommendations outlined inLookAndFeel
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 seeXMLEncoder
.
-
-
Constructor Summary
Constructors Constructor Description BasicLookAndFeel()
-
Method Summary
Modifier and Type Method Description protected Action
createAudioAction(Object key)
Creates and returns anAction
used to play a sound.protected ActionMap
getAudioActionMap()
Returns anActionMap
containing the audio actions for this look and feel.UIDefaults
getDefaults()
Returns the look and feel defaults.protected void
initClassDefaults(UIDefaults table)
Populatestable
with mappings fromuiClassID
to the fully qualified name of the ui class.protected void
initComponentDefaults(UIDefaults table)
Populatestable
with the defaults for the basic look and feel.protected void
initSystemColorDefaults(UIDefaults table)
Populatestable
with system colors.protected void
loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative)
Populatestable
with thename-color
pairs insystemColors
.protected void
playSound(Action audioAction)
If necessary, invokesactionPerformed
onaudioAction
to play a sound.-
Methods declared in class javax.swing.LookAndFeel
getDescription, getDesktopPropertyValue, getDisabledIcon, getDisabledSelectedIcon, getID, getLayoutStyle, getName, getSupportsWindowDecorations, initialize, installBorder, installColors, installColorsAndFont, installProperty, isNativeLookAndFeel, isSupportedLookAndFeel, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, uninitialize, uninstallBorder
-
-
-
-
Method Detail
-
getDefaults
public UIDefaults getDefaults()
Returns the look and feel defaults. The returnedUIDefaults
is populated by invoking, in order,initClassDefaults
,initSystemColorDefaults
andinitComponentDefaults
.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 afterinitialize
has been invoked.- Overrides:
getDefaults
in classLookAndFeel
- Returns:
- the look and feel defaults
- See Also:
initClassDefaults(javax.swing.UIDefaults)
,initSystemColorDefaults(javax.swing.UIDefaults)
,initComponentDefaults(javax.swing.UIDefaults)
-
initClassDefaults
protected void initClassDefaults(UIDefaults table)
Populatestable
with mappings fromuiClassID
to the fully qualified name of the ui class. The value for a particularuiClassID
is"javax.swing.plaf.basic.Basic + uiClassID"
. For example, the value for theuiClassID
TreeUI
is"javax.swing.plaf.basic.BasicTreeUI"
.- Parameters:
table
- theUIDefaults
instance the entries are added to- Throws:
NullPointerException
- iftable
isnull
- See Also:
LookAndFeel
,getDefaults()
-
initSystemColorDefaults
protected void initSystemColorDefaults(UIDefaults table)
Populatestable
with system colors. This creates an array ofname-color
pairs and invokesloadSystemColors
.The name is a
String
that corresponds to the name of one of the staticSystemColor
fields in theSystemColor
class. A name-color pair is created for every suchSystemColor
field.The
color
corresponds to a hexString
as understood byColor.decode
. For example, one of thename-color
pairs is"desktop"-"#005C5C"
. This corresponds to theSystemColor
fielddesktop
, with a color value ofnew 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 invokesloadSystemColors
with the suppliedtable
andname-color
pair array. The last argument toloadSystemColors
indicates whether the value of the field inSystemColor
should be used. This method passes the value ofisNativeLookAndFeel()
as the last argument toloadSystemColors
.- Parameters:
table
- theUIDefaults
object the values are added to- Throws:
NullPointerException
- iftable
isnull
- See Also:
SystemColor
,getDefaults()
,loadSystemColors(javax.swing.UIDefaults, java.lang.String[], boolean)
-
loadSystemColors
protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative)
Populatestable
with thename-color
pairs insystemColors
. Refer toinitSystemColorDefaults(UIDefaults)
for details on the format ofsystemColors
.An entry is added to
table
for each of thename-color
pairs insystemColors
. The entry key is thename
of thename-color
pair.The value of the entry corresponds to the
color
of thename-color
pair. The value of the entry is calculated in one of two ways. With either approach the value is always aColorUIResource
.If
useNative
isfalse
, thecolor
is created by usingColor.decode
to convert theString
into aColor
. Ifdecode
can not convert theString
into aColor
(NumberFormatException
is thrown) then aColorUIResource
of black is used.If
useNative
istrue
, thecolor
is the value of the field inSystemColor
with the same name as thename
of thename-color
pair. If the field is not valid, aColorUIResource
of black is used.- Parameters:
table
- theUIDefaults
object the values are added tosystemColors
- array ofname-color
pairs as described ininitSystemColorDefaults(UIDefaults)
useNative
- whether the color is obtained fromSystemColor
orColor.decode
- Throws:
NullPointerException
- ifsystemColors
isnull
; orsystemColors
is not empty, andtable
isnull
; or one of the names of thename-color
pairs isnull
; oruseNative
isfalse
and one of thecolors
of thename-color
pairs isnull
ArrayIndexOutOfBoundsException
- ifuseNative
isfalse
andsystemColors.length
is odd- See Also:
initSystemColorDefaults(javax.swing.UIDefaults)
,SystemColor
,Color.decode(String)
-
initComponentDefaults
protected void initComponentDefaults(UIDefaults table)
Populatestable
with the defaults for the basic look and feel.- Parameters:
table
- theUIDefaults
to add the values to- Throws:
NullPointerException
- iftable
isnull
-
getAudioActionMap
protected ActionMap getAudioActionMap()
Returns anActionMap
containing the audio actions for this look and feel.The returned
ActionMap
containsActions
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 anAction
out of theActionMap
and passing it toplaySound
.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"
isnull
and the value of the default"AuditoryCues.cueList"
isnon-null
, anActionMapUIResource
is created and populated. Population is done by iterating over each of the elements of the"AuditoryCues.cueList"
array, and invokingcreateAudioAction()
to create anAction
for each element. The resultingAction
is placed in theActionMapUIResource
, using the array element as the key. For example, if the"AuditoryCues.cueList"
array contains a single-element,"audioKey"
, theActionMapUIResource
is created, then populated by way ofactionMap.put(cueList[0], createAudioAction(cueList[0]))
.If the value of the default
"AuditoryCues.actionMap"
isnull
and the value of the default"AuditoryCues.cueList"
isnull
, an emptyActionMapUIResource
is created.- Returns:
- an ActionMap containing
Actions
responsible for playing auditory cues - Throws:
ClassCastException
- if the value of the default"AuditoryCues.actionMap"
is not anActionMap
, or the value of the default"AuditoryCues.cueList"
is not anObject[]
- Since:
- 1.4
- See Also:
createAudioAction(java.lang.Object)
,playSound(Action)
-
createAudioAction
protected Action createAudioAction(Object key)
Creates and returns anAction
used to play a sound.If
key
isnon-null
, anAction
is created using the value from the defaults with keykey
. The value identifies the sound resource to load whenactionPerformed
is invoked on theAction
. The sound resource is loaded into abyte[]
by way ofgetClass().getResourceAsStream()
.- Parameters:
key
- the key identifying the audio action- Returns:
- an
Action
used to play the source, ornull
ifkey
isnull
- Since:
- 1.4
- See Also:
playSound(Action)
-
playSound
protected void playSound(Action audioAction)
If necessary, invokesactionPerformed
onaudioAction
to play a sound. TheactionPerformed
method is invoked if the value of the"AuditoryCues.playList"
default is anon-null
Object[]
containing aString
entry equal to the name of theaudioAction
.- Parameters:
audioAction
- an Action that knows how to render the audio associated with the system or user activity that is occurring; a value ofnull
, is ignored- Throws:
ClassCastException
- ifaudioAction
isnon-null
and the value of the default"AuditoryCues.playList"
is not anObject[]
- Since:
- 1.4
-
-