File Source: StatusbarPopupPanel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupPanel__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 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 package com.dmdirc.addons.ui_swing.components.statusbar;
23
24 import com.dmdirc.addons.ui_swing.UIUtilities;
25 import com.dmdirc.ui.interfaces.StatusBarComponent;
26
27 import java.awt.Color;
28 import java.awt.Component;
29 import java.awt.Graphics;
30 import java.awt.event.MouseEvent;
31 import java.awt.event.MouseListener;
32 import javax.swing.BorderFactory;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35
36 import javax.swing.UIManager;
37 import javax.swing.border.EtchedBorder;
38
39 import net.miginfocom.swing.MigLayout;
40
41 /**
42 * A panel shown in the status bar which displays a {@link StatusbarPopupWindow}
43 * when the user mouses over it.
44 *
45 * @since 0.6.3m1
46 * @author chris
47 */
/*
P/P * Method: StatusbarPopupWindow access$000(StatusbarPopupPanel)
*
* Preconditions:
* x0 != null
* init'ed(x0.dialog)
*
* Postconditions:
* return_value == x0.dialog
* init'ed(return_value)
*/
48 public abstract class StatusbarPopupPanel extends JPanel
49 implements StatusBarComponent, MouseListener {
50
51 /**
52 * A version number for this class. It should be changed whenever the class
53 * structure is changed (or anything else that would prevent serialized
54 * objects being unserialized with the new class).
55 */
56 private static final long serialVersionUID = 2;
57
58 /** The label we use to show information. */
59 protected final JLabel label;
60
61 /** The popup window we're using to show extra info. */
62 private StatusbarPopupWindow dialog;
63
64 /**
65 * Creates a new {@link StatusbarPopupPanel}, using a default text label.
66 */
67 public StatusbarPopupPanel() {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupPanel()
*
* Postconditions:
* this.label == &new JLabel(StatusbarPopupPanel#1)
* new JLabel(StatusbarPopupPanel#1) num objects == 1
*/
68 this(new JLabel("Unknown"));
69 }
70
71 /**
72 * Creates a new {@link StatusbarPopupPanel}, using the specified label.
73 *
74 * @param label The label to be displayed in the status bar
75 */
76 public StatusbarPopupPanel(final JLabel label) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupPanel(JLabel)
*
* Postconditions:
* this.label == label
* init'ed(this.label)
*/
77 super();
78
79 this.label = label;
80
81 setBorder(BorderFactory.createEtchedBorder());
82 setLayout(new MigLayout("ins 0 rel 0 rel, aligny center"));
83 add(label);
84
85 addMouseListener(this);
86 }
87
88 /**
89 * Closes and reopens the dialog to update information and border positions.
90 */
91 public final void refreshDialog() {
/*
P/P * Method: void refreshDialog()
*/
92 UIUtilities.invokeLater(new Runnable() {
93 @Override
94 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* init'ed(this.dialog)
* (soft) this.dialog.parent != null
* (soft) this.dialog.parentWindow != null
*
* Postconditions:
* init'ed(this.dialog)
* new ErrorPopup(getWindow#1) num objects <= 1
* init'ed(new ErrorPopup(getWindow#1).parent)
* init'ed(new ErrorPopup(getWindow#1).parentWindow)
* init'ed(new ErrorPopup(getWindow#1).server)
* new InvitePopup(getWindow#1) num objects <= 1
* init'ed(new InvitePopup(getWindow#1).parent)
* possibly_updated(new InvitePopup(getWindow#1).parentWindow)
* possibly_updated(new InvitePopup(getWindow#1).server)
*/
95 synchronized (StatusbarPopupPanel.this) {
96 if (dialog != null) {
97 closeDialog();
98 openDialog();
99 }
100 }
101 }
102 });
103 }
104
105 /**
106 * Opens the information dialog.
107 */
108 protected final void openDialog() {
/*
P/P * Method: void openDialog()
*
* Presumptions:
* this.dialog.parent@110 != null
* this.dialog.parentWindow@110 != null
*
* Postconditions:
* this.dialog != null
* new ErrorPopup(getWindow#1) num objects <= 1
* init'ed(new ErrorPopup(getWindow#1).parent)
* init'ed(new ErrorPopup(getWindow#1).parentWindow)
* init'ed(new ErrorPopup(getWindow#1).server)
* new InvitePopup(getWindow#1) num objects <= 1
* init'ed(new InvitePopup(getWindow#1).parent)
* possibly_updated(new InvitePopup(getWindow#1).parentWindow)
* possibly_updated(new InvitePopup(getWindow#1).server)
*/
109 synchronized (StatusbarPopupPanel.this) {
110 dialog = getWindow();
111 dialog.setVisible(true);
112 }
113 }
114
115 /**
116 * Closes the information dialog.
117 */
118 protected final void closeDialog() {
/*
P/P * Method: void closeDialog()
*
* Preconditions:
* init'ed(this.dialog)
* (soft) this.dialog.parent != null
* (soft) this.dialog.parentWindow != null
*
* Postconditions:
* this.dialog == null
*/
119 synchronized (StatusbarPopupPanel.this) {
120 if (dialog != null) {
121 dialog.setVisible(false);
122 dialog.dispose();
123 dialog = null;
124 }
125 }
126 }
127
128 /**
129 * Sets the text for this label.
130 *
131 * @param text New text
132 */
133 public void setText(final String text) {
/*
P/P * Method: void setText(String)
*
* Preconditions:
* this.label != null
*/
134 label.setText(text);
135 }
136
137 /**
138 * Retrieves the implementation of {@link StatusbarPopupWindow} that should
139 * be shown by this panel when the user mouses over it.
140 *
141 * @return A concrete {@link StatusbarPopupWindow} implementation to use
142 */
143 protected abstract StatusbarPopupWindow getWindow();
144
145 /**
146 * {@inheritDoc}
147 *
148 * @param e Mouse event
149 */
150 @Override
151 public void mouseClicked(final MouseEvent e) {
152 // Don't care
/*
P/P * Method: void mouseClicked(MouseEvent)
*/
153 }
154
155 /**
156 * {@inheritDoc}
157 *
158 * @param e Mouse event
159 */
160 @Override
161 public void mousePressed(final MouseEvent e) {
162 // Don't care
/*
P/P * Method: void mousePressed(MouseEvent)
*/
163 }
164
165 /**
166 * {@inheritDoc}
167 *
168 * @param e Mouse event
169 */
170 @Override
171 public void mouseReleased(final MouseEvent e) {
172 // Don't care
/*
P/P * Method: void mouseReleased(MouseEvent)
*/
173 }
174
175 /**
176 * {@inheritDoc}
177 *
178 * @param e Mouse event
179 */
180 @Override
181 public void mouseEntered(final MouseEvent e) {
/*
P/P * Method: void mouseEntered(MouseEvent)
*
* Postconditions:
* this.dialog != null
* new ErrorPopup(getWindow#1) num objects <= 1
* init'ed(new ErrorPopup(getWindow#1).parent)
* init'ed(new ErrorPopup(getWindow#1).parentWindow)
* init'ed(new ErrorPopup(getWindow#1).server)
* new InvitePopup(getWindow#1) num objects <= 1
* init'ed(new InvitePopup(getWindow#1).parent)
* possibly_updated(new InvitePopup(getWindow#1).parentWindow)
* possibly_updated(new InvitePopup(getWindow#1).server)
*/
182 setBackground(UIManager.getColor("ToolTip.background"));
183 setForeground(UIManager.getColor("ToolTip.foreground"));
184 setBorder(new ToplessEtchedBorder());
185
186 openDialog();
187 }
188
189 /**
190 * {@inheritDoc}
191 *
192 * @param e Mouse event
193 */
194 @Override
195 public void mouseExited(final MouseEvent e) {
/*
P/P * Method: void mouseExited(MouseEvent)
*
* Preconditions:
* init'ed(this.dialog)
* (soft) this.dialog.parent != null
* (soft) this.dialog.parentWindow != null
*
* Postconditions:
* this.dialog == null
*/
196 setBackground(null);
197 setForeground(null);
198 setBorder(new EtchedBorder());
199
200 closeDialog();
201 }
202
203 /**
204 * An {@link EtchedBorder} with no top.
205 */
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupPanel$ToplessEtchedBorder(StatusbarPopupPanel$1)
*/
206 private static class ToplessEtchedBorder extends EtchedBorder {
207
208 /**
209 * A version number for this class. It should be changed whenever the class
210 * structure is changed (or anything else that would prevent serialized
211 * objects being unserialized with the new class).
212 */
213 private static final long serialVersionUID = 1;
214
215 /** {@inheritDoc} */
216 @Override
217 public void paintBorder(final Component c, final Graphics g,
218 final int x, final int y, final int width, final int height) {
/*
P/P * Method: void paintBorder(Component, Graphics, int, int, int, int)
*
* Preconditions:
* g != null
* height >= -231+2
* init'ed(this.etchType)
* width >= -231+2
* x <= 231
* y <= 231
*
* Presumptions:
* init'ed(java.awt.Color.WHITE)
*
* Test Vectors:
* this.etchType: {-231..0, 2..232-1}, {1}
*/
219 int w = width;
220 int h = height;
221
222 g.translate(x, y);
223
224 g.setColor(etchType == LOWERED? getShadowColor(c) : getHighlightColor(c));
225 g.drawLine(0, h-2, w, h-2);
226 g.drawLine(0, 0, 0, h-1);
227 g.drawLine(w-2, 0, w-2, h-1);
228
229 g.setColor(Color.WHITE);
230 g.drawLine(0, h-1, w, h-1);
231 g.drawLine(w-1, 0, w-1, h-1);
232
233 g.translate(-x, -y);
234 }
235
236 }
237 }
SofCheck Inspector Build Version : 2.17854
| StatusbarPopupPanel.java |
2009-Jun-25 01:54:24 |
| StatusbarPopupPanel.class |
2009-Sep-02 17:04:14 |
| StatusbarPopupPanel$1.class |
2009-Sep-02 17:04:14 |
| StatusbarPopupPanel$ToplessEtchedBorder.class |
2009-Sep-02 17:04:14 |