Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LastMailPane |
|
| 1.6666666666666667;1.667 |
1 | package com.nilhcem.fakesmtp.gui.tab; | |
2 | ||
3 | import com.nilhcem.fakesmtp.gui.info.ClearAllButton; | |
4 | import com.nilhcem.fakesmtp.model.EmailModel; | |
5 | import com.nilhcem.fakesmtp.server.MailSaver; | |
6 | ||
7 | import javax.swing.JScrollPane; | |
8 | import javax.swing.JTextArea; | |
9 | import java.util.Observable; | |
10 | import java.util.Observer; | |
11 | ||
12 | /** | |
13 | * Scrolled text area where will be displayed the last received email. | |
14 | * | |
15 | * @author Nilhcem | |
16 | * @since 1.0 | |
17 | */ | |
18 | public final class LastMailPane implements Observer { | |
19 | ||
20 | 0 | private final JScrollPane lastMailPane = new JScrollPane(); |
21 | 0 | private final JTextArea lastMailArea = new JTextArea(); |
22 | ||
23 | /** | |
24 | * Creates the text area and disables the possibility to edit it. | |
25 | */ | |
26 | 0 | public LastMailPane() { |
27 | 0 | lastMailArea.setEditable(false); |
28 | 0 | lastMailPane.getViewport().add(lastMailArea, null); |
29 | 0 | } |
30 | ||
31 | /** | |
32 | * Returns the JScrollPane object. | |
33 | * | |
34 | * @return the JScrollPane object. | |
35 | */ | |
36 | public JScrollPane get() { | |
37 | 0 | return lastMailPane; |
38 | } | |
39 | ||
40 | /** | |
41 | * Updates the content of the text area. | |
42 | * <p> | |
43 | * This method will be called by an observable element. | |
44 | * </p> | |
45 | * <ul> | |
46 | * <li>If the observable is a {@link MailSaver} object, the text area will contain the content of the last received email;</li> | |
47 | * <li>If the observable is a {@link ClearAllButton} object, the text area will be cleared.</li> | |
48 | * </ul> | |
49 | * | |
50 | * @param o the observable element which will notify this class. | |
51 | * @param data optional parameters (an {@code EmailModel} object, for the case of a {@code MailSaver} observable). | |
52 | */ | |
53 | @Override | |
54 | public synchronized void update(Observable o, Object data) { | |
55 | 0 | if (o instanceof MailSaver) { |
56 | 0 | EmailModel model = (EmailModel) data; |
57 | 0 | lastMailArea.setText(model.getEmailStr()); |
58 | 0 | } else if (o instanceof ClearAllButton) { |
59 | 0 | lastMailArea.setText(""); |
60 | } | |
61 | 0 | } |
62 | } |