001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks;
032:
033: import javax.swing.JComponent;
034: import javax.swing.JMenuBar;
035: import javax.swing.JToolBar;
036:
037: /**
038: * Describes the border styles for JMenuBar and JToolBar. Border styles are
039: * look-dependent and shadow look-independent <code>HeaderStyle</code>s.
040: *
041: * @author Karsten Lentzsch
042: * @version $Revision: 1.3 $
043: *
044: * @see HeaderStyle
045: */
046: public final class BorderStyle {
047:
048: public static final BorderStyle EMPTY = new BorderStyle("Empty");
049: public static final BorderStyle SEPARATOR = new BorderStyle(
050: "Separator");
051: public static final BorderStyle ETCHED = new BorderStyle("Etched");
052:
053: private final String name;
054:
055: // Instance Creation ******************************************************
056:
057: private BorderStyle(String name) {
058: this .name = name;
059: }
060:
061: // ************************************************************************
062:
063: /**
064: * Looks up the client property for the header style from the JToolBar.
065: *
066: * @param toolBar the tool bar to inspect
067: * @param clientPropertyKey the key used to lookup the property
068: * @return the border style used to choose a border in the UI delegate
069: */
070: public static BorderStyle from(JToolBar toolBar,
071: String clientPropertyKey) {
072: return from0(toolBar, clientPropertyKey);
073: }
074:
075: /**
076: * Looks up the client property for the header style from the JMenuBar.
077: *
078: * @param menuBar the menu bar to inspect
079: * @param clientPropertyKey the key used to lookup the property
080: * @return the border style used to choose a border in the UI delegate
081: */
082: public static BorderStyle from(JMenuBar menuBar,
083: String clientPropertyKey) {
084: return from0(menuBar, clientPropertyKey);
085: }
086:
087: /**
088: * Looks up the client property for the header style from the specified
089: * JComponent.
090: *
091: * @param c the compoent to inspect
092: * @param clientPropertyKey
093: * the key used to lookup the property
094: * @return the border style used to choose a border in the UI delegate
095: */
096: private static BorderStyle from0(JComponent c,
097: String clientPropertyKey) {
098: Object value = c.getClientProperty(clientPropertyKey);
099: if (value instanceof BorderStyle)
100: return (BorderStyle) value;
101:
102: if (value instanceof String) {
103: return BorderStyle.valueOf((String) value);
104: }
105:
106: return null;
107: }
108:
109: private static BorderStyle valueOf(String 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(
118: "Invalid BorderStyle name " + name);
119: }
120:
121: public String toString() {
122: return name;
123: }
124:
125: }
|