KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > plaf > gtk > GtkToolbarUI


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * GtkToolbarUI.java
21  *
22  * Created on January 17, 2004, 3:00 AM
23  */

24
25 package org.netbeans.swing.plaf.gtk;
26
27 import javax.swing.*;
28 import javax.swing.border.Border JavaDoc;
29 import javax.swing.plaf.ButtonUI JavaDoc;
30 import javax.swing.plaf.ComponentUI JavaDoc;
31 import javax.swing.plaf.basic.BasicToolBarUI JavaDoc;
32 import java.awt.*;
33 import java.awt.event.ContainerEvent JavaDoc;
34 import java.awt.event.ContainerListener JavaDoc;
35
36 /** A ToolbarUI subclass that gets rid of all borders
37  * on buttons and provides a finder-style toolbar look.
38  *
39  * @author Tim Boudreau
40  */

41 public class GtkToolbarUI extends BasicToolBarUI JavaDoc implements ContainerListener JavaDoc {
42     //private Border b = new AdaptiveMatteBorder (true, true, true, true, 3, true);
43
/** Creates a new instance of PlainGtkToolbarUI */
44     private GtkToolbarUI() {
45     }
46     
47     public static ComponentUI JavaDoc createUI(JComponent c) {
48         return new GtkToolbarUI();
49     }
50     
51     public void installUI( JComponent c ) {
52         super.installUI(c);
53         //c.setBorder(b);
54
c.setOpaque(false);
55         c.addContainerListener(this);
56         installButtonUIs (c);
57     }
58     
59     public void uninstallUI (JComponent c) {
60         super.uninstallUI (c);
61         c.setBorder (null);
62         c.removeContainerListener(this);
63     }
64     
65     public void paint(Graphics g, JComponent c) {
66         GradientPaint gp = new GradientPaint (0f, 0f,
67             UIManager.getColor("controlHighlight"), //NOI18N
68
0f, c.getHeight(),
69             UIManager.getColor("control")); //NOI18N
70
((Graphics2D) g).setPaint (gp);
71         Insets ins = c.getInsets();
72         g.fillRect (ins.left, ins.top, c.getWidth() - (ins.left + ins.top), c.getHeight() - (ins.top + ins.bottom));
73     }
74     
75     
76     protected Border JavaDoc createRolloverBorder() {
77         return BorderFactory.createEmptyBorder(2,2,2,2);
78     }
79     
80     protected Border JavaDoc createNonRolloverBorder() {
81         return createRolloverBorder();
82     }
83     
84     private Border JavaDoc createNonRolloverToggleBorder() {
85         return createRolloverBorder();
86     }
87     
88     protected void setBorderToRollover(Component c) {
89         if (c instanceof AbstractButton) {
90             ((AbstractButton) c).setBorderPainted(false);
91             ((AbstractButton) c).setBorder(BorderFactory.createEmptyBorder());
92             ((AbstractButton) c).setContentAreaFilled(false);
93             ((AbstractButton) c).setOpaque(false);
94         }
95         if (c instanceof JComponent) {
96             ((JComponent) c).setOpaque(false);
97         }
98     }
99     
100     protected void setBorderToNormal(Component c) {
101         if (c instanceof AbstractButton) {
102             ((AbstractButton) c).setBorderPainted(false);
103             ((AbstractButton) c).setContentAreaFilled(false);
104             ((AbstractButton) c).setOpaque(false);
105         }
106         if (c instanceof JComponent) {
107             ((JComponent) c).setOpaque(false);
108         }
109     }
110     
111     public void setFloating(boolean b, Point p) {
112         //nobody wants this
113
}
114     
115     private void installButtonUI (Component c) {
116         if (c instanceof AbstractButton) {
117             ((AbstractButton) c).setUI(buttonui);
118         }
119         if (c instanceof JComponent) {
120             ((JComponent) c).setOpaque(false);
121         }
122     }
123     
124     private void installButtonUIs (Container parent) {
125         Component[] c = parent.getComponents();
126         for (int i=0; i < c.length; i++) {
127             installButtonUI(c[i]);
128         }
129     }
130     
131     private static final ButtonUI JavaDoc buttonui = new GtkToolBarButtonUI();
132     public void componentAdded(ContainerEvent JavaDoc e) {
133         installButtonUI (e.getChild());
134     }
135     
136     public void componentRemoved(ContainerEvent JavaDoc e) {
137         //do nothing
138
}
139 }
140
Popular Tags