File Source: MessageLabel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.statusbar.MessageLabel__static_init
*/
1 /*
2 * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.ui_swing.components.statusbar;
24
25 import com.dmdirc.addons.ui_swing.UIUtilities;
26 import com.dmdirc.config.IdentityManager;
27 import com.dmdirc.ui.IconManager;
28 import com.dmdirc.ui.interfaces.StatusBarComponent;
29 import com.dmdirc.ui.interfaces.StatusMessageNotifier;
30
31 import java.awt.event.MouseEvent;
32 import java.awt.event.MouseListener;
33 import java.util.Date;
34 import java.util.Timer;
35 import java.util.TimerTask;
36
37 import javax.swing.BorderFactory;
38 import javax.swing.Icon;
39 import javax.swing.JLabel;
40 import javax.swing.SwingUtilities;
41
42 /**
43 * Message label handles showing messages in the status bar.
44 */
/*
P/P * Method: TimerTask access$102(MessageLabel, TimerTask)
*
* Preconditions:
* x0 != null
*
* Postconditions:
* return_value == x1
* init'ed(return_value)
* x0.messageTimer == return_value
*/
45 public class MessageLabel extends JLabel implements StatusBarComponent,
46 MouseListener {
47
48 /**
49 * A version number for this class. It should be changed whenever the class
50 * structure is changed (or anything else that would prevent serialized
51 * objects being unserialized with the new class).
52 */
53 private static final long serialVersionUID = 1;
54 /** Default status bar message. */
55 private static final String DEFAULT_MESSAGE = "Ready.";
56 /** current status bar message notifier. */
57 private transient StatusMessageNotifier messageNotifier;
58 /** Timer to clear the message. */
59 private transient TimerTask messageTimer;
60
61 /**
62 * Instantiates a new message label.
63 */
64 public MessageLabel() {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.statusbar.MessageLabel()
*/
65 super();
66 setText(DEFAULT_MESSAGE);
67 setBorder(BorderFactory.createEtchedBorder());
68 addMouseListener(this);
69 }
70
71 public void setMessage(final String newMessage) {
/*
P/P * Method: void setMessage(String)
*/
72 setMessage(newMessage, (StatusMessageNotifier) null);
73 }
74
75 public void setMessage(final String newMessage,
76 final StatusMessageNotifier newNotifier) {
/*
P/P * Method: void setMessage(String, StatusMessageNotifier)
*/
77 setMessage(null, newMessage, newNotifier);
78 }
79
80 public void setMessage(final String iconType, final String newMessage) {
/*
P/P * Method: void setMessage(String, String)
*/
81 setMessage(iconType, newMessage, null);
82 }
83
84 public void setMessage(final String iconType, final String newMessage,
85 final StatusMessageNotifier newNotifier) {
/*
P/P * Method: void setMessage(String, String, StatusMessageNotifier)
*
* Presumptions:
* com.dmdirc.config.IdentityManager:getGlobalConfig(...)@86 != null
*/
86 final int timeout =
87 IdentityManager.getGlobalConfig().
88 getOptionInt("statusBar", "messageDisplayLength");
89 setMessage(iconType, newMessage, newNotifier, timeout);
90 }
91
92 public void setMessage(final String newMessage,
93 final StatusMessageNotifier newNotifier, final int timeout) {
/*
P/P * Method: void setMessage(String, StatusMessageNotifier, int)
*/
94 setMessage(null, newMessage, newNotifier, timeout);
95 }
96
97 public synchronized void setMessage(final String iconType, final String newMessage,
98 final StatusMessageNotifier newNotifier, final int timeout) {
99 final Icon icon;
/*
P/P * Method: void setMessage(String, String, StatusMessageNotifier, int)
*
* Presumptions:
* com.dmdirc.ui.IconManager:getIconManager(...)@103 != null
*
* Test Vectors:
* iconType: Inverse{null}, Addr_Set{null}
*/
100 if (iconType == null) {
101 icon = null;
102 } else {
103 icon = IconManager.getIconManager().getIcon(iconType);
104 }
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.statusbar.MessageLabel$1(MessageLabel, Icon, String, StatusMessageNotifier, int)
*
* Postconditions:
* this.val$icon == Param_2
* init'ed(this.val$icon)
* this.val$newMessage == Param_3
* init'ed(this.val$newMessage)
* this.val$newNotifier == Param_4
* init'ed(this.val$newNotifier)
* this.val$timeout == Param_5
* init'ed(this.val$timeout)
*/
105 SwingUtilities.invokeLater(new Runnable() {
106
107 /** {@inheritDoc} */
108 @Override
109 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* init'ed(this.messageTimer)
*
* Presumptions:
* this.val$timeout*1_000 + java.lang.System:currentTimeMillis(...)@130 in {-9_223_372_036_854_776_058..18_446_744_073_709_551_365}
*
* Postconditions:
* this.messageNotifier == this.val$newNotifier
* init'ed(this.messageNotifier)
* this.messageTimer == One-of{old this.messageTimer, &new MessageLabel$1$1(run#1)}
* init'ed(this.messageTimer)
* new MessageLabel$1$1(run#1) num objects <= 1
*
* Test Vectors:
* this.messageTimer: Addr_Set{null}, Inverse{null}
* java.lang.String:equals(...)@121: {1}, {0}
*/
110 setIcon(icon);
111 setText(UIUtilities.clipStringifNeeded(MessageLabel.this,
112 newMessage, getWidth()));
113 messageNotifier = newNotifier;
114
115 if (messageTimer != null &&
116 (System.currentTimeMillis() -
117 messageTimer.scheduledExecutionTime()) <= 0) {
118 messageTimer.cancel();
119 }
120
121 if (!DEFAULT_MESSAGE.equals(newMessage)) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.statusbar.MessageLabel$1$1(MessageLabel$1)
*/
122 messageTimer = new TimerTask() {
123
124 /** {@inheritDoc} */
125 @Override
126 public void run() {
/*
P/P * Method: void run()
*/
127 clearMessage();
128 }
129 };
130 new Timer("SwingStatusBar messageTimer").schedule(messageTimer,
131 new Date(System.currentTimeMillis() + 250 +
132 timeout * 1000L));
133 }
134 }
135 });
136
137 }
138
139 /**
140 * Removes the message from the status bar.
141 */
142 public void clearMessage() {
/*
P/P * Method: void clearMessage()
*
* Postconditions:
* this.messageNotifier == null
*/
143 setMessage(DEFAULT_MESSAGE);
144 messageNotifier = null;
145 }
146
147 /**
148 * {@inheritDoc}
149 *
150 * @param e Mouse event
151 */
152 @Override
153 public void mouseClicked(final MouseEvent e) {
/*
P/P * Method: void mouseClicked(MouseEvent)
*
* Preconditions:
* init'ed(this.messageNotifier)
* (soft) e != null
*
* Test Vectors:
* this.messageNotifier: Addr_Set{null}, Inverse{null}
*/
154 if (messageNotifier != null) {
155 messageNotifier.clickReceived(e.getButton(), e.getClickCount());
156 }
157 }
158
159 /**
160 * {@inheritDoc}
161 *
162 * @param e Mouse event
163 */
164 @Override
165 public void mousePressed(final MouseEvent e) {
166 //Ignore
/*
P/P * Method: void mousePressed(MouseEvent)
*/
167 }
168
169 /**
170 * {@inheritDoc}
171 *
172 * @param e Mouse event
173 */
174 @Override
175 public void mouseReleased(final MouseEvent e) {
176 //Ignore
/*
P/P * Method: void mouseReleased(MouseEvent)
*/
177 }
178
179 /**
180 * {@inheritDoc}
181 *
182 * @param e Mouse event
183 */
184 @Override
185 public void mouseEntered(final MouseEvent e) {
186 //Ignore
/*
P/P * Method: void mouseEntered(MouseEvent)
*/
187 }
188
189 /**
190 * {@inheritDoc}
191 *
192 * @param e Mouse event
193 */
194 @Override
195 public void mouseExited(final MouseEvent e) {
196 //Ignore
/*
P/P * Method: void mouseExited(MouseEvent)
*/
197 }
198 }
SofCheck Inspector Build Version : 2.17854
| MessageLabel.java |
2009-Jun-25 01:54:24 |
| MessageLabel.class |
2009-Sep-02 17:04:14 |
| MessageLabel$1.class |
2009-Sep-02 17:04:14 |
| MessageLabel$1$1.class |
2009-Sep-02 17:04:14 |