Path: blob/master/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBorder.java
41154 views
/*1* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.apple.laf;2627import java.awt.*;2829import javax.swing.*;30import javax.swing.border.Border;31import javax.swing.plaf.UIResource;3233public class AquaMenuBorder implements Border, UIResource {34public AquaMenuBorder() { }3536/**37* Paints the border for the specified component with the specified38* position and size.39* @param c the component for which this border is being painted40* @param g the paint graphics41* @param x the x position of the painted border42* @param y the y position of the painted border43* @param width the width of the painted border44* @param height the height of the painted border45*/46public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {47// for now we don't paint a border. We let the button paint it since there48// needs to be a strict ordering for aqua components.49//paintButton(c, g, x, y, width, height);50//if (c instanceof JPopupMenu) {51//g.setColor(Color.red);52//g.drawRect(x,y, width-1, height-1);53//}54}5556/**57* Returns whether or not the border is opaque. If the border58* is opaque, it is responsible for filling in it's own59* background when painting.60*/61public boolean isBorderOpaque() {62return false;63}6465protected static Insets getItemInsets() {66return new Insets(1, 5, 1, 5);67}6869protected static Insets getEmptyInsets() {70return new Insets(0, 0, 0, 0);71}7273protected static Insets getPopupInsets() {74return new Insets(4, 0, 4, 0);75}7677/**78* Returns the insets of the border.79* @param c the component for which this border insets value applies80*/81public Insets getBorderInsets(final Component c) {82if (!(c instanceof JPopupMenu)) {83return getItemInsets();84}8586// for more info on this issue, see AquaComboBoxPopup.updateContents()87final JPopupMenu menu = (JPopupMenu)c;88final int nChildren = menu.getComponentCount();89if (nChildren > 0) {90final Component firstChild = menu.getComponent(0);91if (firstChild instanceof Box.Filler) return getEmptyInsets();92if (firstChild instanceof JScrollPane) return getEmptyInsets();93}9495// just need top and bottom, and not right and left.96// but only for non-list popups.97return getPopupInsets();98}99}100101102