/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Provides the basic look and feel for a <code>JOptionPane</code>.
* <code>BasicMessagePaneUI</code> provides a means to place an icon,
* message and buttons into a <code>Container</code>.
* Generally, the layout will look like:<p>
* <pre>
* ------------------
* | i | message |
* | c | message |
* | o | message |
* | n | message |
* ------------------
* | buttons |
* |________________|
* </pre>
* icon is an instance of <code>Icon</code> that is wrapped inside a
* <code>JLabel</code>. The message is an opaque object and is tested
* for the following: if the message is a <code>Component</code> it is
* added to the <code>Container</code>, if it is an <code>Icon</code>
* it is wrapped inside a <code>JLabel</code> and added to the
* <code>Container</code> otherwise it is wrapped inside a <code>JLabel</code>.
* <p>
* The above layout is used when the option pane's
* <code>ComponentOrientation</code> property is horizontal, left-to-right.
* The layout will be adjusted appropriately for other orientations.
* <p>
* The <code>Container</code>, message, icon, and buttons are all
* determined from abstract methods.
*
* @author James Gosling
* @author Scott Violet
* @author Amy Fowler
*/
/**
* <code>JOptionPane</code> that the receiver is providing the
* look and feel for.
*/
/** JComponent provide for input if optionPane.getWantsInput() returns
* true. */
/** Component to receive focus when messaged with selectInitialValue. */
/** This is set to true in validateComponent if a Component is contained
* in either the message or the buttons. */
protected boolean hasCustomComponents;
static {
new GetPropertyAction("line.separator"));
newline = "\n";
}
}
}
/**
* Creates a new BasicOptionPaneUI instance.
*/
return new BasicOptionPaneUI();
}
/**
* Installs the receiver as the L&F for the passed in
* <code>JOptionPane</code>.
*/
optionPane = (JOptionPane)c;
}
/**
* Removes the receiver from the L&F controller of the passed in split
* pane.
*/
optionPane = null;
}
protected void installDefaults() {
"OptionPane.foreground", "OptionPane.font");
}
protected void uninstallDefaults() {
}
protected void installComponents() {
}
}
protected void uninstallComponents() {
hasCustomComponents = false;
}
}
protected void installListeners() {
}
}
protected void uninstallListeners() {
if (propertyChangeListener != null) {
}
}
return getHandler();
}
}
return handler;
}
protected void installKeyboardActions() {
"OptionPane.actionMap");
}
protected void uninstallKeyboardActions() {
}
optionPane, this, "OptionPane.windowBindings");
}
}
return null;
}
/**
* Returns the minimum size the option pane should be. Primarily
* provided for subclassers wishing to offer a different minimum size.
*/
if (minimumSize == null) {
}
}
/**
* If <code>c</code> is the <code>JOptionPane</code> the receiver
* is contained in, the preferred
* size that is returned is the maximum of the preferred size of
* the <code>LayoutManager</code> for the <code>JOptionPane</code>, and
* <code>getMinimumOptionPaneSize</code>.
*/
if (c == optionPane) {
return new Dimension
return lmSize;
}
return ourMin;
}
return null;
}
/**
* Messaged from installComponents to create a Container containing the
* body of the message. The icon is the created by calling
* <code>addIcon</code>.
*/
"OptionPane.messageAreaBorder");
}
/* Fill the body. */
}
getMaxCharactersPerLineCount(), false);
return top;
}
/**
* Creates the appropriate object to represent <code>msg</code> and
* places it into <code>container</code>. If <code>msg</code> is an
* instance of Component, it is added directly, if it is an Icon,
* a JLabel is created to represent it, otherwise a JLabel is
* created for the string, if <code>d</code> is an Object[], this
* method will be recursively invoked for the children.
* <code>internallyCreated</code> is true if Objc is an instance
* of Component and was created internally by this method (this is
* used to correctly set hasCustomComponents only if !internallyCreated).
*/
boolean internallyCreated) {
return;
}
// To workaround problem where Gridbad will set child
// to its minimum size if its preferred size will not fit
// within allocated cells
} else {
}
if (!internallyCreated) {
hasCustomComponents = true;
}
}
} else {
if (len <= 0) {
return;
}
int nl;
int nll = 0;
nll = 2;
nll = 1;
}
if (nl >= 0) {
// break up newlines
if (nl == 0) {
public Dimension getPreferredSize() {
if (f != null) {
}
}
};
true);
} else {
maxll, false);
}
false);
c.setName("OptionPane.verticalBox");
burstStringInto(c, s, maxll);
} else {
}
}
}
/**
* Returns the message to display from the JOptionPane the receiver is
* providing the look and feel for.
*/
if (optionPane != null) {
if (optionPane.getWantsInput()) {
/* Create a user component to capture the input. If the
selectionValues are non null the component and there
are < 20 values it'll be a combobox, if non null and
>= 20, it'll be a list, otherwise it'll be a textfield. */
}
if (inputValue != null) {
}
} else {
if(inputValue != null)
}
} else {
if (inputValue != null) {
}
}
Object[] newMessage;
} else {
}
return newMessage;
}
return optionPane.getMessage();
}
return null;
}
/**
* Creates and adds a JLabel representing the icon returned from
* <code>getIcon</code> to <code>top</code>. This is messaged from
* <code>createMessageArea</code>
*/
/* Create the icon. */
}
}
/**
* Returns the icon from the JOptionPane the receiver is providing
* the look and feel for, or the default icon as returned from
* <code>getDefaultIcon</code>.
*/
return mIcon;
}
/**
* Returns the icon to use for the passed in type.
*/
return null;
switch(messageType) {
case 0:
propertyName = "OptionPane.errorIcon";
break;
case 1:
propertyName = "OptionPane.informationIcon";
break;
case 2:
propertyName = "OptionPane.warningIcon";
break;
case 3:
propertyName = "OptionPane.questionIcon";
break;
}
if (propertyName != null) {
}
return null;
}
/**
* Returns the maximum number of characters to place on a line.
*/
protected int getMaxCharactersPerLineCount() {
return optionPane.getMaxCharactersPerLineCount();
}
/**
* Recursively creates new JLabel instances to represent <code>d</code>.
* Each JLabel instance is added to <code>c</code>.
*/
// Primitive line wrapping
if (len <= 0)
return;
if (p <= 0)
if (p > 0 && p < len) {
return;
}
}
}
return null;
}
/**
* Creates and returns a Container containing the buttons. The buttons
* are created by calling <code>getButtons</code>.
*/
"OptionPane.buttonAreaBorder");
}
"OptionPane.sameSizeButtons", true),
6),
false)));
return bottom;
}
/**
* Creates the appropriate object to represent each of the objects in
* <code>buttons</code> and adds it to <code>container</code>. This
* differs from addMessageComponents in that it will recurse on
* <code>buttons</code> and that if button is not a Component
* it will create an instance of JButton.
*/
int initialIndex) {
boolean sizeButtonsToSame = getSizeButtonsToSameWidth();
boolean createdAll = true;
int maxWidth = 0;
if (sizeButtonsToSame) {
}
createdAll = false;
hasCustomComponents = true;
} else {
if (button instanceof ButtonFactory) {
}
else
optionPane, this, "OptionPane.buttonClickThreshhold",
0));
if (buttonListener != null) {
}
}
if (sizeButtonsToSame && createdAll &&
(newComponent instanceof JButton)) {
}
if (counter == initialIndex) {
if (initialFocusComponent instanceof JButton) {
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() &
}
}
}
});
}
}
}
/* Set the padding, windows seems to use 8 if <= 2 components,
otherwise 4 is used. It may actually just be the size of the
buttons is always the same, not sure. */
"OptionPane.setButtonMargin", true) && sizeButtonsToSame &&
createdAll) {
int padSize;
}
}
}
}
return new ButtonActionListener(buttonIndex);
}
/**
* Returns the buttons to display from the JOptionPane the receiver is
* providing the look and feel for. If the JOptionPane has options
* set, they will be provided, otherwise if the optionType is
* YES_NO_OPTION, yesNoOptions is returned, if the type is
* YES_NO_CANCEL_OPTION yesNoCancelOptions is returned, otherwise
* defaultButtons are returned.
*/
if (optionPane != null) {
if (suppliedOptions == null) {
int minimumWidth =
"OptionPane.buttonMinimumWidth",-1);
getMnemonic("OptionPane.yesButtonMnemonic", l),
"OptionPane.yesIcon"), minimumWidth);
getMnemonic("OptionPane.noButtonMnemonic", l),
"OptionPane.noIcon"), minimumWidth);
getMnemonic("OptionPane.yesButtonMnemonic", l),
"OptionPane.yesIcon"), minimumWidth);
getMnemonic("OptionPane.noButtonMnemonic", l),
"OptionPane.noIcon"), minimumWidth);
getMnemonic("OptionPane.cancelButtonMnemonic", l),
"OptionPane.cancelIcon"), minimumWidth);
getMnemonic("OptionPane.okButtonMnemonic", l),
"OptionPane.okIcon"), minimumWidth);
getMnemonic("OptionPane.cancelButtonMnemonic", l),
"OptionPane.cancelIcon"), minimumWidth);
} else {
getMnemonic("OptionPane.okButtonMnemonic", l),
"OptionPane.okIcon"), minimumWidth);
}
return defaultOptions;
}
return suppliedOptions;
}
return null;
}
return 0;
}
try {
}
catch (NumberFormatException nfe) { }
return 0;
}
/**
* Returns true, basic L&F wants all the buttons to have the same
* width.
*/
protected boolean getSizeButtonsToSameWidth() {
return true;
}
/**
* 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.
*/
protected int getInitialValueIndex() {
if (optionPane != null) {
return 0;
}
return counter;
}
}
}
return -1;
}
/**
* Sets the input value in the option pane the receiver is providing
* the look and feel for based on the value in the inputComponent.
*/
protected void resetInputValue() {
} else if(inputComponent != null &&
(inputComponent instanceof JComboBox)) {
.getSelectedItem());
} else if(inputComponent != null) {
.getSelectedValue());
}
}
/**
* If inputComponent is non-null, the focus is requested on that,
* otherwise request focus on the default value
*/
if (inputComponent != null)
else {
if (initialFocusComponent != null)
if (initialFocusComponent instanceof JButton) {
}
}
}
}
/**
* Returns true if in the last call to validateComponent the message
* or buttons contained a subclass of Component.
*/
return hasCustomComponents;
}
/**
* <code>ButtonAreaLayout</code> behaves in a similar manner to
* <code>FlowLayout</code>. It lays out all components from left to
* right. If <code>syncAllWidths</code> is true, the widths of each
* component will be set to the largest preferred size width.
*
* This class should be treated as a "protected" inner class.
* Instantiate it only within subclasses of {@code BasicOptionPaneUI}.
*/
protected boolean syncAllWidths;
protected int padding;
/** If true, children are lumped together in parent. */
protected boolean centersChildren;
private int orientation;
private boolean reverseButtons;
/**
* Indicates whether or not centersChildren should be used vs
* the orientation. This is done for backward compatability
* for subclassers.
*/
private boolean useOrientation;
this.syncAllWidths = syncAllWidths;
centersChildren = true;
useOrientation = false;
}
boolean reverseButtons) {
this(syncAllSizes, padding);
useOrientation = true;
this.orientation = orientation;
this.reverseButtons = reverseButtons;
}
}
public boolean getSyncAllWidths() {
return syncAllWidths;
}
this.padding = newPadding;
}
public int getPadding() {
return padding;
}
useOrientation = false;
}
public boolean getCentersChildren() {
return centersChildren;
}
if (!useOrientation) {
return SwingConstants.CENTER;
}
return orientation;
}
switch (orientation) {
case SwingConstants.LEFT:
return SwingConstants.RIGHT;
case SwingConstants.RIGHT:
return SwingConstants.LEFT;
case SwingConstants.CENTER:
return SwingConstants.CENTER;
}
return SwingConstants.LEFT;
}
}
int maxWidth = 0;
int maxHeight = 0;
int totalButtonWidth = 0;
int x = 0;
int xOffset = 0;
}
if (getSyncAllWidths()) {
}
switch (getOrientation(container)) {
case SwingConstants.LEFT:
break;
case SwingConstants.RIGHT:
break;
case SwingConstants.CENTER:
}
else {
if (getSyncAllWidths()) {
}
else {
(numChildren - 1);
}
}
break;
}
if (getSyncAllWidths()) {
}
else {
}
if (xOffset != 0) {
x += xOffset;
}
else {
}
}
}
}
if(c != null) {
int height = 0;
if (syncAllWidths) {
int maxWidth = 0;
}
extraHeight + height);
}
else {
int totalWidth = 0;
}
}
}
}
}
return minimumLayoutSize(c);
}
}
/**
* This class should be treated as a "protected" inner class.
* Instantiate it only within subclasses of {@code BasicOptionPaneUI}.
*/
/**
* If the source of the PropertyChangeEvent <code>e</code> equals the
* optionPane and is one of the ICON_PROPERTY, MESSAGE_PROPERTY,
* OPTIONS_PROPERTY or INITIAL_VALUE_PROPERTY,
* validateComponent is invoked.
*/
getHandler().propertyChange(e);
}
}
/**
* used representing the message.
*/
"OptionPane.messageForeground");
}
"OptionPane.messageFont");
if (messageFont != null) {
}
}
/**
* used representing the button portion of the optionpane.
*/
"OptionPane.buttonFont");
if (buttonFont != null) {
}
}
/**
* This class should be treated as a "protected" inner class.
* Instantiate it only within subclasses of {@code BasicOptionPaneUI}.
*/
protected int buttonIndex;
this.buttonIndex = buttonIndex;
}
if (optionPane != null) {
/* If the option pane takes input, then store the input value
* if custom options were specified, if the option type is
* DEFAULT_OPTION, OR if option type is set to a predefined
* one and the user chose the affirmative answer.
*/
if (inputComponent != null) {
buttonIndex == 0)) {
}
}
buttonIndex == 1) {
} else {
}
} else {
}
}
}
}
//
// ActionListener
//
}
//
// MouseListener
//
}
}
}
}
if (e.getClickCount() == 2) {
}
}
//
// PropertyChangeListener
//
if(e.getSource() == optionPane) {
// Option Pane Auditory Cue Activation
// only respond to "ancestor" changes
// the idea being that a JOptionPane gets a JDialog when it is
// set to appear and loses it's JDialog when it is dismissed.
if ("ancestor" == e.getPropertyName()) {
boolean isComingUp;
// if the old value is null, then the JOptionPane is being
// created since it didn't previously have an ancestor.
if (e.getOldValue() == null) {
isComingUp = true;
} else {
isComingUp = false;
}
// figure out what to do based on the message type
switch (op.getMessageType()) {
case JOptionPane.PLAIN_MESSAGE:
if (isComingUp) {
"OptionPane.informationSound");
}
break;
case JOptionPane.QUESTION_MESSAGE:
if (isComingUp) {
"OptionPane.questionSound");
}
break;
if (isComingUp) {
"OptionPane.informationSound");
}
break;
case JOptionPane.WARNING_MESSAGE:
if (isComingUp) {
"OptionPane.warningSound");
}
break;
case JOptionPane.ERROR_MESSAGE:
if (isComingUp) {
"OptionPane.errorSound");
}
break;
default:
op.getMessageType());
break;
}
}
// Visual activity
}
else if (changeName == "componentOrientation") {
if (o != e.getOldValue()) {
}
}
}
}
}
//
// Classes used when optionPane.getWantsInput returns true.
//
/**
* A JTextField that allows you to specify an array of KeyStrokes that
* that will have their bindings processed regardless of whether or
* not they are registered on the JTextField. This is used as we really
* want the ActionListener to be notified so that we can push the
* change to the JOptionPane, but we also want additional bindings
* (those of the JRootPane) to be processed as well.
*/
super(cols);
}
/**
* Sets the KeyStrokes that will be additional processed for
* ancestor bindings.
*/
}
pressed);
counter--) {
// Returning false will allow further processing
// of the bindings, eg our parent Containers will get a
// crack at them.
return false;
}
}
}
return processed;
}
}
/**
* Registered in the ActionMap. Sets the value of the option pane
* to <code>JOptionPane.CLOSED_OPTION</code>.
*/
super(key);
}
}
}
}
/**
* This class is used to create the default buttons. This indirection is
* used so that addButtonComponents can tell which Buttons were created
* by us vs subclassers or from the JOptionPane itself.
*/
private static class ButtonFactory {
private int mnemonic;
this.minimumWidth = minimumWidth;
}
if (minimumWidth > 0) {
} else {
}
}
if (mnemonic != 0) {
}
return button;
}
int minimumWidth;
super(text);
this.minimumWidth = minimumWidth;
}
return min;
}
return pref;
}
}
}
}