KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > message > viewer > SpamStatusViewer


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.message.viewer;
19
20 import java.awt.BorderLayout JavaDoc;
21 import java.awt.Color JavaDoc;
22 import java.awt.Font JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25
26 import javax.swing.BorderFactory JavaDoc;
27 import javax.swing.JButton JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.border.Border JavaDoc;
32
33 import org.columba.core.command.CommandProcessor;
34 import org.columba.mail.command.IMailFolderCommandReference;
35 import org.columba.mail.folder.IMailbox;
36 import org.columba.mail.folder.command.MarkMessageCommand;
37 import org.columba.mail.folder.command.ToggleMarkCommand;
38 import org.columba.mail.gui.frame.MailFrameMediator;
39 import org.columba.mail.gui.message.IMessageController;
40
41 /**
42  * IViewer displaying spam status information.
43  *
44  * @author fdietz
45  *
46  */

47 public class SpamStatusViewer extends JPanel JavaDoc implements ICustomViewer,
48         ActionListener JavaDoc {
49
50
51     private boolean visible;
52
53     private IMessageController mediator;
54
55     private JLabel JavaDoc label;
56
57     private JButton JavaDoc button;
58
59     private JPanel JavaDoc panel;
60
61     public SpamStatusViewer(IMessageController mediator) {
62         super();
63
64         this.mediator = mediator;
65         setBackground(Color.white);
66
67         panel = new JPanel JavaDoc();
68         label = new JLabel JavaDoc("");
69         label.setFont(label.getFont().deriveFont(Font.BOLD));
70         button = new JButton JavaDoc("No Spam");
71
72         setLayout(new BorderLayout JavaDoc());
73         setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
74         panel.setBackground(new Color JavaDoc(0xFABB48));
75         panel.setLayout(new BorderLayout JavaDoc());
76
77         Border JavaDoc border = BorderFactory.createLineBorder(Color.gray);
78
79         panel.setBorder(BorderFactory.createCompoundBorder(border,
80                 BorderFactory.createEmptyBorder(2, 5, 2, 2)));
81
82         add(panel, BorderLayout.CENTER);
83
84         panel.add(label, BorderLayout.WEST);
85
86         panel.add(button, BorderLayout.EAST);
87
88         button.addActionListener(this);
89
90         visible = false;
91     }
92
93     protected void layoutComponents(boolean isSpam) {
94
95         if (isSpam) {
96             panel.removeAll();
97
98             setLayout(new BorderLayout JavaDoc());
99             setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
100             panel.setBackground(new Color JavaDoc(1.0f, 0.8f, 0.5f));
101             panel.setLayout(new BorderLayout JavaDoc());
102             panel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
103
104             add(panel, BorderLayout.CENTER);
105
106             panel.add(label, BorderLayout.WEST);
107
108             panel.add(button, BorderLayout.EAST);
109
110         } else {
111             removeAll();
112         }
113
114         revalidate();
115         updateUI();
116     }
117
118     /**
119      * @see javax.swing.JComponent#updateUI()
120      */

121     public void updateUI() {
122         super.updateUI();
123
124         setBorder(new MessageBorder(new Color JavaDoc(255, 176, 100), 1, true));
125         
126         Color JavaDoc color = new Color JavaDoc(255, 255, 160);
127         
128         if (panel != null)
129             panel.setBackground(color);
130
131
132     }
133
134     private void setSpam(boolean isSpam) {
135
136         if (label != null) {
137             if (isSpam == true)
138                 label.setText("Message is marked as spam");
139             else
140                 label.setText("");
141
142             //layoutComponents(isSpam);
143
}
144     }
145
146     /**
147      * @see org.columba.mail.gui.message.status.Status#show(org.columba.mail.folder.Folder,
148      * java.lang.Object)
149      */

150     public void view(IMailbox folder, Object JavaDoc uid, MailFrameMediator mediator)
151             throws Exception JavaDoc {
152         Boolean JavaDoc spam = (Boolean JavaDoc) folder.getAttribute(uid, "columba.spam");
153
154         visible = spam.booleanValue();
155
156     }
157
158     /**
159      * @see org.columba.mail.gui.message.viewer.IViewer#getView()
160      */

161     public JComponent JavaDoc getView() {
162         return label;
163     }
164
165     /**
166      * @see org.columba.mail.gui.message.viewer.IViewer#isVisible()
167      */

168     public boolean isVisible() {
169         // only show view if message is marked as spam
170
return visible;
171     }
172
173     /**
174      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
175      */

176     public void actionPerformed(ActionEvent JavaDoc arg0) {
177         // get selected message
178
IMailFolderCommandReference r = mediator.getSelectedReference();
179
180         // mark as not spam
181
r.setMarkVariant(MarkMessageCommand.MARK_AS_NOTSPAM);
182         
183         ToggleMarkCommand c = new ToggleMarkCommand(r);
184         CommandProcessor.getInstance().addOp(c);
185     }
186
187     /**
188      * @see org.columba.mail.gui.message.viewer.IViewer#updateGUI()
189      */

190     public void updateGUI() throws Exception JavaDoc {
191         setSpam(visible);
192
193     }
194 }
Popular Tags