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: import java.awt.geom.AffineTransform;
053: import javax.swing.*;
054: import javax.swing.plaf.ComponentUI;
055: import javax.swing.plaf.basic.BasicHTML;
056: import javax.swing.text.View;
057: import org.netbeans.swing.tabcontrol.SlideBarDataModel;
058: import org.netbeans.swing.tabcontrol.SlidingButton;
059: import org.netbeans.swing.tabcontrol.SlidingButtonUI;
060: import org.netbeans.swing.tabcontrol.plaf.GenericGlowingChiclet;
061:
062: /**
063: *
064: * @author mkleint
065: */
066: public class AquaSlidingButtonUI extends SlidingButtonUI {
067:
068: private static AquaSlidingButtonUI AQUA_INSTANCE = null;
069:
070: static Color[] rollover = new Color[] { new Color(222, 222, 227),
071: new Color(220, 238, 255), new Color(190, 247, 255),
072: new Color(205, 205, 205) };
073:
074: /** Creates a new instance of AquaSlidingButtonUI */
075: private AquaSlidingButtonUI() {
076: }
077:
078: /** Aqua ui for sliding buttons. This class is public so it can be
079: * instantiated by UIManager, but is of no interest as API. */
080: public static ComponentUI createUI(JComponent c) {
081: if (AQUA_INSTANCE == null) {
082: AQUA_INSTANCE = new AquaSlidingButtonUI();
083: }
084: return AQUA_INSTANCE;
085: }
086:
087: public void installUI(JComponent c) {
088: super .installUI(c);
089: c.setFont(UIManager.getFont("Tree.font"));
090: }
091:
092: private ChicletWrapper chic = new ChicletWrapper();
093:
094: protected void paintBackground(Graphics2D graph, AbstractButton b) {
095: chic.setNotch(false, false);
096:
097: chic
098: .setState(((SlidingButton) b).isBlinkState() ? GenericGlowingChiclet.STATE_ATTENTION
099: : 0);
100: chic.setArcs(0.5f, 0.5f, 0.5f, 0.5f);
101: chic.setBounds(0, 1, b.getWidth(), b.getHeight() - 2);
102: chic.setAllowVertical(true);
103: chic.draw(graph);
104: chic.setAllowVertical(false);
105: }
106:
107: protected void paintButtonPressed(Graphics graph, AbstractButton b) {
108: chic.setNotch(false, false);
109: int state = 0;
110: state |= b.getModel().isSelected() ? GenericGlowingChiclet.STATE_SELECTED
111: : 0;
112: state |= b.getModel().isPressed() ? GenericGlowingChiclet.STATE_PRESSED
113: : 0;
114: state |= b.getModel().isRollover() ? GenericGlowingChiclet.STATE_ACTIVE
115: : 0;
116: state |= ((SlidingButton) b).isBlinkState() ? GenericGlowingChiclet.STATE_ATTENTION
117: : 0;
118: chic.setState(state);
119: chic.setArcs(0.5f, 0.5f, 0.5f, 0.5f);
120: chic.setBounds(0, 1, b.getWidth(), b.getHeight() - 2);
121: chic.setAllowVertical(true);
122: chic.draw((Graphics2D) graph);
123: chic.setAllowVertical(false);
124: }
125:
126: // ********************************
127: // Layout Methods
128: // ********************************
129: public Dimension getPreferredSize(JComponent c) {
130: SlidingButton slide = (SlidingButton) c;
131: Dimension d = new Dimension(super .getPreferredSize(c));
132: Insets i = c.getInsets();
133: int orientation = slide.getOrientation();
134:
135: if (orientation == SlideBarDataModel.SOUTH) {
136: if (i.top + i.bottom < 5)
137: d.height += 5;
138: if (i.left + i.right < 7)
139: d.width += 7;
140: } else {
141: if (i.top + i.bottom < 7)
142: d.height += 7;
143: if (i.left + i.right < 5)
144: d.width += 5;
145: }
146:
147: return d;
148: }
149: }
|