Class BasicOptionPaneUI
java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.OptionPaneUI
javax.swing.plaf.basic.BasicOptionPaneUI
- Direct Known Subclasses:
SynthOptionPaneUI
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 ClassesModifier and TypeClassDescriptionclassThis class should be treated as a "protected" inner class.static classButtonAreaLayoutbehaves in a similar manner toFlowLayout.classThis class should be treated as a "protected" inner class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanThis is set to true in validateComponent if a Component is contained in either the message or the buttons.protected ComponentComponent to receive focus when messaged with selectInitialValue.protected JComponentJComponent provide for input if optionPane.getWantsInput() returns true.static final intThe minimum height ofJOptionPane.protected DimensionThe size ofJOptionPane.static final intThe minimum width ofJOptionPane.protected JOptionPaneJOptionPanethat the receiver is providing the look and feel for.protected PropertyChangeListenerThe instance ofPropertyChangeListener. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddButtonComponents(Container container, Object[] buttons, int initialIndex) Creates the appropriate object to represent each of the objects inbuttonsand adds it tocontainer.protected voidCreates and adds a JLabel representing the icon returned fromgetIcontotop.protected voidaddMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated) Creates the appropriate object to representmsgand places it intocontainer.protected voidburstStringInto(Container c, String d, int maxll) Recursively creates newJLabelinstances to representd.booleanReturns true if in the last call to validateComponent the message or buttons contained a subclass of Component.protected ActionListenercreateButtonActionListener(int buttonIndex) Constructs a new instance of aButtonActionListener.protected ContainerCreates and returns aContainercontaining the buttons.protected LayoutManagerReturns a layout manager.protected ContainerMessaged frominstallComponentsto create aContainercontaining the body of the message.protected PropertyChangeListenerReturns an instance ofPropertyChangeListener.protected ContainerReturns a separator.static ComponentUICreates a newBasicOptionPaneUIinstance.protected Object[]Returns the buttons to display from theJOptionPanethe receiver is providing the look and feel for.protected IcongetIcon()Returns the icon from theJOptionPanethe receiver is providing the look and feel for, or the default icon as returned fromgetDefaultIcon.protected IcongetIconForType(int messageType) Returns the icon to use for the passed in type.protected intReturns the initial index into the buttons to select.protected intReturns the maximum number of characters to place on a line.protected ObjectReturns the message to display from theJOptionPanethe receiver is providing the look and feel for.Returns the minimum size the option pane should be.Ifcis theJOptionPanethe receiver is contained in, the preferred size that is returned is the maximum of the preferred size of theLayoutManagerfor theJOptionPane, andgetMinimumOptionPaneSize.protected booleanReturnstrue, basic L&F wants all the buttons to have the same width.protected voidRegisters components.protected voidInstalls default properties.protected voidRegisters keyboard actions.protected voidRegisters listeners.voidInstalls the receiver as the L&F for the passed inJOptionPane.protected voidSets the input value in the option pane the receiver is providing the look and feel for based on the value in the inputComponent.voidIf inputComponent is non-null, the focus is requested on that, otherwise request focus on the default valueprotected voidUnregisters components.protected voidUninstalls default properties.protected voidUnregisters keyboard actions.protected voidUnregisters listeners.voidRemoves 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 minimum width ofJOptionPane.- See Also:
-
MinimumHeight
public static final int MinimumHeightThe minimum height ofJOptionPane.- See Also:
-
optionPane
JOptionPanethat 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()Constructs aBasicOptionPaneUI.
-
-
Method Details
-
createUI
Creates a newBasicOptionPaneUIinstance.- Parameters:
x- the component- Returns:
- a new
BasicOptionPaneUIinstance
-
installUI
Installs the receiver as the L&F for the passed inJOptionPane.- Overrides:
installUIin classComponentUI- Parameters:
c- the component where this UI delegate is being installed- See Also:
-
uninstallUI
Removes the receiver from the L&F controller of the passed in split pane.- Overrides:
uninstallUIin 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:
-
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
-
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
Ifcis theJOptionPanethe receiver is contained in, the preferred size that is returned is the maximum of the preferred size of theLayoutManagerfor theJOptionPane, andgetMinimumOptionPaneSize.- Overrides:
getPreferredSizein 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
Dimensionobject containing given component's preferred size appropriate for the look and feel - See Also:
-
createMessageArea
Messaged frominstallComponentsto create aContainercontaining 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 representmsgand places it intocontainer. Ifmsgis an instance ofComponent, it is added directly; if it is anIcon, aJLabelis created to represent it; otherwise, aJLabelis created for the string. Ifmsgis an Object[], this method will be recursively invoked for the children.internallyCreatedistrueifmsgis an instance ofComponentand was created internally by this method (this is used to correctly sethasCustomComponentsonly ifinternallyCreatedisfalse).- Parameters:
container- a containercons- an instance ofGridBagConstraintsmsg- a messagemaxll- a maximum lengthinternallyCreated-trueif the component was internally created
-
getMessage
Returns the message to display from theJOptionPanethe receiver is providing the look and feel for.- Returns:
- the message to display
-
addIcon
Creates and adds a JLabel representing the icon returned fromgetIcontotop. This is messaged fromcreateMessageArea.- Parameters:
top- a container
-
getIcon
Returns the icon from theJOptionPanethe 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
-
createSeparator
-
createButtonArea
Creates and returns aContainercontaining the buttons. The buttons are created by callinggetButtons.- Returns:
- a
Containercontaining the buttons
-
addButtonComponents
Creates the appropriate object to represent each of the objects inbuttonsand adds it tocontainer. This differs from addMessageComponents in that it will recurse onbuttonsand 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 theJOptionPanethe receiver is providing the look and feel for. If theJOptionPanehas options set, they will be provided, otherwise if the optionType isYES_NO_OPTION,yesNoOptionsis returned, if the type isYES_NO_CANCEL_OPTIONyesNoCancelOptionsis returned, otherwisedefaultButtonsare 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:
trueif 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:
selectInitialValuein 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:
containsCustomComponentsin classOptionPaneUI- Parameters:
op- aJOptionPane- Returns:
trueif the givenJOptionPanecontains user createdComponents
-