- 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 JavaBeansTM has been added to the
java.beans
package. Please seeXMLEncoder
.
-
-
Constructor Summary
Constructors Constructor and Description BasicLookAndFeel()
-
Method Summary
Methods Modifier and Type Method and 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.void
initialize()
Initializes the 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.void
uninitialize()
Uninitializes the look and feel.-
Methods inherited from class javax.swing.LookAndFeel
getDescription, getDesktopPropertyValue, getDisabledIcon, getDisabledSelectedIcon, getID, getLayoutStyle, getName, getSupportsWindowDecorations, installBorder, installColors, installColorsAndFont, installProperty, isNativeLookAndFeel, isSupportedLookAndFeel, loadKeyBindings, makeComponentInputMap, makeIcon, makeInputMap, makeKeyBindings, provideErrorFeedback, toString, 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)
-
initialize
public void initialize()
Initializes the look and feel. While this method is public, it should only be invoked by theUIManager
when a look and feel is installed as the current look and feel. This method is invoked before theUIManager
invokesgetDefaults
. 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 thatisSupportedLookAndFeel()
returnsfalse
.- Overrides:
initialize
in classLookAndFeel
- See Also:
LookAndFeel.uninitialize()
,UIManager.setLookAndFeel(javax.swing.LookAndFeel)
-
uninitialize
public void uninitialize()
Uninitializes the look and feel. While this method is public, it should only be invoked by theUIManager
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.
- Overrides:
uninitialize
in classLookAndFeel
- See Also:
LookAndFeel.initialize()
,UIManager.setLookAndFeel(javax.swing.LookAndFeel)
-
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
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/12/2024 09:16:51 Cette version de la page est en cache (à la date du 22/12/2024 09:16:51) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 01/09/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/plaf/basic/BasicLookAndFeel.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.