File Source: ErrorPanel.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.statusbar.ErrorPanel$1__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.MainFrame;
26 import com.dmdirc.addons.ui_swing.SwingController;
27 import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
28 import com.dmdirc.logger.ErrorLevel;
29 import com.dmdirc.logger.ErrorListener;
30 import com.dmdirc.logger.ErrorManager;
31 import com.dmdirc.logger.ProgramError;
32 import com.dmdirc.ui.IconManager;
33
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.MouseEvent;
37 import java.util.Collection;
38 import java.util.List;
39
40 import javax.swing.Icon;
41 import javax.swing.JLabel;
42 import javax.swing.JMenuItem;
43 import javax.swing.JPopupMenu;
44 import javax.swing.SwingUtilities;
45
46 /**
47 * Shows error status in the status bar.
48 *
49 * @since 0.6.3m1
50 * @author chris
51 */
/*
P/P * Method: ErrorLevel access$102(ErrorPanel, ErrorLevel)
*
* Preconditions:
* x0 != null
*
* Postconditions:
* return_value == x1
* init'ed(return_value)
* x0.errorLevel == return_value
*/
52 public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, ActionListener {
53
54 /**
55 * A version number for this class. It should be changed whenever the class
56 * structure is changed (or anything else that would prevent serialized
57 * objects being unserialized with the new class).
58 */
59 private static final long serialVersionUID = 2;
60
61 /** non error state image icon. */
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.statusbar.ErrorPanel__static_init
*
* Presumptions:
* com.dmdirc.ui.IconManager:getIconManager(...)@62 != null
*
* Postconditions:
* init'ed(DEFAULT_ICON)
*/
62 private static final Icon DEFAULT_ICON = IconManager.getIconManager().
63 getIcon("normal");
64 /** Currently showing error level. */
65 private ErrorLevel errorLevel;
66 /** Status controller. */
67 private final MainFrame mainFrame;
68 /** Swing status bar. */
69 private SwingStatusBar statusBar;
70 /** Error manager. */
71 private final ErrorManager errorManager = ErrorManager.getErrorManager();
72 /** Dismiss menu. */
73 private final JPopupMenu menu;
74 /** Dismiss menu item. */
75 private final JMenuItem dismiss;
76 /** Show menu item. */
77 private final JMenuItem show;
78 /** Swing controller. */
79 private SwingController controller;
80
81 /**
82 * Creates a new ErrorPanel for the speicified status bar.
83 *
84 * @param controller Swing controller
85 * @param mainFrame Main frame
86 * @param statusBar Status bar
87 */
88 public ErrorPanel(final SwingController controller,
89 final MainFrame mainFrame, final SwingStatusBar statusBar) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.statusbar.ErrorPanel(SwingController, MainFrame, SwingStatusBar)
*
* Presumptions:
* com.dmdirc.logger.ErrorManager:getErrorManager(...)@71 != null
*
* Postconditions:
* this.controller == controller
* init'ed(this.controller)
* this.dismiss == &new JMenuItem(ErrorPanel#3)
* this.errorManager != null
* this.label == &new JLabel(ErrorPanel#1)
* this.mainFrame == mainFrame
* init'ed(this.mainFrame)
* this.menu == &new JPopupMenu(ErrorPanel#2)
* this.show == &new JMenuItem(ErrorPanel#4)
* this.statusBar == statusBar
* ...
*/
90 super(new JLabel());
91
92 this.controller = controller;
93 this.mainFrame = mainFrame;
94 this.statusBar = statusBar;
95
96 menu = new JPopupMenu();
97 dismiss = new JMenuItem("Clear All");
98 show = new JMenuItem("Open");
99 label.setIcon(DEFAULT_ICON);
100 setVisible(errorManager.getErrorCount() > 0);
101 menu.add(show);
102 menu.add(dismiss);
103 errorManager.addErrorListener(this);
104 dismiss.addActionListener(this);
105 show.addActionListener(this);
106 checkErrors();
107 }
108
109 /** {@inheritDoc} */
110 @Override
111 protected StatusbarPopupWindow getWindow() {
/*
P/P * Method: StatusbarPopupWindow getWindow()
*
* Postconditions:
* return_value == &new ErrorPopup(getWindow#1)
* new ErrorPopup(getWindow#1) num objects == 1
* return_value.parent == this
* return_value.parent != null
* return_value.parentWindow == this.mainFrame
* init'ed(return_value.parentWindow)
*/
112 return new ErrorPopup(this, mainFrame);
113 }
114
115 /** Clears the error. */
116 public void clearError() {
/*
P/P * Method: void clearError()
*
* Preconditions:
* this.label != null
*
* Postconditions:
* this.errorLevel == null
*/
117 label.setIcon(DEFAULT_ICON);
118 errorLevel = null;
119 }
120
121 /** {@inheritDoc} */
122 @Override
123 public void errorAdded(final ProgramError error) {
/*
P/P * Method: void errorAdded(ProgramError)
*/
124 checkErrors();
125 }
126
127 /** {@inheritDoc} */
128 @Override
129 public void errorDeleted(final ProgramError error) {
/*
P/P * Method: void errorDeleted(ProgramError)
*/
130 checkErrors();
131 }
132
133 /** {@inheritDoc} */
134 @Override
135 public void errorStatusChanged(final ProgramError error) {
136 //Ignore
/*
P/P * Method: void errorStatusChanged(ProgramError)
*/
137 }
138
139 /** Checks all the errors for the most significant error. */
140 private void checkErrors() {
/*
P/P * Method: void checkErrors()
*/
141 SwingUtilities.invokeLater(new Runnable() {
142
143 /** {@inheritDoc} */
144 @Override
145 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* this.errorManager != null
* (soft) this.label != null
*
* Presumptions:
* com.dmdirc.logger.ErrorManager:getErrors(...)@147 != null
* com.dmdirc.logger.ProgramError:getLevel(...)@153 != null
* com.dmdirc.logger.ProgramError:getLevel(...)@155 != null
* java.util.Iterator:next(...)@152 != null
*
* Postconditions:
* init'ed(this.errorLevel)
*
* Test Vectors:
* com.dmdirc.logger.ErrorLevel:moreImportant(...)@153: {1}, {0}
* java.util.Iterator:hasNext(...)@152: {0}, {1}
* java.util.List:isEmpty(...)@149: {0}, {1}
*/
146 clearError();
147 final List<ProgramError> errors = errorManager.getErrors();
148
149 if (errors.isEmpty()) {
150 setVisible(false);
151 } else {
152 for (ProgramError error : errors) {
153 if (errorLevel == null ||
154 !error.getLevel().moreImportant(errorLevel)) {
155 errorLevel = error.getLevel();
156 label.setIcon(errorLevel.getIcon());
157 }
158 }
159 setVisible(true);
160 }
161 }
162 });
163 }
164
165 /** {@inheritDoc} */
166 @Override
167 public boolean isReady() {
/*
P/P * Method: bool isReady()
*
* Preconditions:
* this.statusBar != null
*
* Postconditions:
* init'ed(return_value)
*/
168 return statusBar.isValid();
169 }
170
171 /**
172 * {@inheritDoc}
173 *
174 * @param mouseEvent Mouse event
175 */
176 @Override
177 public void mousePressed(final MouseEvent mouseEvent) {
/*
P/P * Method: void mousePressed(MouseEvent)
*
* Preconditions:
* mouseEvent != null
* (soft) this.menu != null
*/
178 super.mousePressed(mouseEvent);
179 checkMouseEvent(mouseEvent);
180 }
181
182 /**
183 * {@inheritDoc}
184 *
185 * @param mouseEvent Mouse event
186 */
187 @Override
188 public void mouseReleased(final MouseEvent mouseEvent) {
/*
P/P * Method: void mouseReleased(MouseEvent)
*
* Preconditions:
* mouseEvent != null
* (soft) this.menu != null
*/
189 super.mouseReleased(mouseEvent);
190 checkMouseEvent(mouseEvent);
191 }
192
193 /**
194 * {@inheritDoc}
195 *
196 * @param mouseEvent Mouse event
197 */
198 @Override
199 public void mouseEntered(final MouseEvent mouseEvent) {
/*
P/P * Method: void mouseEntered(MouseEvent)
*
* Preconditions:
* mouseEvent != null
* (soft) this.menu != 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)
*/
200 super.mouseEntered(mouseEvent);
201 checkMouseEvent(mouseEvent);
202 }
203
204 /**
205 * {@inheritDoc}
206 *
207 * @param mouseEvent Mouse event
208 */
209 @Override
210 public void mouseExited(final MouseEvent mouseEvent) {
/*
P/P * Method: void mouseExited(MouseEvent)
*
* Preconditions:
* mouseEvent != null
* init'ed(this.dialog)
* (soft) this.dialog.parent != null
* (soft) this.dialog.parentWindow != null
* (soft) this.menu != null
*
* Postconditions:
* this.dialog == null
*/
211 super.mouseExited(mouseEvent);
212 checkMouseEvent(mouseEvent);
213 }
214
215 /**
216 * {@inheritDoc}
217 *
218 * @param mouseEvent Mouse event
219 */
220 @Override
221 public void mouseClicked(final MouseEvent mouseEvent) {
/*
P/P * Method: void mouseClicked(MouseEvent)
*
* Preconditions:
* mouseEvent != null
* (soft) this.controller != null
* (soft) this.menu != null
*
* Test Vectors:
* java.awt.event.MouseEvent:getButton(...)@223: {-231..0, 2..232-1}, {1}
*/
222 super.mouseClicked(mouseEvent);
223 if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
224 controller.showErrorDialog();
225 }
226 checkMouseEvent(mouseEvent);
227 }
228
229 /**
230 * Checks a mouse event for a popup trigger.
231 *
232 * @param e Mouse event
233 */
234 private void checkMouseEvent(MouseEvent e) {
/*
P/P * Method: void checkMouseEvent(MouseEvent)
*
* Preconditions:
* e != null
* (soft) this.menu != null
*
* Test Vectors:
* java.awt.event.MouseEvent:isPopupTrigger(...)@235: {0}, {1}
*/
235 if (e.isPopupTrigger()) {
236 menu.show(this, e.getX(), e.getY());
237 }
238 }
239
240 /**
241 * {@inheritDoc}
242 *
243 * @param e Action event
244 */
245 @Override
246 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* e != null
* (soft) this.controller != null
*
* Presumptions:
* com.dmdirc.logger.ErrorManager:getErrorManager(...)@250 != null
* com.dmdirc.logger.ErrorManager:getErrorManager(...)@253 != null
* com.dmdirc.logger.ErrorManager:getErrors(...)@250 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@252: {0}, {1}
*/
247 if (e.getSource() == show) {
248 controller.showErrorDialog();
249 } else {
250 final Collection<ProgramError> errors =
251 ErrorManager.getErrorManager().getErrors();
252 for (ProgramError error : errors) {
253 ErrorManager.getErrorManager().deleteError(error);
254 }
255 }
256 }
257
258 }
SofCheck Inspector Build Version : 2.17854
| ErrorPanel.java |
2009-Jun-25 01:54:24 |
| ErrorPanel.class |
2009-Sep-02 17:04:17 |
| ErrorPanel$1.class |
2009-Sep-02 17:04:17 |