4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage com.apple.laf;
4632N/A
4632N/Aimport java.awt.*;
4632N/A
4632N/Aimport javax.swing.*;
4632N/Aimport javax.swing.plaf.ComponentUI;
4632N/Aimport javax.swing.plaf.basic.BasicOptionPaneUI;
4632N/A
4632N/Apublic class AquaOptionPaneUI extends BasicOptionPaneUI {
4632N/A private static final int kOKCancelButtonWidth = 79;
4632N/A private static final int kButtonHeight = 23;
4632N/A
4632N/A private static final int kDialogSmallPadding = 4;
4632N/A private static final int kDialogLargePadding = 23;
4632N/A
4632N/A /**
4632N/A * Creates a new BasicOptionPaneUI instance.
4632N/A */
4632N/A public static ComponentUI createUI(final JComponent x) {
4632N/A return new AquaOptionPaneUI();
4632N/A }
4632N/A
4632N/A /**
4632N/A * Creates and returns a Container containin the buttons. The buttons
4632N/A * are created by calling <code>getButtons</code>.
4632N/A */
4632N/A protected Container createButtonArea() {
4632N/A final Container bottom = super.createButtonArea();
4632N/A // Now replace the Layout
4632N/A bottom.setLayout(new AquaButtonAreaLayout(true, kDialogSmallPadding));
4632N/A return bottom;
4632N/A }
4632N/A
4632N/A /**
4632N/A * Messaged from installComponents to create a Container containing the
4632N/A * body of the message.
4632N/A * The icon and body should be aligned on their top edges
4632N/A */
4632N/A protected Container createMessageArea() {
4632N/A final JPanel top = new JPanel();
4632N/A top.setBorder(UIManager.getBorder("OptionPane.messageAreaBorder"));
4632N/A top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS));
4632N/A
4632N/A /* Fill the body. */
4632N/A final Container body = new JPanel();
4632N/A
4632N/A final Icon sideIcon = getIcon();
4632N/A
4632N/A if (sideIcon != null) {
4632N/A final JLabel iconLabel = new JLabel(sideIcon);
4632N/A iconLabel.setVerticalAlignment(SwingConstants.TOP);
4632N/A
4632N/A final JPanel iconPanel = new JPanel();
4632N/A iconPanel.add(iconLabel);
4632N/A top.add(iconPanel);
4632N/A top.add(Box.createHorizontalStrut(kDialogLargePadding));
4632N/A }
4632N/A
4632N/A body.setLayout(new GridBagLayout());
4632N/A final GridBagConstraints cons = new GridBagConstraints();
4632N/A cons.gridx = cons.gridy = 0;
4632N/A cons.gridwidth = GridBagConstraints.REMAINDER;
4632N/A cons.gridheight = 1;
4632N/A cons.anchor = GridBagConstraints.WEST;
4632N/A cons.insets = new Insets(0, 0, 3, 0);
4632N/A
4632N/A addMessageComponents(body, cons, getMessage(), getMaxCharactersPerLineCount(), false);
4632N/A top.add(body);
4632N/A
4632N/A return top;
4632N/A }
4632N/A
4632N/A /**
4632N/A * AquaButtonAreaLayout lays out all
4632N/A * components according to the HI Guidelines:
4632N/A * The most important button is always on the far right
4632N/A * The group of buttons is on the right for left-to-right,
4632N/A * left for right-to-left
4632N/A * The widths of each component will be set to the largest preferred size width.
4632N/A *
4632N/A *
4632N/A * This inner class is marked &quot;public&quot; due to a compiler bug.
4632N/A * This class should be treated as a &quot;protected&quot; inner class.
4632N/A * Instantiate it only within subclasses of BasicOptionPaneUI.
4632N/A *
4632N/A * BasicOptionPaneUI expects that its buttons are layed out with
4632N/A * a subclass of ButtonAreaLayout
4632N/A */
4632N/A public static class AquaButtonAreaLayout extends ButtonAreaLayout {
4632N/A public AquaButtonAreaLayout(final boolean syncAllWidths, final int padding) {
4632N/A super(true, padding);
4632N/A }
4632N/A
4632N/A public void layoutContainer(final Container container) {
4632N/A final Component[] children = container.getComponents();
4632N/A if (children == null || 0 >= children.length) return;
4632N/A
4632N/A final int numChildren = children.length;
4632N/A final int yLocation = container.getInsets().top;
4632N/A
4632N/A // Always syncAllWidths - and heights!
4632N/A final Dimension maxSize = new Dimension(kOKCancelButtonWidth, kButtonHeight);
4632N/A for (int i = 0; i < numChildren; i++) {
4632N/A final Dimension sizes = children[i].getPreferredSize();
4632N/A maxSize.width = Math.max(maxSize.width, sizes.width);
4632N/A maxSize.height = Math.max(maxSize.height, sizes.height);
4632N/A }
4632N/A
4632N/A // ignore getCentersChildren, because we don't
4632N/A int xLocation = container.getSize().width - (maxSize.width * numChildren + (numChildren - 1) * padding);
4632N/A final int xOffset = maxSize.width + padding;
4632N/A
4632N/A // most important button (button zero) on far right
4632N/A for (int i = numChildren - 1; i >= 0; i--) {
4632N/A children[i].setBounds(xLocation, yLocation, maxSize.width, maxSize.height);
4632N/A xLocation += xOffset;
4632N/A }
4632N/A }
4632N/A }
4632N/A}