KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > windows > WindowsPopupMenuSeparatorUI


1 /*
2  * @(#)WindowsPopupMenuSeparatorUI.java 1.3 07/01/18
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.java.swing.plaf.windows;
9
10 import java.awt.*;
11
12 import javax.swing.*;
13 import javax.swing.plaf.basic.BasicPopupMenuSeparatorUI JavaDoc;
14 import javax.swing.plaf.ComponentUI JavaDoc;
15
16 import com.sun.java.swing.plaf.windows.TMSchema.Part;
17 import com.sun.java.swing.plaf.windows.TMSchema.State;
18 import com.sun.java.swing.plaf.windows.XPStyle.Skin;
19
20 /**
21  * Windows L&F implementation of PopupMenuSeparatorUI.
22  *
23  * @version 1.3 01/18/07
24  * @author Leif Samuelsson
25  * @author Igor Kushnirskiy
26  */

27
28 public class WindowsPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI JavaDoc {
29
30     public static ComponentUI JavaDoc createUI(JComponent c) {
31         return new WindowsPopupMenuSeparatorUI();
32     }
33
34     public void paint(Graphics g, JComponent c) {
35         Dimension s = c.getSize();
36         if (WindowsMenuItemUI.isVistaPainting()) {
37             int x = 1;
38             Component parent = c.getParent();
39             if (parent instanceof JComponent) {
40                 Object JavaDoc gutterOffsetObject =
41                     ((JComponent) parent).getClientProperty(
42                         WindowsPopupMenuUI.GUTTER_OFFSET_KEY);
43                 if (gutterOffsetObject instanceof Integer JavaDoc) {
44                     /*
45                      * gutter offset is in parent's coordinates.
46                      * See comment in
47                      * WindowsPopupMenuUI.getTextOffset(JComponent)
48                      */

49                     x = ((Integer JavaDoc) gutterOffsetObject).intValue() - c.getX();
50                     x += WindowsPopupMenuUI.getGutterWidth();
51                 }
52             }
53             Skin skin = XPStyle.getXP().getSkin(c, Part.MP_POPUPSEPARATOR);
54             int skinHeight = skin.getHeight();
55             int y = (s.height - skinHeight) / 2;
56             skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL);
57         } else {
58             int y = s.height / 2;
59             g.setColor(c.getForeground());
60             g.drawLine(1, y - 1, s.width - 2, y - 1);
61
62             g.setColor(c.getBackground());
63             g.drawLine(1, y, s.width - 2, y);
64         }
65     }
66
67     public Dimension getPreferredSize(JComponent c) {
68     int fontHeight = c.getFontMetrics(c.getFont()).getHeight();
69
70     return new Dimension(0, fontHeight/2 + 2);
71     }
72
73 }
74
Popular Tags