001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.gui.message.viewer;
019:
020: import java.awt.BorderLayout;
021: import java.awt.Color;
022: import java.awt.Font;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025:
026: import javax.swing.BorderFactory;
027: import javax.swing.JButton;
028: import javax.swing.JComponent;
029: import javax.swing.JLabel;
030: import javax.swing.JPanel;
031: import javax.swing.border.Border;
032:
033: import org.columba.core.command.CommandProcessor;
034: import org.columba.mail.command.IMailFolderCommandReference;
035: import org.columba.mail.folder.IMailbox;
036: import org.columba.mail.folder.command.MarkMessageCommand;
037: import org.columba.mail.folder.command.ToggleMarkCommand;
038: import org.columba.mail.gui.frame.MailFrameMediator;
039: import org.columba.mail.gui.message.IMessageController;
040:
041: /**
042: * IViewer displaying spam status information.
043: *
044: * @author fdietz
045: *
046: */
047: public class SpamStatusViewer extends JPanel implements ICustomViewer,
048: ActionListener {
049:
050: private boolean visible;
051:
052: private IMessageController mediator;
053:
054: private JLabel label;
055:
056: private JButton button;
057:
058: private JPanel panel;
059:
060: public SpamStatusViewer(IMessageController mediator) {
061: super ();
062:
063: this .mediator = mediator;
064: setBackground(Color.white);
065:
066: panel = new JPanel();
067: label = new JLabel("");
068: label.setFont(label.getFont().deriveFont(Font.BOLD));
069: button = new JButton("No Spam");
070:
071: setLayout(new BorderLayout());
072: setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
073: panel.setBackground(new Color(0xFABB48));
074: panel.setLayout(new BorderLayout());
075:
076: Border border = BorderFactory.createLineBorder(Color.gray);
077:
078: panel.setBorder(BorderFactory.createCompoundBorder(border,
079: BorderFactory.createEmptyBorder(2, 5, 2, 2)));
080:
081: add(panel, BorderLayout.CENTER);
082:
083: panel.add(label, BorderLayout.WEST);
084:
085: panel.add(button, BorderLayout.EAST);
086:
087: button.addActionListener(this );
088:
089: visible = false;
090: }
091:
092: protected void layoutComponents(boolean isSpam) {
093:
094: if (isSpam) {
095: panel.removeAll();
096:
097: setLayout(new BorderLayout());
098: setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
099: panel.setBackground(new Color(1.0f, 0.8f, 0.5f));
100: panel.setLayout(new BorderLayout());
101: panel
102: .setBorder(BorderFactory.createEmptyBorder(2, 2, 2,
103: 2));
104:
105: add(panel, BorderLayout.CENTER);
106:
107: panel.add(label, BorderLayout.WEST);
108:
109: panel.add(button, BorderLayout.EAST);
110:
111: } else {
112: removeAll();
113: }
114:
115: revalidate();
116: updateUI();
117: }
118:
119: /**
120: * @see javax.swing.JComponent#updateUI()
121: */
122: public void updateUI() {
123: super .updateUI();
124:
125: setBorder(new MessageBorder(new Color(255, 176, 100), 1, true));
126:
127: Color color = new Color(255, 255, 160);
128:
129: if (panel != null)
130: panel.setBackground(color);
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 uid,
151: MailFrameMediator mediator) throws Exception {
152: Boolean spam = (Boolean) folder.getAttribute(uid,
153: "columba.spam");
154:
155: visible = spam.booleanValue();
156:
157: }
158:
159: /**
160: * @see org.columba.mail.gui.message.viewer.IViewer#getView()
161: */
162: public JComponent getView() {
163: return label;
164: }
165:
166: /**
167: * @see org.columba.mail.gui.message.viewer.IViewer#isVisible()
168: */
169: public boolean isVisible() {
170: // only show view if message is marked as spam
171: return visible;
172: }
173:
174: /**
175: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
176: */
177: public void actionPerformed(ActionEvent arg0) {
178: // get selected message
179: IMailFolderCommandReference r = mediator.getSelectedReference();
180:
181: // mark as not spam
182: r.setMarkVariant(MarkMessageCommand.MARK_AS_NOTSPAM);
183:
184: ToggleMarkCommand c = new ToggleMarkCommand(r);
185: CommandProcessor.getInstance().addOp(c);
186: }
187:
188: /**
189: * @see org.columba.mail.gui.message.viewer.IViewer#updateGUI()
190: */
191: public void updateGUI() throws Exception {
192: setSpam(visible);
193:
194: }
195: }
|