javax.swing.plaf.basic

Class BasicOptionPaneUI

public class BasicOptionPaneUI extends OptionPaneUI

This class is the UI delegate for JOptionPane in the Basic Look and Feel.
Nested Class Summary
classBasicOptionPaneUI.ButtonActionListener
This is a helper class that listens to the buttons located at the bottom of the JOptionPane.
static classBasicOptionPaneUI.ButtonAreaLayout
This helper layout manager is responsible for the layout of the button area.
classBasicOptionPaneUI.PropertyChangeHandler
This helper class handles property change events from the JOptionPane.
Field Summary
protected booleanhasCustomComponents
Whether the JOptionPane contains custom components.
protected ComponentinitialFocusComponent
The button that will receive focus based on initialValue when no input component is present.
protected JComponentinputComponent
The component that receives input when the JOptionPane needs it.
protected DimensionminimumSize
The minimum dimensions of the JOptionPane.
static intMinimumHeight
The minimum height for JOptionPanes.
static intMinimumWidth
The minimum width for JOptionPanes.
protected JOptionPaneoptionPane
The JOptionPane this UI delegate is used for.
protected PropertyChangeListenerpropertyChangeListener
The propertyChangeListener for the JOptionPane.
Constructor Summary
BasicOptionPaneUI()
Creates a new BasicOptionPaneUI object.
Method Summary
protected voidaddButtonComponents(Container container, Object[] buttons, int initialIndex)
This method is messaged to add the buttons to the given container.
protected voidaddIcon(Container top)
This method adds the appropriate icon the given container.
protected voidaddMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)
This method creates the proper object (if necessary) to represent msg.
protected voidburstStringInto(Container c, String d, int maxll)
This method creates instances of d (recursively if necessary based on maxll) and adds to c.
booleancontainsCustomComponents(JOptionPane op)
This method returns true if the given JOptionPane contains custom components.
protected ActionListenercreateButtonActionListener(int buttonIndex)
This method creates a button action listener for the given button index.
protected ContainercreateButtonArea()
This method creates the button area.
protected LayoutManagercreateLayoutManager()
This method creates a new LayoutManager for the button area.
protected ContainercreateMessageArea()
This method creates the message area.
protected PropertyChangeListenercreatePropertyChangeListener()
This method creates a new PropertyChangeListener for listening to the JOptionPane.
protected ContainercreateSeparator()
This method creates a Container that will separate the message and button areas.
static ComponentUIcreateUI(JComponent x)
This method creates a new BasicOptionPaneUI for the given component.
protected Object[]getButtons()
This method returns the buttons for the JOptionPane.
protected IcongetIcon()
This method will return the icon the user has set or the icon that will be used based on message type.
protected IcongetIconForType(int messageType)
This method returns the icon for the given messageType.
protected intgetInitialValueIndex()
This method returns the index of the initialValue in the options array.
protected intgetMaxCharactersPerLineCount()
This method returns the maximum number of characters that should be placed on a line.
DimensiongetMaximumSize(JComponent c)
This method returns the maximum size.
protected ObjectgetMessage()
This method returns the message of the JOptionPane.
DimensiongetMinimumOptionPaneSize()
This method returns the minimum size of the JOptionPane.
DimensiongetMinimumSize(JComponent c)
This method returns the minimum size.
DimensiongetPreferredSize(JComponent c)
This method returns the preferred size of the JOptionPane.
protected booleangetSizeButtonsToSameWidth()
This method returns whether all buttons should have the same width.
protected voidinstallComponents()
This method installs components for the JOptionPane.
protected voidinstallDefaults()
This method installs defaults for the JOptionPane.
protected voidinstallKeyboardActions()
This method installs keyboard actions for the JOptionpane.
protected voidinstallListeners()
This method installs listeners for the JOptionPane.
voidinstallUI(JComponent c)
This method installs the UI for the JOptionPane.
protected voidresetInputValue()
Changes the inputValue property in the JOptionPane based on the current value of the inputComponent.
voidselectInitialValue(JOptionPane op)
This method requests focus to the inputComponent (if one is present) and the initialFocusComponent otherwise.
protected voiduninstallComponents()
This method uninstalls all the components in the JOptionPane.
protected voiduninstallDefaults()
This method uninstalls the defaults for the JOptionPane.
protected voiduninstallKeyboardActions()
This method uninstalls keyboard actions for the JOptionPane.
protected voiduninstallListeners()
This method uninstalls listeners for the JOptionPane.
voiduninstallUI(JComponent c)
This method uninstalls the UI for the given JComponent.

Field Detail

hasCustomComponents

protected boolean hasCustomComponents
Whether the JOptionPane contains custom components.

initialFocusComponent

protected Component initialFocusComponent
The button that will receive focus based on initialValue when no input component is present. If an input component is present, then the input component will receive focus instead.

inputComponent

protected JComponent inputComponent
The component that receives input when the JOptionPane needs it.

minimumSize

protected Dimension minimumSize
The minimum dimensions of the JOptionPane.

MinimumHeight

public static final int MinimumHeight
The minimum height for JOptionPanes.

MinimumWidth

public static final int MinimumWidth
The minimum width for JOptionPanes.

optionPane

protected JOptionPane optionPane
The JOptionPane this UI delegate is used for.

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
The propertyChangeListener for the JOptionPane.

Constructor Detail

BasicOptionPaneUI

public BasicOptionPaneUI()
Creates a new BasicOptionPaneUI object.

Method Detail

addButtonComponents

protected void addButtonComponents(Container container, Object[] buttons, int initialIndex)
This method is messaged to add the buttons to the given container.

Parameters: container The container to add components to. buttons The buttons to add. (If it is an instance of component, the Object is added directly. If it is an instance of Icon, it is packed into a label and added. For all other cases, the string representation of the Object is retreived and packed into a label.) initialIndex The index of the component that is the initialValue.

addIcon

protected void addIcon(Container top)
This method adds the appropriate icon the given container.

Parameters: top The container to add an icon to.

addMessageComponents

protected void addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)
This method creates the proper object (if necessary) to represent msg. (If msg is an instance of Component, it will add it directly. If it is an icon, then it will pack it in a label and add it. Otherwise, it gets treated as a string. If the string is longer than maxll, a box is created and the burstStringInto is called with the box as the container. The box is then added to the given container. Otherwise, the string is packed in a label and placed in the given container.) This method is also used for adding the inputComponent to the container.

Parameters: container The container to add to. cons The constraints when adding. msg The message to add. maxll The max line length. internallyCreated Whether the msg is internally created.

burstStringInto

protected void burstStringInto(Container c, String d, int maxll)
This method creates instances of d (recursively if necessary based on maxll) and adds to c.

Parameters: c The container to add to. d The string to burst. maxll The max line length.

containsCustomComponents

public boolean containsCustomComponents(JOptionPane op)
This method returns true if the given JOptionPane contains custom components.

Parameters: op The JOptionPane to check.

Returns: True if the JOptionPane contains custom components.

createButtonActionListener

protected ActionListener createButtonActionListener(int buttonIndex)
This method creates a button action listener for the given button index.

Parameters: buttonIndex The index of the button in components.

Returns: A new ButtonActionListener.

createButtonArea

protected Container createButtonArea()
This method creates the button area.

Returns: A new Button Area.

createLayoutManager

protected LayoutManager createLayoutManager()
This method creates a new LayoutManager for the button area.

Returns: A new LayoutManager for the button area.

createMessageArea

protected Container createMessageArea()
This method creates the message area.

Returns: A new message area.

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
This method creates a new PropertyChangeListener for listening to the JOptionPane.

Returns: A new PropertyChangeListener.

createSeparator

protected Container createSeparator()
This method creates a Container that will separate the message and button areas.

Returns: A Container that will separate the message and button areas.

createUI

public static ComponentUI createUI(JComponent x)
This method creates a new BasicOptionPaneUI for the given component.

Parameters: x The component to create a UI for.

Returns: A new BasicOptionPaneUI.

getButtons

protected Object[] getButtons()
This method returns the buttons for the JOptionPane. If no options are set, a set of options will be created based upon the optionType.

Returns: The buttons that will be added.

getIcon

protected Icon getIcon()
This method will return the icon the user has set or the icon that will be used based on message type.

Returns: The icon to use in the JOptionPane.

getIconForType

protected Icon getIconForType(int messageType)
This method returns the icon for the given messageType.

Parameters: messageType The type of message.

Returns: The icon for the given messageType.

getInitialValueIndex

protected int getInitialValueIndex()
This method returns the index of the initialValue in the options array.

Returns: The index of the initalValue.

getMaxCharactersPerLineCount

protected int getMaxCharactersPerLineCount()
This method returns the maximum number of characters that should be placed on a line.

Returns: The maximum number of characteres that should be placed on a line.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
This method returns the maximum size.

Parameters: c The JComponent to measure.

Returns: The maximum size.

getMessage

protected Object getMessage()
This method returns the message of the JOptionPane.

Returns: The message.

getMinimumOptionPaneSize

public Dimension getMinimumOptionPaneSize()
This method returns the minimum size of the JOptionPane.

Returns: The minimum size.

getMinimumSize

public Dimension getMinimumSize(JComponent c)
This method returns the minimum size.

Parameters: c The JComponent to measure.

Returns: The minimum size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
This method returns the preferred size of the JOptionPane. The preferred size is the maximum of the size desired by the layout and the minimum size.

Parameters: c The JComponent to measure.

Returns: The preferred size.

getSizeButtonsToSameWidth

protected boolean getSizeButtonsToSameWidth()
This method returns whether all buttons should have the same width.

Returns: Whether all buttons should have the same width.

installComponents

protected void installComponents()
This method installs components for the JOptionPane.

installDefaults

protected void installDefaults()
This method installs defaults for the JOptionPane.

installKeyboardActions

protected void installKeyboardActions()
This method installs keyboard actions for the JOptionpane.

installListeners

protected void installListeners()
This method installs listeners for the JOptionPane.

installUI

public void installUI(JComponent c)
This method installs the UI for the JOptionPane.

Parameters: c The JComponent to install the UI for.

resetInputValue

protected void resetInputValue()
Changes the inputValue property in the JOptionPane based on the current value of the inputComponent.

selectInitialValue

public void selectInitialValue(JOptionPane op)
This method requests focus to the inputComponent (if one is present) and the initialFocusComponent otherwise.

Parameters: op The JOptionPane.

uninstallComponents

protected void uninstallComponents()
This method uninstalls all the components in the JOptionPane.

uninstallDefaults

protected void uninstallDefaults()
This method uninstalls the defaults for the JOptionPane.

uninstallKeyboardActions

protected void uninstallKeyboardActions()
This method uninstalls keyboard actions for the JOptionPane.

uninstallListeners

protected void uninstallListeners()
This method uninstalls listeners for the JOptionPane.

uninstallUI

public void uninstallUI(JComponent c)
This method uninstalls the UI for the given JComponent.

Parameters: c The JComponent to uninstall for.