1 19 20 package org.netbeans.modules.tasklist.core.filter; 21 22 import java.awt.Component ; 23 import java.lang.reflect.InvocationTargetException ; 24 import java.text.ParseException ; 25 import java.text.SimpleDateFormat ; 26 import java.util.Date ; 27 import javax.swing.*; 28 29 import org.openide.ErrorManager; 30 import org.openide.nodes.Node; 31 import org.openide.util.NbBundle; 32 33 39 public class IntegerFilterCondition extends OneOfFilterCondition { 40 public static final int EQUALS = 0; 41 public static final int NOTEQUALS = 1; 42 public static final int LESSTHAN = 2; 43 public static final int LESSOREQUALS = 3; 44 public static final int GREATERTHAN = 4; 45 public static final int GREATEROREQUALS = 5; 46 47 52 public static IntegerFilterCondition[] createConditions() { 53 return new IntegerFilterCondition[] { 54 new IntegerFilterCondition(IntegerFilterCondition.EQUALS), 55 new IntegerFilterCondition(IntegerFilterCondition.NOTEQUALS), 56 new IntegerFilterCondition(IntegerFilterCondition.LESSTHAN), 57 new IntegerFilterCondition(IntegerFilterCondition.LESSOREQUALS), 58 new IntegerFilterCondition(IntegerFilterCondition.GREATERTHAN), 59 new IntegerFilterCondition(IntegerFilterCondition.GREATEROREQUALS) 60 }; 61 }; 62 63 private static String [] NAME_KEYS = { 64 "Equals", "NotEquals", "LessThan", "LessEquals", "GreaterThan", "GreaterEquals", }; 71 72 73 private int constant; 74 75 81 public IntegerFilterCondition(int id) { 82 super(NAME_KEYS, id); 83 } 84 85 public IntegerFilterCondition(final IntegerFilterCondition rhs) { 86 super(rhs); 87 this.constant = rhs.constant; 88 } 89 90 public Object clone() { 91 return new IntegerFilterCondition(this); 92 } 93 94 95 private IntegerFilterCondition() {super(NAME_KEYS); this.constant = -1; } 96 97 public JComponent createConstantComponent() { 98 JTextField tf = new JTextField(); 99 tf.setText(String.valueOf(constant)); 100 tf.setToolTipText(Util.getString("int_desc")); 101 return tf; 102 } 103 104 public void getConstantFrom(JComponent cmp) { 105 JTextField tf = (JTextField) cmp; 106 try { 107 constant = Integer.parseInt(tf.getText()); 108 } catch (NumberFormatException e) { 109 } 111 } 112 113 public boolean isTrue(Object obj) { 114 int n = ((Integer ) obj).intValue(); 115 switch (getId()) { 116 case EQUALS: 117 return constant == n; 118 case NOTEQUALS: 119 return constant != n; 120 case LESSTHAN: 121 return n < constant; 122 case LESSOREQUALS: 123 return n <= constant; 124 case GREATERTHAN: 125 return n > constant; 126 case GREATEROREQUALS: 127 return n >= constant; 128 default: 129 throw new InternalError ("wrong id"); 130 } 131 } 132 133 private static class Convertor extends OneOfFilterCondition.Convertor { 134 private static final String ELEM_INTEGER_CONDITION = "IntegerCondition"; 135 private static final String ATTR_CONSTANT = "constant"; 136 137 public Convertor() { super(ELEM_INTEGER_CONDITION, NAME_KEYS);} 138 public static IntegerFilterCondition.Convertor create() { 139 return new IntegerFilterCondition.Convertor(); 140 } 141 142 protected Object readElement(org.w3c.dom.Element element) 143 throws java.io.IOException , java.lang.ClassNotFoundException 144 { 145 IntegerFilterCondition cond = new IntegerFilterCondition(); 146 super.readCondition(element, cond); 147 cond.constant = Integer.parseInt(element.getAttribute(ATTR_CONSTANT)); 148 return cond; 149 } 150 151 protected void writeElement(org.w3c.dom.Document document, org.w3c.dom.Element element, Object obj) 153 throws java.io.IOException , org.w3c.dom.DOMException 154 { 155 IntegerFilterCondition cond = (IntegerFilterCondition)obj; 156 super.writeCondition(document, element, cond); 157 element.setAttribute(ATTR_CONSTANT, Integer.toString(cond.constant)); 158 } 159 } 160 161 } 162 | Popular Tags |