1 19 20 package org.netbeans.core.windows.view.ui; 21 22 import java.awt.event.ActionEvent ; 23 import org.openide.awt.StatusDisplayer; 24 25 import javax.swing.*; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 28 import java.awt.*; 29 import java.awt.event.ActionListener ; 30 31 35 final class StatusLine extends JLabel implements ChangeListener , Runnable { 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 clearing; 41 42 private class Updater implements ActionListener { 43 44 private Object token; 45 46 private long startTime; 47 48 private Timer controller; 49 50 public Updater(Object 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 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 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"); if (f == null) { 103 f = UIManager.getFont ("Tree.font"); } 105 if (f != null) { 106 setFont(f); 107 } 108 } 109 110 public void stateChanged(ChangeEvent e) { 111 if(SwingUtilities.isEventDispatchThread()) { 112 run(); 113 } else { 114 SwingUtilities.invokeLater (this); 115 } 116 } 117 118 120 public void run () { 121 String currentMsg = d.getStatusText (); 122 setForeground(UIManager.getColor("Label.foreground")); 123 setText (currentMsg); 124 if (SURVIVING_TIME != 0) { 125 Object token = new Object (); 126 clearing = token; 127 if (!"".equals(currentMsg)) { 128 new Updater(token).schedule(); 129 } 130 } 131 } 132 133 135 public Dimension getPreferredSize() { 136 return new Dimension(100, 0); 137 } 138 139 141 public Dimension getMinimumSize() { 142 return new Dimension(0, 0); 143 } 144 145 } 146 | Popular Tags |