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: package org.netbeans.swing.tabcontrol.plaf;
043:
044: import java.awt.Color;
045: import java.awt.Dimension;
046: import java.awt.Font;
047: import java.awt.FontMetrics;
048: import java.awt.Graphics;
049: import java.awt.Graphics2D;
050: import java.awt.Insets;
051: import java.awt.Rectangle;
052:
053: import javax.swing.plaf.basic.BasicToggleButtonUI;
054: import java.awt.geom.AffineTransform;
055: import javax.swing.AbstractButton;
056: import javax.swing.BorderFactory;
057: import javax.swing.ButtonModel;
058: import javax.swing.Icon;
059: import javax.swing.JComponent;
060: import javax.swing.JToggleButton;
061: import javax.swing.JToolBar;
062: import javax.swing.SwingUtilities;
063: import javax.swing.UIManager;
064: import javax.swing.plaf.ComponentUI;
065: import javax.swing.plaf.basic.BasicHTML;
066: import javax.swing.plaf.metal.MetalToggleButtonUI;
067: import javax.swing.text.View;
068: import org.netbeans.swing.tabcontrol.SlideBarDataModel;
069: import org.netbeans.swing.tabcontrol.SlidingButton;
070: import org.netbeans.swing.tabcontrol.SlidingButtonUI;
071:
072: /**
073: *
074: * @see SlidingButtonUI
075: *
076: * @author Milos Kleint
077: */
078: public class MetalSlidingButtonUI extends SlidingButtonUI {
079: // Has the shared instance defaults been initialized?
080: private boolean defaults_initialized = false;
081: protected JToggleButton hiddenToggle;
082:
083: private static final MetalSlidingButtonUI INSTANCE = new MetalSlidingButtonUI();
084:
085: private MetalSlidingButtonUI() {
086: }
087:
088: public static ComponentUI createUI(JComponent c) {
089: return INSTANCE;
090: }
091:
092: public void installDefaults(AbstractButton b) {
093: super .installDefaults(b);
094: if (!defaults_initialized) {
095: hiddenToggle = new JToggleButton();
096: hiddenToggle.setText("");
097: JToolBar bar = new JToolBar();
098: bar.setRollover(true);
099: bar.add(hiddenToggle);
100: defaults_initialized = true;
101: }
102: }
103:
104: protected void uninstallDefaults(AbstractButton b) {
105: super .uninstallDefaults(b);
106: defaults_initialized = false;
107: }
108:
109: public void paint(Graphics g, JComponent c) {
110: ColorUtil.setupAntialiasing(g);
111:
112: AbstractButton button = (AbstractButton) c;
113: hiddenToggle.setBorderPainted(true);
114: // hiddenToggle.setBorderPainted(button.isBorderPainted());
115: hiddenToggle.setRolloverEnabled(button.isRolloverEnabled());
116: hiddenToggle.setFocusable(button.isFocusable());
117: hiddenToggle.setFocusPainted(button.isFocusPainted());
118: hiddenToggle.setMargin(button.getMargin());
119: // hiddenToggle.setBorder(button.getBorder());
120: hiddenToggle.getModel().setRollover(
121: button.getModel().isRollover());
122: hiddenToggle.getModel().setPressed(
123: button.getModel().isPressed());
124: hiddenToggle.getModel().setArmed(button.getModel().isArmed());
125: hiddenToggle.getModel().setSelected(
126: button.getModel().isSelected());
127:
128: hiddenToggle.setBounds(button.getBounds());
129: super .paint(g, c);
130: }
131:
132: protected void paintBackground(Graphics2D g, AbstractButton button) {
133: hiddenToggle.setBackground(button.getBackground());
134: hiddenToggle.paint(g);
135: }
136:
137: protected void paintButtonPressed(Graphics g, AbstractButton b) {
138: hiddenToggle.setBackground(b.getBackground());
139: hiddenToggle.paint(g);
140: }
141:
142: }
|