KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > HeaderStyle


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;
32
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JMenuBar JavaDoc;
35 import javax.swing.JToolBar JavaDoc;
36
37 /**
38  * Describes the header styles for JMenuBar and JToolBar.
39  * Header styles are look-independent and can be shadowed by a look-dependent
40  * <code>BorderStyle</code>.
41  *
42  * @author Karsten Lentzsch
43  * @version $Revision: 1.3 $
44  *
45  * @see BorderStyle
46  */

47 public final class HeaderStyle {
48     
49     public static final HeaderStyle SINGLE = new HeaderStyle("Single");
50     public static final HeaderStyle BOTH = new HeaderStyle("Both");
51
52     private final String JavaDoc name;
53
54
55     private HeaderStyle(String JavaDoc name) {
56         this.name = name;
57     }
58     
59     
60     /**
61      * Looks up the client property for the <code>HeaderStyle</code>
62      * from the JToolBar.
63      *
64      * @param menuBar the menu bar to inspect
65      * @return the menu bar's header style
66      */

67     public static HeaderStyle from(JMenuBar JavaDoc menuBar) {
68         return from0(menuBar);
69     }
70     
71     
72     /**
73      * Looks up the client property for the <code>HeaderStyle</code>
74      * from the JToolBar.
75      *
76      * @param toolBar the tool bar to inspect
77      * @return the tool bar's header style
78      */

79     public static HeaderStyle from(JToolBar JavaDoc toolBar) {
80         return from0(toolBar);
81     }
82
83     
84     /**
85      * Looks up the client property for the <code>HeaderStyle</code>
86      * from the specified JComponent.
87      *
88      * @param c the component to inspect
89      * @return the header style for the given component
90      */

91     private static HeaderStyle from0(JComponent JavaDoc c) {
92         Object JavaDoc value = c.getClientProperty(Options.HEADER_STYLE_KEY);
93         if (value instanceof HeaderStyle)
94             return (HeaderStyle) value;
95         
96         if (value instanceof String JavaDoc) {
97             return HeaderStyle.valueOf((String JavaDoc) value);
98         }
99         
100         return null;
101     }
102     
103     
104     /**
105      * Looks up and answers the <code>HeaderStyle</code> with the specified name.
106      *
107      * @param name the name of the HeaderStyle object to lookup
108      * @return the associated HeaderStyle
109      */

110     private static HeaderStyle valueOf(String JavaDoc name) {
111         if (name.equalsIgnoreCase(SINGLE.name))
112             return SINGLE;
113         else if (name.equalsIgnoreCase(BOTH.name))
114             return BOTH;
115         else
116             throw new IllegalArgumentException JavaDoc("Invalid HeaderStyle name " + name);
117     }
118     
119
120     public String JavaDoc toString() {
121         return name;
122     }
123     
124 }
Popular Tags