Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libAnimation / src / com / iver / cit / gvsig / animation / dateFilter / DateFilter.java @ 23598

History | View | Annotate | Download (4.26 KB)

1
package com.iver.cit.gvsig.animation.dateFilter;
2

    
3

    
4
//public class DateFilter implements ICustomVectorialFilter, IPersistence {
5
        public class DateFilter {
6
//
7
//        public static int FIELDTYPE_DATE = 0;
8
//        public static int FIELDTYPE_DATESTRING = 1;
9
//
10
//        public static int BOTH = 2 | 4;
11
//        public static int BEFORE_BEGIN = 2;
12
//        public static int AFTER_END = 4;
13
//
14
//        private int fieldType = -1;
15
//
16
//        private int filterFieldIndex = -1;
17
//        private Date minDate = null;
18
//        private Date maxDate = null;
19
//        // derived
20
//        private SimpleDateFormat localeDF = null;
21
//        private SimpleDateFormat javaDF = null;
22
//        private Calendar cl = null;
23
//
24
//        private int filterMode = BEFORE_BEGIN;
25
//
26
//        public void setFieldIndex(int index) {
27
//                filterFieldIndex = index;
28
//        }
29
//
30
//        public void setFieldType(int type) {
31
//                fieldType = type;
32
//        }
33
//
34
//        public void setMinDate(Date miniDate) {
35
//                minDate = miniDate;
36
//        }
37
//
38
//        public void setMaxDate(Date maxiDate) {
39
//                maxDate = maxiDate;
40
//        }
41
//
42
//        public int getFieldType() {
43
//                return fieldType;
44
//        }
45
//
46
//        public Date getMinDate() {
47
//                return minDate;
48
//        }
49
//
50
//        public Date getMaxDate() {
51
//                return maxDate;
52
//        }
53
//
54
//        public boolean accepts(IFeature feature) {
55
//
56
//                if (filterFieldIndex == -1 || minDate == null || maxDate == null)
57
//                        return false;
58
//
59
//                Value val = feature.getAttribute(filterFieldIndex);
60
//                if (val instanceof NullValue)
61
//                        return false;
62
//
63
//                Date dateVal = null;
64
//                if (fieldType == FIELDTYPE_DATE) {
65
//                        try {
66
//                                dateVal = ((DateValue) val).getValue();
67
//                        } catch (RuntimeException e) {
68
//                                return false;
69
//                        }
70
//                } else if (fieldType == FIELDTYPE_DATESTRING) {
71
//                        if (localeDF == null)
72
//                                localeDF = new SimpleDateFormat("dd/MM/yyyy");
73
//                        if (javaDF == null)
74
//                                javaDF = new SimpleDateFormat("yyyy-MM-dd");
75
//
76
//                        String valStr = val.toString();
77
//
78
//                        try {
79
//                                java.util.Date utDate = localeDF.parse(valStr); // reads locale
80
//                                // dd/MM/yyyy
81
//                                // strings
82
//                                String utDateStr = javaDF.format(utDate); // outputs
83
//                                // yyyy-MM-dd
84
//                                dateVal = Date.valueOf(utDateStr); // creates Date for
85
//                                // comparison
86
//                        } catch (ParseException e) {
87
//                                return false;
88
//                        }
89
//                }
90
//
91
//                try {
92
//                        String dateValStr = dateVal.toString();
93
//                        String minDateStr = minDate.toString();
94
//                        String maxDateStr = maxDate.toString();
95
//
96
//                        if (((this.filterMode & BEFORE_BEGIN) != BEFORE_BEGIN))
97
//                                if (dateVal.compareTo(minDate) < 0)
98
//                                        return false;
99
//
100
//                        if (((this.filterMode & AFTER_END) != AFTER_END))
101
//                                if (dateVal.compareTo(maxDate) > 0)
102
//                                        return false;
103
//
104
//                } catch (Exception e) {
105
//                        return false;
106
//                }
107
//                return true;
108
//        }
109
//
110
//        public String getClassName() {
111
//                return this.getClass().getName();
112
//        }
113
//
114
//        public XMLEntity getXMLEntity() {
115
//                XMLEntity xml = new XMLEntity();
116
//
117
//                xml.putProperty("fieldType", fieldType);
118
//                xml.putProperty("fieldIndex", filterFieldIndex);
119
//                xml.putProperty("minDate", minDate.toString());
120
//                xml.putProperty("maxDate", maxDate.toString());
121
//
122
//                return xml;
123
//        }
124
//
125
//        public void setXMLEntity(XMLEntity xml) {
126
//                if (xml.contains("fieldType"))
127
//                        fieldType = xml.getIntProperty("fieldType");
128
//
129
//                if (xml.contains("fieldIndex"))
130
//                        filterFieldIndex = xml.getIntProperty("fieldIndex");
131
//
132
//                if (xml.contains("minDate"))
133
//                        minDate = Date.valueOf(xml.getStringProperty("minDate"));
134
//
135
//                if (xml.contains("maxDate"))
136
//                        maxDate = Date.valueOf(xml.getStringProperty("maxDate"));
137
//        }
138
//
139
//        public String toString() {
140
//                String result = "";
141
//
142
//                result += minDate.toString() + "\n" + maxDate.toString();
143
//
144
//                return result;
145
//        }
146
//
147
//        public boolean compareTo(ICustomVectorialFilter filter) {
148
//                DateFilter filterAux = (DateFilter) filter;
149
//                boolean type = this.getFieldType() == filterAux.getFieldType();
150
//                boolean min = this.getMinDate().toString().equals(
151
//                                filterAux.getMinDate().toString());
152
//                boolean max = this.getMaxDate().toString().equals(
153
//                                filterAux.getMaxDate().toString());
154
//
155
//                return (type && min && max);
156
//        }
157
//
158
//        public int getFilterMode() {
159
//                return filterMode;
160
//        }
161
//
162
//        public void setFilterMode(int filterMode) {
163
//                this.filterMode = filterMode;
164
//        }
165
}