KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > plaf > aqua > AquaSeparatorUI


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * AquaSeparatorUI.java
21  *
22  * Created on March 14, 2004, 4:57 AM
23  */

24
25 package org.netbeans.swing.plaf.aqua;
26
27 import java.awt.Color JavaDoc;
28 import java.awt.Dimension JavaDoc;
29 import java.awt.Graphics JavaDoc;
30 import javax.swing.JComponent JavaDoc;
31 import javax.swing.JPopupMenu JavaDoc;
32 import javax.swing.plaf.ComponentUI JavaDoc;
33 import javax.swing.plaf.SeparatorUI JavaDoc;
34
35 /**
36  * Aqua SeparatorUI in JPopupMenu has a height of 12px. The line has a
37  * padding-left and padding-right of 1px. And the line is draw at px 6.
38  *
39  * Only JPopupMenu Separator get draw, all other are 0x0 px.
40  *
41  * @author Christopher Atlan
42  */

43 public class AquaSeparatorUI extends SeparatorUI JavaDoc {
44     private final static Color JavaDoc lineColor = new Color JavaDoc(215, 215, 215);
45     
46     private static ComponentUI JavaDoc separatorui = new AquaSeparatorUI();
47     
48     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
49         return separatorui;
50     }
51     
52     public void paint( Graphics JavaDoc g, JComponent JavaDoc c ) {
53         if (c.getParent() instanceof JPopupMenu JavaDoc) {
54             Dimension JavaDoc s = c.getSize();
55             
56             g.setColor(lineColor);
57             g.drawLine(1, 5, s.width - 2, 5);
58         }
59     }
60     
61     public Dimension JavaDoc getPreferredSize(JComponent JavaDoc c) {
62         Dimension JavaDoc s;
63         if (c.getParent() instanceof JPopupMenu JavaDoc) {
64             return new Dimension JavaDoc( 0, 12 );
65         } else {
66             s = new Dimension JavaDoc(0, 0);
67         }
68         
69         return s;
70     }
71     
72     public Dimension JavaDoc getMinimumSize( JComponent JavaDoc c ) { return null; }
73     public Dimension JavaDoc getMaximumSize( JComponent JavaDoc c ) { return null; }
74 }
75
Popular Tags