KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > plaf > WinXPSlidingButtonUI


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.swing.tabcontrol.plaf;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.awt.FontMetrics JavaDoc;
27 import java.awt.Graphics JavaDoc;
28 import java.awt.Graphics2D JavaDoc;
29 import java.awt.Insets JavaDoc;
30 import java.awt.Rectangle JavaDoc;
31
32 import javax.swing.plaf.basic.BasicToggleButtonUI JavaDoc;
33 import java.awt.geom.AffineTransform JavaDoc;
34 import javax.swing.AbstractButton JavaDoc;
35 import javax.swing.BorderFactory JavaDoc;
36 import javax.swing.ButtonModel JavaDoc;
37 import javax.swing.Icon JavaDoc;
38 import javax.swing.JButton JavaDoc;
39 import javax.swing.JComponent JavaDoc;
40 import javax.swing.JToggleButton JavaDoc;
41 import javax.swing.JToolBar JavaDoc;
42 import javax.swing.UIDefaults JavaDoc;
43 import javax.swing.UIManager JavaDoc;
44 import javax.swing.border.Border JavaDoc;
45 import javax.swing.border.CompoundBorder JavaDoc;
46 import javax.swing.plaf.ComponentUI JavaDoc;
47 import javax.swing.plaf.basic.BasicGraphicsUtils JavaDoc;
48 import org.netbeans.swing.tabcontrol.SlidingButton;
49 import org.netbeans.swing.tabcontrol.SlidingButtonUI;
50
51 /**
52  *
53  * @see SlidingButtonUI
54  *
55  * @author Milos Kleint
56  */

57 public class WinXPSlidingButtonUI extends WindowsSlidingButtonUI {
58
59     //XXX
60
private static final SlidingButtonUI INSTANCE = new WinXPSlidingButtonUI();
61     
62     // Has the shared instance defaults been initialized?
63
private boolean defaults_initialized = false;
64     protected JToggleButton JavaDoc hiddenToggle;
65     
66     
67     WinXPSlidingButtonUI() {
68     }
69     
70     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
71         return INSTANCE;
72     }
73
74     /** Install a border on the button */
75     protected void installBorder (AbstractButton JavaDoc b) {
76         // XXX
77
b.setBorder (//BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(),
78
BorderFactory.createEmptyBorder(2, 2, 2, 2));
79     }
80     
81     public void installDefaults (AbstractButton JavaDoc b) {
82         super.installDefaults(b);
83     if(!defaults_initialized) {
84             hiddenToggle = new JToggleButton JavaDoc();
85             hiddenToggle.setText("");
86             JToolBar JavaDoc bar = new JToolBar JavaDoc();
87             bar.add(hiddenToggle);
88         defaults_initialized = true;
89     }
90     }
91     
92     protected void uninstallDefaults(AbstractButton JavaDoc b) {
93     super.uninstallDefaults(b);
94     defaults_initialized = false;
95     }
96     
97     public void paint(Graphics JavaDoc g, JComponent JavaDoc c) {
98         ColorUtil.setupAntialiasing(g);
99         AbstractButton JavaDoc button = (AbstractButton JavaDoc)c;
100         hiddenToggle.setBorderPainted(button.isBorderPainted());
101         hiddenToggle.setRolloverEnabled(button.isRolloverEnabled());
102         hiddenToggle.setFocusable(button.isFocusable());
103         hiddenToggle.setFocusPainted(button.isFocusPainted());
104         hiddenToggle.setMargin(button.getMargin());
105         hiddenToggle.setBorder(button.getBorder());
106         hiddenToggle.getModel().setRollover(button.getModel().isRollover());
107         hiddenToggle.getModel().setPressed(button.getModel().isPressed());
108         hiddenToggle.getModel().setArmed(button.getModel().isArmed());
109         hiddenToggle.getModel().setSelected(button.getModel().isSelected());
110         
111         hiddenToggle.setBounds(button.getBounds());
112         super.paint(g, c);
113     }
114     
115     protected void paintBackground(Graphics2D JavaDoc g, AbstractButton JavaDoc b) {
116         if (((SlidingButton) b).isBlinkState()) {
117             g.setColor(WinClassicEditorTabCellRenderer.ATTENTION_COLOR);
118             g.fillRect (0, 0, b.getWidth(), b.getHeight());
119             hiddenToggle.setFont(b.getFont());
120         } else {
121             hiddenToggle.paint(g);
122         }
123     }
124     
125     protected void paintButtonPressed(Graphics JavaDoc g, AbstractButton JavaDoc b) {
126         hiddenToggle.paint(g);
127     }
128 }
129
Popular Tags