KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > windows > WindowsToolBarUI


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.windows;
32
33 import java.awt.Component JavaDoc;
34 import java.awt.Container JavaDoc;
35 import java.beans.PropertyChangeEvent JavaDoc;
36 import java.beans.PropertyChangeListener JavaDoc;
37
38 import javax.swing.AbstractButton JavaDoc;
39 import javax.swing.JComponent JavaDoc;
40 import javax.swing.JToolBar JavaDoc;
41 import javax.swing.LookAndFeel JavaDoc;
42 import javax.swing.border.Border JavaDoc;
43 import javax.swing.plaf.ComponentUI JavaDoc;
44 import javax.swing.plaf.metal.MetalToolBarUI JavaDoc;
45
46 import com.jgoodies.looks.BorderStyle;
47 import com.jgoodies.looks.HeaderStyle;
48 import com.jgoodies.looks.Options;
49
50 /**
51  * Corrects superclass behavior for rollover borders
52  * and adds behavior for handling different types of borders.
53  *
54  * @author Karsten Lentzsch
55  * @version $Revision: 1.2 $
56  */

57 public final class WindowsToolBarUI extends MetalToolBarUI JavaDoc {
58
59     private PropertyChangeListener JavaDoc listener;
60
61     public static ComponentUI JavaDoc createUI(JComponent JavaDoc b) {
62         return new WindowsToolBarUI();
63     }
64
65     // Handling Special Borders *********************************************
66

67     protected void installDefaults() {
68         super.installDefaults();
69         installSpecialBorder();
70     }
71
72     protected void installListeners() {
73         super.installListeners();
74         listener = createBorderStyleListener();
75         toolBar.addPropertyChangeListener(listener);
76     }
77
78     protected void uninstallListeners() {
79         toolBar.removePropertyChangeListener(listener);
80         super.uninstallListeners();
81     }
82
83     private PropertyChangeListener JavaDoc createBorderStyleListener() {
84         return new PropertyChangeListener JavaDoc() {
85
86             public void propertyChange(PropertyChangeEvent JavaDoc e) {
87                 String JavaDoc prop = e.getPropertyName();
88                 if (prop.equals(Options.HEADER_STYLE_KEY)
89                     || prop.equals(WindowsLookAndFeel.BORDER_STYLE_KEY)) {
90                     WindowsToolBarUI.this.installSpecialBorder();
91                 }
92             }
93
94         };
95     }
96
97     /**
98      * Installs a special border, if either a look-dependent
99      * <code>BorderStyle</code> or a look-independent
100      * <code>HeaderStyle</code> has been specified.
101      * A look specific <code>BorderStyle<code> shadows
102      * a <code>HeaderStyle</code>.<p>
103      *
104      * Specifying a <code>HeaderStyle</code> is recommend.
105      */

106     private void installSpecialBorder() {
107         String JavaDoc suffix;
108         BorderStyle borderStyle =
109             BorderStyle.from(toolBar, WindowsLookAndFeel.BORDER_STYLE_KEY);
110         if (borderStyle == BorderStyle.EMPTY)
111             suffix = "emptyBorder";
112         else if (borderStyle == BorderStyle.SEPARATOR)
113             suffix = "separatorBorder";
114         else if (borderStyle == BorderStyle.ETCHED)
115             suffix = "etchedBorder";
116         else if (HeaderStyle.from(toolBar) == HeaderStyle.BOTH)
117             suffix = "headerBorder";
118         else
119             return;
120         LookAndFeel.installBorder(toolBar, "ToolBar." + suffix);
121     }
122
123     protected DockingListener createDockingListener(JToolBar JavaDoc toolbar) {
124         return new DockingListener(toolbar);
125     }
126
127     // Handling Rollover Borders ********************************************
128

129     protected Border JavaDoc createRolloverBorder() {
130         return WindowsBorders.getRolloverButtonBorder();
131     }
132
133     protected void setBorderToRollover(Component JavaDoc c) {
134         if (c instanceof AbstractButton JavaDoc) {
135             super.setBorderToRollover(c);
136         } else if (c instanceof Container JavaDoc) {
137             Container JavaDoc cont = (Container JavaDoc) c;
138             for (int i = 0; i < cont.getComponentCount(); i++)
139                 super.setBorderToRollover(cont.getComponent(i));
140         }
141     }
142
143 }
Popular Tags