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.border.*;
4632N/Aimport javax.swing.plaf.*;
4632N/Aimport javax.swing.plaf.basic.BasicToolBarUI;
4632N/A
4632N/Aimport com.apple.laf.AquaUtils.*;
4632N/A
4632N/Apublic class AquaToolBarUI extends BasicToolBarUI implements SwingConstants {
4632N/A private static RecyclableSingleton<ToolBarBorder> toolBarBorder = new RecyclableSingletonFromDefaultConstructor<ToolBarBorder>(ToolBarBorder.class);
4632N/A public static Border getToolBarBorder() {
4632N/A return toolBarBorder.get();
4632N/A }
4632N/A
4632N/A public static ComponentUI createUI(final JComponent c) {
4632N/A return new AquaToolBarUI();
4632N/A }
4632N/A
4632N/A protected void setBorderToNonRollover(final Component c) { }
4632N/A protected void setBorderToNormal(final Component c) { }
4632N/A protected void setBorderToRollover(final Component c) { }
4632N/A
4632N/A protected RootPaneContainer createFloatingWindow(final JToolBar toolbar) {
4632N/A final RootPaneContainer window = super.createFloatingWindow(toolbar);
4632N/A window.getRootPane().putClientProperty("Window.style", "small");
4632N/A return window;
4632N/A }
4632N/A
4632N/A /* ToolBarBorder and drag-off handle, based loosly on MetalBumps */
4632N/A static class ToolBarBorder extends AbstractBorder implements UIResource, javax.swing.SwingConstants {
4632N/A protected void fillHandle(final Graphics g, final int x1, final int y1, final int x2, final int y2, final boolean horizontal) {
4632N/A g.setColor(UIManager.getColor("ToolBar.borderHandleColor"));
4632N/A if (horizontal) {
4632N/A final int h = y2 - y1 - 2;
4632N/A g.fillRect(x1 + 2, y1 + 1, 1, h);
4632N/A g.fillRect(x1 + 5, y1 + 1, 1, h);
4632N/A } else {
4632N/A final int w = x2 - x1 - 2;
4632N/A g.fillRect(x1 + 1, y1 + 2, w, 1);
4632N/A g.fillRect(x1 + 1, y1 + 5, w, 1);
4632N/A }
4632N/A }
4632N/A
4632N/A public void paintBorder(final java.awt.Component c, final Graphics g, int x, int y, final int w, final int h) {
4632N/A g.translate(x, y);
4632N/A
4632N/A if (c.isOpaque()) {
5233N/A AquaUtils.fillRect(g, c, c.getBackground(), 0, 0, w - 1, h - 1);
4632N/A }
4632N/A
4632N/A final Color oldColor = g.getColor();
4632N/A
4632N/A final JToolBar jtb = (JToolBar)c;
4632N/A final ComponentOrientation orient = jtb.getComponentOrientation();
4632N/A final boolean horizontal = jtb.getOrientation() == SwingConstants.HORIZONTAL;
4632N/A
4632N/A if (jtb.isFloatable()) {
4632N/A if (horizontal) {
4632N/A if (orient.isLeftToRight()) {
4632N/A fillHandle(g, 2, 2, 10, h - 2, true);
4632N/A } else {
4632N/A fillHandle(g, w - 10, 2, w - 2, h - 2, true);
4632N/A }
4632N/A } else {
4632N/A fillHandle(g, 2, 2, w - 2, 10, false);
4632N/A }
4632N/A }
4632N/A
4632N/A g.setColor(oldColor);
4632N/A
4632N/A g.translate(-x, -y);
4632N/A }
4632N/A
4632N/A public Insets getBorderInsets(final java.awt.Component c) {
4632N/A final Insets borderInsets = new Insets(5, 5, 5, 5);
4632N/A return getBorderInsets(c, borderInsets);
4632N/A }
4632N/A
4632N/A public Insets getBorderInsets(final java.awt.Component c, final Insets borderInsets) {
4632N/A borderInsets.left = 4;
4632N/A borderInsets.right = 4;
4632N/A borderInsets.top = 2;
4632N/A borderInsets.bottom = 2;
4632N/A
4632N/A if (((JToolBar)c).isFloatable()) {
4632N/A if (((JToolBar)c).getOrientation() == HORIZONTAL) {
4632N/A borderInsets.left = 12;
4632N/A // We don't have to adjust for right-to-left
4632N/A } else { // vertical
4632N/A borderInsets.top = 12;
4632N/A }
4632N/A }
4632N/A
4632N/A final Insets margin = ((JToolBar)c).getMargin();
4632N/A
4632N/A if (margin != null) {
4632N/A borderInsets.left += margin.left;
4632N/A borderInsets.top += margin.top;
4632N/A borderInsets.right += margin.right;
4632N/A borderInsets.bottom += margin.bottom;
4632N/A }
4632N/A
4632N/A return borderInsets;
4632N/A }
4632N/A
4632N/A public boolean isBorderOpaque() {
4632N/A return true;
4632N/A }
4632N/A }
5233N/A
5233N/A @Override
5233N/A public final void update(final Graphics g, final JComponent c) {
5233N/A if (c.isOpaque()) {
5233N/A AquaUtils.fillRect(g, c);
5233N/A }
5233N/A paint(g, c);
5233N/A }
4632N/A}