KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.Graphics JavaDoc;
36 import java.beans.PropertyChangeEvent JavaDoc;
37 import java.beans.PropertyChangeListener JavaDoc;
38
39 import javax.swing.AbstractButton JavaDoc;
40 import javax.swing.JComponent JavaDoc;
41 import javax.swing.JToolBar JavaDoc;
42 import javax.swing.LookAndFeel JavaDoc;
43 import javax.swing.plaf.ComponentUI JavaDoc;
44
45 import com.sun.java.swing.plaf.windows.WindowsToolBarUI;
46
47 import com.jgoodies.looks.BorderStyle;
48 import com.jgoodies.looks.HeaderStyle;
49 import com.jgoodies.looks.Options;
50
51 /**
52  * Adds behavior for handling different types of borders.
53  *
54  * @author Karsten Lentzsch
55  * @version $Revision: 1.2 $
56  */

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

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

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

135     protected void setBorderToRollover(Component JavaDoc c) {
136         if (c instanceof AbstractButton JavaDoc) {
137             super.setBorderToRollover(c);
138         } else if (c instanceof Container JavaDoc) {
139             Container JavaDoc cont = (Container JavaDoc) c;
140             for (int i = 0; i < cont.getComponentCount(); i++)
141                 super.setBorderToRollover(cont.getComponent(i));
142         }
143     }
144     
145
146     // Painting *************************************************************
147

148     public void paint(Graphics JavaDoc g, JComponent JavaDoc c) {
149     }
150
151 }
Popular Tags