2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
41
package org.netbeans.swing.tabcontrol;
43
import java.awt.Color;
44
import java.awt.Component;
45
import java.awt.Insets;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48
import javax.swing.JComponent;
49
import javax.swing.Timer;
50
import javax.swing.JToggleButton;
51
import javax.swing.SwingConstants;
52
import javax.swing.UIManager;
53
import javax.swing.plaf.ButtonUI;
56
* JToggleButton subclass which maps to an index in the data model, and displays
57
* whatever the content of the data model at that index is. Buttons are added or removed
58
* from the tab displayer as the model changes. This class is public to allow
59
* alternate UIs for the buttons to be provided via subclasses of <code>SlidingButtonUI</code>.
61
* @author Dafe Simonek, Tim Boudreau
63
public final class SlidingButton extends JToggleButton {
64
/** UI Class ID for IndexButtons, to be used by providers of UI delegates */
65
public static final String UI_CLASS_ID = "SlidingButtonUI";
67
// /**** XXX temporary - should go into LFDefaults table *********/
69
// UIManager.getDefaults().put(UI_CLASS_ID, "org.netbeans.core.windows.view.ui.slides.MetalSlidingButtonUI");
72
/** orientation of this button */
73
private int orientation;
74
/** Ascoiated tab data */
78
/** Create a new button representing TabData from the model.
80
* @param buttonData Tab data as text, icon, tooltip etc.
81
* @param orientation horizontal/vertical orientation of the button
83
public SlidingButton(TabData buttonData, int orientation) {
84
super(buttonData.getText(), buttonData.getIcon(), false);
86
// grab the text from client property
87
// XXX please rewrite when API is invented - see issue #55955
88
Component comp = buttonData.getComponent();
89
if (comp instanceof JComponent) {
90
Object slidingName = ((JComponent)comp).getClientProperty("SlidingName");
91
if (slidingName instanceof String) {
92
setText((String)slidingName);
96
this.orientation = orientation;
99
//setFont (displayer.getFont());
101
// setFocusPainted(false);
102
setRolloverEnabled(true);
104
setVerticalAlignment(SwingConstants.CENTER);
105
setHorizontalAlignment(SwingConstants.CENTER);
106
// setMargin(new Insets(1,1,1,1));
107
setMargin(new Insets(0,3,0,3));
108
setBorderPainted(false);
109
// setHorizontalTextPosition(SwingConstants.);
110
// setVerticalTextPosition(SwingConstants.CENTER);
111
// note, updateUI() is called from superclass constructor
114
public void addNotify() {
116
//XXX register with tooltip manager
119
public void removeNotify() {
120
super.removeNotify();
122
//XXX register with tooltip manager
125
public String getToolTipText() {
126
return data.getTooltip();
129
/************** Swing standard technique for attaching UI class *********/
131
public void updateUI () {
132
ButtonUI ui = (ButtonUI)UIManager.getUI(this);
134
// create our default UI class if not found in UIManager
135
ui = (ButtonUI)SlidingButtonUI.createUI(this);
140
public String getUIClassID() {
144
/************ Data accessing methods ***********/
146
/** Returns orinetation of this button */
147
public int getOrientation() {
151
public boolean isBlinking() {
155
private Timer blinkTimer = null;
156
private boolean blinkState = false;
157
public void setBlinking (boolean val) {
158
if (!val && blinkTimer != null) {
161
boolean wasBlinkState = blinkState;
166
} else if (val && blinkTimer == null) {
167
blinkTimer = new Timer(700, new BlinkListener());
174
private class BlinkListener implements ActionListener {
175
public void actionPerformed (ActionEvent ae) {
176
blinkState = !blinkState;
182
* Used by the UI to determine whether to use the blink
183
* color or the regular color
185
public final boolean isBlinkState() {
189
public final Color getBackground() {
190
return isBlinkState() ?
191
new Color(252, 250, 244) : super.getBackground();
194
public TabData getData() {