KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > filter > plugins > ColorFilter


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.filter.plugins;
17
18 import java.awt.Color JavaDoc;
19
20 import org.columba.core.filter.AbstractFilter;
21 import org.columba.core.filter.FilterCriteria;
22 import org.columba.core.filter.IFilterCriteria;
23 import org.columba.core.folder.api.IFolder;
24 import org.columba.mail.folder.IMailbox;
25
26
27 /**
28  * Filter for filtering on a message color.
29  * @author redsolo
30  */

31 public class ColorFilter extends AbstractFilter {
32     private int defaultColorRGB;
33     private int criteriaRGB;
34     private int criteriaCondition;
35
36     /**
37  * @param f filter containing the configuration.
38  */

39     public ColorFilter() {
40         super();
41
42         defaultColorRGB = Color.black.getRGB();
43     }
44
45     /** {@inheritDoc} */
46     public boolean process(IFolder folder, Object JavaDoc uid) throws Exception JavaDoc {
47         int messageRGB = defaultColorRGB;
48         Color JavaDoc messageColor = (Color JavaDoc) ((IMailbox)folder).getAttribute(uid, "columba.color");
49
50         if (messageColor != null) {
51             messageRGB = messageColor.getRGB();
52         }
53
54         boolean result = false;
55
56         if ((criteriaCondition == FilterCriteria.IS) &&
57                 (messageRGB == criteriaRGB)) {
58             result = true;
59         } else if ((criteriaCondition == FilterCriteria.IS_NOT) &&
60                 (messageRGB != criteriaRGB)) {
61             result = true;
62         }
63
64         return result;
65     }
66
67     /**
68  * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
69  */

70     public void setUp(IFilterCriteria f) {
71         String JavaDoc colorString = f.getPatternString();
72         criteriaRGB = 0;
73         try {
74             criteriaRGB = Integer.parseInt(colorString);
75         } catch (NumberFormatException JavaDoc e) {
76             criteriaRGB = 0;
77         }
78
79         criteriaCondition = f.getCriteria();
80     }
81 }
82
Popular Tags