KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ui > StatusLine


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.core.windows.view.ui;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import org.openide.awt.StatusDisplayer;
24
25 import javax.swing.*;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import java.awt.*;
29 import java.awt.event.ActionListener JavaDoc;
30
31 /** The status line component of the main window.
32 *
33 * @author Jaroslav Tulach, Jesse Glick
34 */

35 final class StatusLine extends JLabel implements ChangeListener JavaDoc, Runnable JavaDoc {
36     private static int SURVIVING_TIME = Integer.getInteger("org.openide.awt.StatusDisplayer.DISPLAY_TIME", 5000);
37     
38     private StatusDisplayer d = StatusDisplayer.getDefault();
39     
40     Object JavaDoc clearing;
41     
42     private class Updater implements ActionListener JavaDoc {
43         
44         private Object JavaDoc token;
45
46         private long startTime;
47         
48         private Timer controller;
49         
50         public Updater(Object JavaDoc token) {
51             this.token = token;
52         }
53         
54         public void schedule() {
55             controller = new Timer(SURVIVING_TIME, this);
56             controller.setDelay(100);
57             controller.start();
58         }
59         
60         public void actionPerformed(ActionEvent JavaDoc arg0) {
61             if (clearing == token) {
62                 long t = System.currentTimeMillis();
63                 if (startTime != 0L) {
64                     Color c = UIManager.getColor("Label.foreground");
65                     if (c != null) {
66                         int alpha = 256 * (int)(t - startTime) / 2000;
67                         StatusLine.this.setForeground(
68                                 new Color(c.getRed(), c.getGreen(), c.getBlue(), 255 - Math.min(255, alpha)));
69                     }
70                 }
71                 else {
72                     startTime = t;
73                 }
74                 if (t > startTime + 2000) {
75                     controller.stop();
76                 }
77             }
78             else {
79                 controller.stop();
80             }
81         }
82     };
83     
84     /** Creates a new StatusLine */
85     public StatusLine () {
86     }
87     
88     public void addNotify() {
89         super.addNotify();
90         run();
91         d.addChangeListener(this);
92     }
93     
94     public void removeNotify() {
95         super.removeNotify();
96         d.removeChangeListener(this);
97     }
98     
99     public void updateUI() {
100         super.updateUI();
101         Font f = UIManager.getFont ("controlFont"); //NOI18N
102
if (f == null) {
103             f = UIManager.getFont ("Tree.font"); //NOI18N
104
}
105         if (f != null) {
106             setFont(f);
107         }
108     }
109
110     public void stateChanged(ChangeEvent JavaDoc e) {
111         if(SwingUtilities.isEventDispatchThread()) {
112             run();
113         } else {
114             SwingUtilities.invokeLater (this);
115         }
116     }
117     
118     /** Called in event queue, should update the status text.
119     */

120     public void run () {
121         String JavaDoc currentMsg = d.getStatusText ();
122         setForeground(UIManager.getColor("Label.foreground"));
123         setText (currentMsg);
124         if (SURVIVING_TIME != 0) {
125             Object JavaDoc token = new Object JavaDoc();
126             clearing = token;
127             if (!"".equals(currentMsg)) {
128                 new Updater(token).schedule();
129             }
130         }
131     }
132     
133     /** #62967: Pref size so that status line is able to shrink as much as possible.
134      */

135     public Dimension getPreferredSize() {
136         return new Dimension(100, 0);
137     }
138     
139     /** #62967: Minimum size so that status line is able to shrink as much as possible.
140      */

141     public Dimension getMinimumSize() {
142         return new Dimension(0, 0);
143     }
144
145 }
146
Popular Tags