001: /*
002: * $Id: MacOSXStatusBarUI.java,v 1.5 2007/02/08 05:12:15 rbair Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020: */
021:
022: package org.jdesktop.swingx.plaf.macosx;
023:
024: import java.awt.FlowLayout;
025: import java.awt.LayoutManager;
026: import javax.swing.BorderFactory;
027: import javax.swing.JComponent;
028: import javax.swing.border.Border;
029: import javax.swing.plaf.BorderUIResource;
030: import javax.swing.plaf.ComponentUI;
031: import javax.swing.plaf.UIResource;
032: import org.jdesktop.swingx.JXStatusBar;
033: import org.jdesktop.swingx.plaf.StatusBarUI;
034:
035: /**
036: *
037: * @author rbair
038: */
039: public class MacOSXStatusBarUI extends StatusBarUI {
040: /**
041: * The one and only JXStatusBar for this UI delegate
042: */
043: private JXStatusBar statusBar;
044:
045: /** Creates a new instance of BasicStatusBarUI */
046: public MacOSXStatusBarUI() {
047: }
048:
049: /**
050: * Returns an instance of the UI delegate for the specified component.
051: * Each subclass must provide its own static <code>createUI</code>
052: * method that returns an instance of that UI delegate subclass.
053: * If the UI delegate subclass is stateless, it may return an instance
054: * that is shared by multiple components. If the UI delegate is
055: * stateful, then it should return a new instance per component.
056: * The default implementation of this method throws an error, as it
057: * should never be invoked.
058: */
059: public static ComponentUI createUI(JComponent c) {
060: return new MacOSXStatusBarUI();
061: }
062:
063: /**
064: * Configures the specified component appropriate for the look and feel.
065: * This method is invoked when the <code>ComponentUI</code> instance is being installed
066: * as the UI delegate on the specified component. This method should
067: * completely configure the component for the look and feel,
068: * including the following:
069: * <ol>
070: * <li>Install any default property values for color, fonts, borders,
071: * icons, opacity, etc. on the component. Whenever possible,
072: * property values initialized by the client program should <i>not</i>
073: * be overridden.
074: * <li>Install a <code>LayoutManager</code> on the component if necessary.
075: * <li>Create/add any required sub-components to the component.
076: * <li>Create/install event listeners on the component.
077: * <li>Create/install a <code>PropertyChangeListener</code> on the component in order
078: * to detect and respond to component property changes appropriately.
079: * <li>Install keyboard UI (mnemonics, traversal, etc.) on the component.
080: * <li>Initialize any appropriate instance data.
081: * </ol>
082: * @param c the component where this UI delegate is being installed
083: *
084: * @see #uninstallUI
085: * @see javax.swing.JComponent#setUI
086: * @see javax.swing.JComponent#updateUI
087: */
088: @Override
089: public void installUI(JComponent c) {
090: assert c instanceof JXStatusBar;
091: statusBar = (JXStatusBar) c;
092:
093: Border b = statusBar.getBorder();
094: if (b == null || b instanceof UIResource) {
095: statusBar.setBorder(new BorderUIResource(BorderFactory
096: .createEmptyBorder(4, 5, 4, 22)));
097: }
098:
099: LayoutManager m = statusBar.getLayout();
100: if (m == null) {
101: statusBar.setLayout(new FlowLayout());
102: }
103: installDefaults();
104: }
105:
106: protected void installDefaults() {
107: statusBar.setOpaque(false);
108: }
109:
110: /**
111: * Reverses configuration which was done on the specified component during
112: * <code>installUI</code>. This method is invoked when this
113: * <code>UIComponent</code> instance is being removed as the UI delegate
114: * for the specified component. This method should undo the
115: * configuration performed in <code>installUI</code>, being careful to
116: * leave the <code>JComponent</code> instance in a clean state (no
117: * extraneous listeners, look-and-feel-specific property objects, etc.).
118: * This should include the following:
119: * <ol>
120: * <li>Remove any UI-set borders from the component.
121: * <li>Remove any UI-set layout managers on the component.
122: * <li>Remove any UI-added sub-components from the component.
123: * <li>Remove any UI-added event/property listeners from the component.
124: * <li>Remove any UI-installed keyboard UI from the component.
125: * <li>Nullify any allocated instance data objects to allow for GC.
126: * </ol>
127: * @param c the component from which this UI delegate is being removed;
128: * this argument is often ignored,
129: * but might be used if the UI object is stateless
130: * and shared by multiple components
131: *
132: * @see #installUI
133: * @see javax.swing.JComponent#updateUI
134: */
135: @Override
136: public void uninstallUI(JComponent c) {
137: assert c instanceof JXStatusBar;
138: }
139: }
|