KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 package org.netbeans.swing.tabcontrol.plaf;
22
23 import java.awt.Color 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 import java.awt.geom.AffineTransform JavaDoc;
32 import javax.swing.*;
33 import javax.swing.plaf.ComponentUI JavaDoc;
34 import javax.swing.plaf.basic.BasicHTML JavaDoc;
35 import javax.swing.text.View JavaDoc;
36 import org.netbeans.swing.tabcontrol.SlideBarDataModel;
37 import org.netbeans.swing.tabcontrol.SlidingButton;
38 import org.netbeans.swing.tabcontrol.SlidingButtonUI;
39 import org.netbeans.swing.tabcontrol.plaf.GenericGlowingChiclet;
40
41 /**
42  *
43  * @author mkleint
44  */

45 public class AquaSlidingButtonUI extends SlidingButtonUI {
46     
47     private static AquaSlidingButtonUI AQUA_INSTANCE = null;
48     
49     static Color JavaDoc[] rollover = new Color JavaDoc[]{
50         new Color JavaDoc(222, 222, 227), new Color JavaDoc(220, 238, 255), new Color JavaDoc(190, 247, 255),
51         new Color JavaDoc(205, 205, 205)};
52     
53     
54     /** Creates a new instance of AquaSlidingButtonUI */
55     private AquaSlidingButtonUI() {
56     }
57     
58     
59     /** Aqua ui for sliding buttons. This class is public so it can be
60      * instantiated by UIManager, but is of no interest as API. */

61     public static ComponentUI JavaDoc createUI(JComponent c) {
62         if (AQUA_INSTANCE == null) {
63             AQUA_INSTANCE = new AquaSlidingButtonUI();
64         }
65         return AQUA_INSTANCE;
66     }
67
68     public void installUI(JComponent c) {
69         super.installUI(c);
70         c.setFont (UIManager.getFont("Tree.font"));
71     }
72     
73    private ChicletWrapper chic = new ChicletWrapper();
74    protected void paintBackground(Graphics2D JavaDoc graph, AbstractButton b) {
75         chic.setNotch(false, false);
76
77         chic.setState(((SlidingButton) b).isBlinkState() ? GenericGlowingChiclet.STATE_ATTENTION : 0);
78         chic.setArcs(0.5f, 0.5f, 0.5f, 0.5f);
79         chic.setBounds(0, 1, b.getWidth(), b.getHeight() - 2);
80         chic.setAllowVertical(true);
81         chic.draw(graph);
82         chic.setAllowVertical(false);
83     }
84     
85     protected void paintButtonPressed(Graphics JavaDoc graph, AbstractButton b) {
86         chic.setNotch(false, false);
87         int state = 0;
88         state |= b.getModel().isSelected() ? GenericGlowingChiclet.STATE_SELECTED : 0;
89         state |= b.getModel().isPressed() ? GenericGlowingChiclet.STATE_PRESSED : 0;
90         state |= b.getModel().isRollover() ? GenericGlowingChiclet.STATE_ACTIVE : 0;
91         state |= ((SlidingButton) b).isBlinkState() ? GenericGlowingChiclet.STATE_ATTENTION : 0;
92         chic.setState(state);
93         chic.setArcs(0.5f, 0.5f, 0.5f, 0.5f);
94         chic.setBounds(0, 1, b.getWidth(), b.getHeight() - 2);
95         chic.setAllowVertical(true);
96         chic.draw((Graphics2D JavaDoc)graph);
97         chic.setAllowVertical(false);
98     }
99     
100    // ********************************
101
// Layout Methods
102
// ********************************
103
public Dimension JavaDoc getPreferredSize(JComponent c) {
104         SlidingButton slide = (SlidingButton) c;
105     Dimension JavaDoc d = new Dimension JavaDoc(super.getPreferredSize(c));
106         Insets JavaDoc i = c.getInsets();
107         int orientation = slide.getOrientation();
108         
109         if (orientation == SlideBarDataModel.SOUTH) {
110             if (i.top + i.bottom < 5)
111                 d.height += 5;
112             if (i.left + i.right < 7)
113                 d.width += 7;
114         }
115         else {
116             if (i.top + i.bottom < 7)
117                 d.height += 7;
118             if (i.left + i.right < 5)
119                 d.width += 5;
120         }
121
122     return d;
123     }
124 }
125
Popular Tags