KickJava   Java API By Example, From Geeks To Geeks.

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


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.Dimension JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.awt.FontMetrics JavaDoc;
26 import java.awt.Graphics JavaDoc;
27 import java.awt.Graphics2D JavaDoc;
28 import java.awt.Insets JavaDoc;
29 import java.awt.Rectangle JavaDoc;
30
31 import javax.swing.plaf.basic.BasicToggleButtonUI JavaDoc;
32 import java.awt.geom.AffineTransform JavaDoc;
33 import javax.swing.AbstractButton JavaDoc;
34 import javax.swing.BorderFactory JavaDoc;
35 import javax.swing.ButtonModel JavaDoc;
36 import javax.swing.Icon JavaDoc;
37 import javax.swing.JComponent JavaDoc;
38 import javax.swing.JToggleButton JavaDoc;
39 import javax.swing.JToolBar JavaDoc;
40 import javax.swing.SwingUtilities JavaDoc;
41 import javax.swing.UIManager JavaDoc;
42 import javax.swing.plaf.ComponentUI JavaDoc;
43 import javax.swing.plaf.basic.BasicHTML JavaDoc;
44 import javax.swing.plaf.metal.MetalToggleButtonUI JavaDoc;
45 import javax.swing.text.View JavaDoc;
46 import org.netbeans.swing.tabcontrol.SlideBarDataModel;
47 import org.netbeans.swing.tabcontrol.SlidingButton;
48 import org.netbeans.swing.tabcontrol.SlidingButtonUI;
49
50 /**
51  *
52  * @see SlidingButtonUI
53  *
54  * @author Milos Kleint
55  */

56 public class MetalSlidingButtonUI extends SlidingButtonUI {
57     // Has the shared instance defaults been initialized?
58
private boolean defaults_initialized = false;
59     protected JToggleButton JavaDoc hiddenToggle;
60     
61     private static final MetalSlidingButtonUI INSTANCE = new MetalSlidingButtonUI();
62
63     private MetalSlidingButtonUI() {
64     }
65     
66     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
67         return INSTANCE;
68     }
69     
70     
71     public void installDefaults (AbstractButton JavaDoc b) {
72         super.installDefaults(b);
73     if(!defaults_initialized) {
74             hiddenToggle = new JToggleButton JavaDoc();
75             hiddenToggle.setText("");
76             JToolBar JavaDoc bar = new JToolBar JavaDoc();
77             bar.setRollover(true);
78             bar.add(hiddenToggle);
79         defaults_initialized = true;
80     }
81     }
82     
83     protected void uninstallDefaults(AbstractButton JavaDoc b) {
84     super.uninstallDefaults(b);
85     defaults_initialized = false;
86     }
87     
88     public void paint(Graphics JavaDoc g, JComponent JavaDoc c) {
89         ColorUtil.setupAntialiasing(g);
90         
91         AbstractButton JavaDoc button = (AbstractButton JavaDoc)c;
92         hiddenToggle.setBorderPainted(true);
93 // hiddenToggle.setBorderPainted(button.isBorderPainted());
94
hiddenToggle.setRolloverEnabled(button.isRolloverEnabled());
95         hiddenToggle.setFocusable(button.isFocusable());
96         hiddenToggle.setFocusPainted(button.isFocusPainted());
97         hiddenToggle.setMargin(button.getMargin());
98 // hiddenToggle.setBorder(button.getBorder());
99
hiddenToggle.getModel().setRollover(button.getModel().isRollover());
100         hiddenToggle.getModel().setPressed(button.getModel().isPressed());
101         hiddenToggle.getModel().setArmed(button.getModel().isArmed());
102         hiddenToggle.getModel().setSelected(button.getModel().isSelected());
103         
104         hiddenToggle.setBounds(button.getBounds());
105         super.paint(g, c);
106     }
107     
108     protected void paintBackground (Graphics2D JavaDoc g, AbstractButton JavaDoc button) {
109         hiddenToggle.setBackground (button.getBackground());
110         hiddenToggle.paint(g);
111     }
112     
113     protected void paintButtonPressed(Graphics JavaDoc g, AbstractButton JavaDoc b) {
114         hiddenToggle.setBackground (b.getBackground());
115         hiddenToggle.paint(g);
116     }
117     
118 }
119
Popular Tags