KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > common > ExtBasicPopupMenuSeparatorUI


1 /*
2  * Copyright (c) 2001-2005 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.looks.common;
32
33 import java.awt.Dimension JavaDoc;
34 import java.awt.Graphics JavaDoc;
35 import java.awt.Insets JavaDoc;
36
37 import javax.swing.JComponent JavaDoc;
38 import javax.swing.JSeparator JavaDoc;
39 import javax.swing.UIManager JavaDoc;
40 import javax.swing.plaf.ComponentUI JavaDoc;
41 import javax.swing.plaf.basic.BasicPopupMenuSeparatorUI JavaDoc;
42
43 /**
44  * Renders the separator in popup and pull-down menus.
45  * Unlike its superclass we use a setting for the insets and
46  * it uses a shared UI delegate.
47  *
48  * @author Karsten Lentzsch
49  * @version $Revision: 1.3 $
50  */

51 public final class ExtBasicPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI JavaDoc {
52
53     private static final int SEPARATOR_HEIGHT = 2;
54     
55     private Insets JavaDoc insets;
56             
57     /** Shared UI object. */
58     private static ComponentUI JavaDoc popupMenuSeparatorUI;
59     
60     public static ComponentUI JavaDoc createUI(JComponent JavaDoc b) {
61         if (popupMenuSeparatorUI == null) {
62             popupMenuSeparatorUI = new ExtBasicPopupMenuSeparatorUI();
63         }
64         return popupMenuSeparatorUI;
65     }
66     
67     
68     protected void installDefaults(JSeparator JavaDoc s) {
69         super.installDefaults(s);
70         insets = UIManager.getInsets("PopupMenuSeparator.margin");
71     }
72     
73
74     public void paint(Graphics JavaDoc g, JComponent JavaDoc c ) {
75         Dimension JavaDoc s = c.getSize();
76         
77         int topInset = insets.top;
78         int leftInset = insets.left;
79         int rightInset = insets.right;
80
81         // Paint background
82
g.setColor(UIManager.getColor("MenuItem.background"));
83         g.fillRect(0, 0, s.width, s.height);
84
85         // Draw side
86
/*
87         g.setColor(UIManager.getColor("controlHighlight"));
88         g.drawLine(0, 0, 0, s.height -1);
89         g.drawLine(s.width-1, 0, s.width-1, s.height-1);
90         */

91         
92         g.translate(0, topInset);
93         g.setColor(c.getForeground());
94         g.drawLine(leftInset, 0, s.width - rightInset, 0);
95
96         g.setColor(c.getBackground());
97         g.drawLine(leftInset, 1, s.width -rightInset, 1);
98         g.translate(0, -topInset);
99     }
100     
101
102     public Dimension JavaDoc getPreferredSize(JComponent JavaDoc c) {
103         return new Dimension JavaDoc(0, insets.top + SEPARATOR_HEIGHT + insets.bottom);
104     }
105     
106 }
Popular Tags