01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
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: * Filter for filtering on a message color.
28: * @author redsolo
29: */
30: public class ColorFilter extends AbstractFilter {
31: private int defaultColorRGB;
32: private int criteriaRGB;
33: private int criteriaCondition;
34:
35: /**
36: * @param f filter containing the configuration.
37: */
38: public ColorFilter() {
39: super ();
40:
41: defaultColorRGB = Color.black.getRGB();
42: }
43:
44: /** {@inheritDoc} */
45: public boolean process(IFolder folder, Object uid) throws Exception {
46: int messageRGB = defaultColorRGB;
47: Color messageColor = (Color) ((IMailbox) folder).getAttribute(
48: 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 colorString = f.getPatternString();
72: criteriaRGB = 0;
73: try {
74: criteriaRGB = Integer.parseInt(colorString);
75: } catch (NumberFormatException e) {
76: criteriaRGB = 0;
77: }
78:
79: criteriaCondition = f.getCriteria();
80: }
81: }
|