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