WindowsPopupMenuSeparatorUI.java revision 2362
0N/A/*
553N/A * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
553N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
553N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.java.swing.plaf.windows;
0N/A
288N/Aimport java.awt.*;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.plaf.basic.BasicPopupMenuSeparatorUI;
0N/Aimport javax.swing.plaf.ComponentUI;
0N/A
0N/Aimport com.sun.java.swing.plaf.windows.TMSchema.Part;
0N/Aimport com.sun.java.swing.plaf.windows.TMSchema.State;
0N/Aimport com.sun.java.swing.plaf.windows.XPStyle.Skin;
0N/A
0N/A/**
0N/A * Windows L&F implementation of PopupMenuSeparatorUI.
0N/A *
0N/A * @author Leif Samuelsson
0N/A * @author Igor Kushnirskiy
0N/A */
0N/A
0N/Apublic class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI {
0N/A
0N/A public static ComponentUI createUI(JComponent c) {
return new WindowsPopupMenuSeparatorUI();
}
public void paint(Graphics g, JComponent c) {
Dimension s = c.getSize();
if (WindowsMenuItemUI.isVistaPainting()) {
int x = 1;
Component parent = c.getParent();
if (parent instanceof JComponent) {
Object gutterOffsetObject =
((JComponent) parent).getClientProperty(
WindowsPopupMenuUI.GUTTER_OFFSET_KEY);
if (gutterOffsetObject instanceof Integer) {
/*
* gutter offset is in parent's coordinates.
* See comment in
* WindowsPopupMenuUI.getTextOffset(JComponent)
*/
x = ((Integer) gutterOffsetObject).intValue() - c.getX();
x += WindowsPopupMenuUI.getGutterWidth();
}
}
Skin skin = XPStyle.getXP().getSkin(c, Part.MP_POPUPSEPARATOR);
int skinHeight = skin.getHeight();
int y = (s.height - skinHeight) / 2;
skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL);
} else {
int y = s.height / 2;
g.setColor(c.getForeground());
g.drawLine(1, y - 1, s.width - 2, y - 1);
g.setColor(c.getBackground());
g.drawLine(1, y, s.width - 2, y);
}
}
public Dimension getPreferredSize(JComponent c) {
int fontHeight = 0;
Font font = c.getFont();
if (font != null) {
fontHeight = c.getFontMetrics(font).getHeight();
}
return new Dimension(0, fontHeight/2 + 2);
}
}