java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.OptionPaneUI
javax.swing.plaf.basic.BasicOptionPaneUI
- Direct Known Subclasses:
SynthOptionPaneUI
public class BasicOptionPaneUI extends OptionPaneUI
Provides the basic look and feel for a
JOptionPane
.
BasicMessagePaneUI
provides a means to place an icon,
message and buttons into a Container
.
Generally, the layout will look like:
------------------ | i | message | | c | message | | o | message | | n | message | ------------------ | buttons | |________________|icon is an instance of
Icon
that is wrapped inside a
JLabel
. The message is an opaque object and is tested
for the following: if the message is a Component
it is
added to the Container
, if it is an Icon
it is wrapped inside a JLabel
and added to the
Container
otherwise it is wrapped inside a JLabel
.
The above layout is used when the option pane's
ComponentOrientation
property is horizontal, left-to-right.
The layout will be adjusted appropriately for other orientations.
The Container
, message, icon, and buttons are all
determined from abstract methods.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BasicOptionPaneUI.ButtonActionListener
This class should be treated as a "protected" inner class.static class
BasicOptionPaneUI.ButtonAreaLayout
ButtonAreaLayout
behaves in a similar manner toFlowLayout
.class
BasicOptionPaneUI.PropertyChangeHandler
This class should be treated as a "protected" inner class. -
Field Summary
Fields Modifier and Type Field Description protected boolean
hasCustomComponents
This is set to true in validateComponent if a Component is contained in either the message or the buttons.protected Component
initialFocusComponent
Component to receive focus when messaged with selectInitialValue.protected JComponent
inputComponent
JComponent provide for input if optionPane.getWantsInput() returns true.static int
MinimumHeight
The mininum height ofJOptionPane
.protected Dimension
minimumSize
The size ofJOptionPane
.static int
MinimumWidth
The mininum width ofJOptionPane
.protected JOptionPane
optionPane
JOptionPane
that the receiver is providing the look and feel for.protected PropertyChangeListener
propertyChangeListener
The instance ofPropertyChangeListener
. -
Constructor Summary
Constructors Constructor Description BasicOptionPaneUI()
-
Method Summary
Modifier and Type Method Description protected void
addButtonComponents(Container container, Object[] buttons, int initialIndex)
Creates the appropriate object to represent each of the objects inbuttons
and adds it tocontainer
.protected void
addIcon(Container top)
Creates and adds a JLabel representing the icon returned fromgetIcon
totop
.protected void
addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)
Creates the appropriate object to representmsg
and places it intocontainer
.protected void
burstStringInto(Container c, String d, int maxll)
Recursively creates newJLabel
instances to representd
.boolean
containsCustomComponents(JOptionPane op)
Returns true if in the last call to validateComponent the message or buttons contained a subclass of Component.protected ActionListener
createButtonActionListener(int buttonIndex)
Constructs a new instance of aButtonActionListener
.protected Container
createButtonArea()
Creates and returns aContainer
containing the buttons.protected LayoutManager
createLayoutManager()
Returns a layout manager.protected Container
createMessageArea()
Messaged frominstallComponents
to create aContainer
containing the body of the message.protected PropertyChangeListener
createPropertyChangeListener()
Returns an instance ofPropertyChangeListener
.protected Container
createSeparator()
Returns a separator.static ComponentUI
createUI(JComponent x)
Creates a newBasicOptionPaneUI
instance.protected Object[]
getButtons()
Returns the buttons to display from theJOptionPane
the receiver is providing the look and feel for.protected Icon
getIcon()
Returns the icon from theJOptionPane
the receiver is providing the look and feel for, or the default icon as returned fromgetDefaultIcon
.protected Icon
getIconForType(int messageType)
Returns the icon to use for the passed in type.protected int
getInitialValueIndex()
Returns the initial index into the buttons to select.protected int
getMaxCharactersPerLineCount()
Returns the maximum number of characters to place on a line.protected Object
getMessage()
Returns the message to display from theJOptionPane
the receiver is providing the look and feel for.Dimension
getMinimumOptionPaneSize()
Returns the minimum size the option pane should be.Dimension
getPreferredSize(JComponent c)
Ifc
is theJOptionPane
the receiver is contained in, the preferred size that is returned is the maximum of the preferred size of theLayoutManager
for theJOptionPane
, andgetMinimumOptionPaneSize
.protected boolean
getSizeButtonsToSameWidth()
Returnstrue
, basic L&F wants all the buttons to have the same width.protected void
installComponents()
Registers components.protected void
installDefaults()
Installs default properties.protected void
installKeyboardActions()
Registers keyboard actions.protected void
installListeners()
Registers listeners.void
installUI(JComponent c)
Installs the receiver as the L&F for the passed inJOptionPane
.protected void
resetInputValue()
Sets the input value in the option pane the receiver is providing the look and feel for based on the value in the inputComponent.void
selectInitialValue(JOptionPane op)
If inputComponent is non-null, the focus is requested on that, otherwise request focus on the default valueprotected void
uninstallComponents()
Unregisters components.protected void
uninstallDefaults()
Uninstalls default properties.protected void
uninstallKeyboardActions()
Unregisters keyboard actions.protected void
uninstallListeners()
Unregisters listeners.void
uninstallUI(JComponent c)
Removes the receiver from the L&F controller of the passed in split pane.Methods declared in class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, paint, update
-
Field Details
-
MinimumWidth
public static final int MinimumWidthThe mininum width ofJOptionPane
.- See Also:
- Constant Field Values
-
MinimumHeight
public static final int MinimumHeightThe mininum height ofJOptionPane
.- See Also:
- Constant Field Values
-
optionPane
JOptionPane
that the receiver is providing the look and feel for. -
minimumSize
The size ofJOptionPane
. -
inputComponent
JComponent provide for input if optionPane.getWantsInput() returns true. -
initialFocusComponent
Component to receive focus when messaged with selectInitialValue. -
hasCustomComponents
protected boolean hasCustomComponentsThis is set to true in validateComponent if a Component is contained in either the message or the buttons. -
propertyChangeListener
The instance ofPropertyChangeListener
.
-
-
Constructor Details
-
BasicOptionPaneUI
public BasicOptionPaneUI()
-
-
Method Details
-
createUI
Creates a newBasicOptionPaneUI
instance.- Parameters:
x
- the component- Returns:
- a new
BasicOptionPaneUI
instance
-
installUI
Installs the receiver as the L&F for the passed inJOptionPane
.- Overrides:
installUI
in classComponentUI
- Parameters:
c
- the component where this UI delegate is being installed- See Also:
ComponentUI.uninstallUI(javax.swing.JComponent)
,JComponent.setUI(javax.swing.plaf.ComponentUI)
,JComponent.updateUI()
-
uninstallUI
Removes the receiver from the L&F controller of the passed in split pane.- Overrides:
uninstallUI
in classComponentUI
- Parameters:
c
- the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- See Also:
ComponentUI.installUI(javax.swing.JComponent)
,JComponent.updateUI()
-
installDefaults
protected void installDefaults()Installs default properties. -
uninstallDefaults
protected void uninstallDefaults()Uninstalls default properties. -
installComponents
protected void installComponents()Registers components. -
uninstallComponents
protected void uninstallComponents()Unregisters components. -
createLayoutManager
Returns a layout manager.- Returns:
- a layout manager
-
installListeners
protected void installListeners()Registers listeners. -
uninstallListeners
protected void uninstallListeners()Unregisters listeners. -
createPropertyChangeListener
Returns an instance ofPropertyChangeListener
.- Returns:
- an instance of
PropertyChangeListener
-
installKeyboardActions
protected void installKeyboardActions()Registers keyboard actions. -
uninstallKeyboardActions
protected void uninstallKeyboardActions()Unregisters keyboard actions. -
getMinimumOptionPaneSize
Returns the minimum size the option pane should be. Primarily provided for subclassers wishing to offer a different minimum size.- Returns:
- the minimum size of the option pane
-
getPreferredSize
Ifc
is theJOptionPane
the receiver is contained in, the preferred size that is returned is the maximum of the preferred size of theLayoutManager
for theJOptionPane
, andgetMinimumOptionPaneSize
.- Overrides:
getPreferredSize
in classComponentUI
- Parameters:
c
- the component whose preferred size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- Returns:
- a
Dimension
object containing given component's preferred size appropriate for the look and feel - See Also:
JComponent.getPreferredSize()
,LayoutManager.preferredLayoutSize(java.awt.Container)
-
createMessageArea
Messaged frominstallComponents
to create aContainer
containing the body of the message. The icon is the created by callingaddIcon
.- Returns:
- a instance of
Container
-
addMessageComponents
protected void addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)Creates the appropriate object to representmsg
and places it intocontainer
. Ifmsg
is an instance ofComponent
, it is added directly; if it is anIcon
, aJLabel
is created to represent it; otherwise, aJLabel
is created for the string. Ifmsg
is an Object[], this method will be recursively invoked for the children.internallyCreated
istrue
ifmsg
is an instance ofComponent
and was created internally by this method (this is used to correctly sethasCustomComponents
only ifinternallyCreated
isfalse
).- Parameters:
container
- a containercons
- an instance ofGridBagConstraints
msg
- a messagemaxll
- a maximum lengthinternallyCreated
-true
if the component was internally created
-
getMessage
Returns the message to display from theJOptionPane
the receiver is providing the look and feel for.- Returns:
- the message to display
-
addIcon
Creates and adds a JLabel representing the icon returned fromgetIcon
totop
. This is messaged fromcreateMessageArea
.- Parameters:
top
- a container
-
getIcon
Returns the icon from theJOptionPane
the receiver is providing the look and feel for, or the default icon as returned fromgetDefaultIcon
.- Returns:
- the icon
-
getIconForType
Returns the icon to use for the passed in type.- Parameters:
messageType
- a type of message- Returns:
- the icon to use for the passed in type
-
getMaxCharactersPerLineCount
protected int getMaxCharactersPerLineCount()Returns the maximum number of characters to place on a line.- Returns:
- the maximum number of characters to place on a line
-
burstStringInto
Recursively creates newJLabel
instances to representd
. EachJLabel
instance is added toc
.- Parameters:
c
- a containerd
- a textmaxll
- a maximum length of a text
-
createSeparator
Returns a separator.- Returns:
- a separator
-
createButtonArea
Creates and returns aContainer
containing the buttons. The buttons are created by callinggetButtons
.- Returns:
- a
Container
containing the buttons
-
addButtonComponents
Creates the appropriate object to represent each of the objects inbuttons
and adds it tocontainer
. This differs from addMessageComponents in that it will recurse onbuttons
and that if button is not a Component it will create an instance of JButton.- Parameters:
container
- a containerbuttons
- an array of buttonsinitialIndex
- an initial index
-
createButtonActionListener
Constructs a new instance of aButtonActionListener
.- Parameters:
buttonIndex
- an index of the button- Returns:
- a new instance of a
ButtonActionListener
-
getButtons
Returns the buttons to display from theJOptionPane
the receiver is providing the look and feel for. If theJOptionPane
has options set, they will be provided, otherwise if the optionType isYES_NO_OPTION
,yesNoOptions
is returned, if the type isYES_NO_CANCEL_OPTION
yesNoCancelOptions
is returned, otherwisedefaultButtons
are returned.- Returns:
- the buttons to display from the JOptionPane
-
getSizeButtonsToSameWidth
protected boolean getSizeButtonsToSameWidth()Returnstrue
, basic L&F wants all the buttons to have the same width.- Returns:
true
if all the buttons should have the same width
-
getInitialValueIndex
protected int getInitialValueIndex()Returns the initial index into the buttons to select. The index is calculated from the initial value from the JOptionPane and options of the JOptionPane or 0.- Returns:
- the initial index into the buttons to select
-
resetInputValue
protected void resetInputValue()Sets the input value in the option pane the receiver is providing the look and feel for based on the value in the inputComponent. -
selectInitialValue
If inputComponent is non-null, the focus is requested on that, otherwise request focus on the default value- Specified by:
selectInitialValue
in classOptionPaneUI
- Parameters:
op
- aJOptionPane
-
containsCustomComponents
Returns true if in the last call to validateComponent the message or buttons contained a subclass of Component.- Specified by:
containsCustomComponents
in classOptionPaneUI
- Parameters:
op
- aJOptionPane
- Returns:
true
if the givenJOptionPane
contains user createdComponent
s
-