KickJava   Java API By Example, From Geeks To Geeks.

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


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 border styles for JMenuBar and JToolBar. Border styles are
39  * look-dependent and shadow look-independent <code>HeaderStyle</code>s.
40  *
41  * @author Karsten Lentzsch
42  * @version $Revision: 1.2 $
43  *
44  * @see HeaderStyle
45  */

46 public final class BorderStyle {
47
48     public static final BorderStyle EMPTY = new BorderStyle("Empty");
49     public static final BorderStyle SEPARATOR = new BorderStyle("Separator");
50     public static final BorderStyle ETCHED = new BorderStyle("Etched");
51
52     private final String JavaDoc name;
53
54     
55     // Instance Creation ******************************************************
56

57     private BorderStyle(String JavaDoc name) {
58         this.name = name;
59     }
60     
61     
62     // ************************************************************************
63

64     /**
65      * Looks up the client property for the header style from the JToolBar.
66      *
67      * @param toolBar the tool bar to inspect
68      * @param clientPropertyKey the key used to lookup the property
69      * @return the border style used to choose a border in the UI delegate
70      */

71     public static BorderStyle from(JToolBar JavaDoc toolBar, String JavaDoc clientPropertyKey) {
72         return from0(toolBar, clientPropertyKey);
73     }
74
75     /**
76      * Looks up the client property for the header style from the
77      * <code>JToolBar</code.
78      *
79      * @param menuBar the menu bar to inspect
80      * @param clientPropertyKey the key used to lookup the property
81      * @return the border style used to choose a border in the UI delegate
82      */

83     public static BorderStyle from(JMenuBar JavaDoc menuBar, String JavaDoc clientPropertyKey) {
84         return from0(menuBar, clientPropertyKey);
85     }
86
87     /**
88      * Looks up the client property for the header style from the specified
89      * <code>JComponent</code>.
90      *
91      * @param c
92      * the compoent to inspect
93      * @param clientPropertyKey
94      * the key used to lookup the property
95      * @return the border style used to choose a border in the UI delegate
96      */

97     private static BorderStyle from0(JComponent JavaDoc c, String JavaDoc clientPropertyKey) {
98         Object JavaDoc value = c.getClientProperty(clientPropertyKey);
99         if (value instanceof BorderStyle)
100             return (BorderStyle) value;
101
102         if (value instanceof String JavaDoc) {
103             return BorderStyle.valueOf((String JavaDoc) value);
104         }
105
106         return null;
107     }
108
109     private static BorderStyle valueOf(String JavaDoc name) {
110         if (name.equalsIgnoreCase(EMPTY.name))
111             return EMPTY;
112         else if (name.equalsIgnoreCase(SEPARATOR.name))
113             return SEPARATOR;
114         else if (name.equalsIgnoreCase(ETCHED.name))
115             return ETCHED;
116         else
117             throw new IllegalArgumentException JavaDoc("Invalid BorderStyle name "
118                     + name);
119     }
120
121     public String JavaDoc toString() {
122         return name;
123     }
124
125 }
Popular Tags