001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * GtkToolbarUI.java
043: *
044: * Created on January 17, 2004, 3:00 AM
045: */
046:
047: package org.netbeans.swing.plaf.gtk;
048:
049: import javax.swing.*;
050: import javax.swing.border.Border;
051: import javax.swing.plaf.ButtonUI;
052: import javax.swing.plaf.ComponentUI;
053: import javax.swing.plaf.basic.BasicToolBarUI;
054: import java.awt.*;
055: import java.awt.event.ContainerEvent;
056: import java.awt.event.ContainerListener;
057:
058: /** A ToolbarUI subclass that gets rid of all borders
059: * on buttons and provides a finder-style toolbar look.
060: *
061: * @author Tim Boudreau
062: */
063: public class GtkToolbarUI extends BasicToolBarUI implements
064: ContainerListener {
065: //private Border b = new AdaptiveMatteBorder (true, true, true, true, 3, true);
066: /** Creates a new instance of PlainGtkToolbarUI */
067: private GtkToolbarUI() {
068: }
069:
070: public static ComponentUI createUI(JComponent c) {
071: return new GtkToolbarUI();
072: }
073:
074: public void installUI(JComponent c) {
075: super .installUI(c);
076: //c.setBorder(b);
077: c.setOpaque(false);
078: c.addContainerListener(this );
079: installButtonUIs(c);
080: }
081:
082: public void uninstallUI(JComponent c) {
083: super .uninstallUI(c);
084: c.setBorder(null);
085: c.removeContainerListener(this );
086: }
087:
088: public void paint(Graphics g, JComponent c) {
089: GradientPaint gp = new GradientPaint(0f, 0f, UIManager
090: .getColor("controlHighlight"), //NOI18N
091: 0f, c.getHeight(), UIManager.getColor("control")); //NOI18N
092: ((Graphics2D) g).setPaint(gp);
093: Insets ins = c.getInsets();
094: g.fillRect(ins.left, ins.top, c.getWidth()
095: - (ins.left + ins.top), c.getHeight()
096: - (ins.top + ins.bottom));
097: }
098:
099: protected Border createRolloverBorder() {
100: return BorderFactory.createEmptyBorder(2, 2, 2, 2);
101: }
102:
103: protected Border createNonRolloverBorder() {
104: return createRolloverBorder();
105: }
106:
107: private Border createNonRolloverToggleBorder() {
108: return createRolloverBorder();
109: }
110:
111: protected void setBorderToRollover(Component c) {
112: if (c instanceof AbstractButton) {
113: ((AbstractButton) c).setBorderPainted(false);
114: ((AbstractButton) c).setBorder(BorderFactory
115: .createEmptyBorder());
116: ((AbstractButton) c).setContentAreaFilled(false);
117: ((AbstractButton) c).setOpaque(false);
118: }
119: if (c instanceof JComponent) {
120: ((JComponent) c).setOpaque(false);
121: }
122: }
123:
124: protected void setBorderToNormal(Component c) {
125: if (c instanceof AbstractButton) {
126: ((AbstractButton) c).setBorderPainted(false);
127: ((AbstractButton) c).setContentAreaFilled(false);
128: ((AbstractButton) c).setOpaque(false);
129: }
130: if (c instanceof JComponent) {
131: ((JComponent) c).setOpaque(false);
132: }
133: }
134:
135: public void setFloating(boolean b, Point p) {
136: //nobody wants this
137: }
138:
139: private void installButtonUI(Component c) {
140: if (c instanceof AbstractButton) {
141: ((AbstractButton) c).setUI(buttonui);
142: }
143: if (c instanceof JComponent) {
144: ((JComponent) c).setOpaque(false);
145: }
146: }
147:
148: private void installButtonUIs(Container parent) {
149: Component[] c = parent.getComponents();
150: for (int i = 0; i < c.length; i++) {
151: installButtonUI(c[i]);
152: }
153: }
154:
155: private static final ButtonUI buttonui = new GtkToolBarButtonUI();
156:
157: public void componentAdded(ContainerEvent e) {
158: installButtonUI(e.getChild());
159: }
160:
161: public void componentRemoved(ContainerEvent e) {
162: //do nothing
163: }
164: }
|