svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / libAnimation / src / com / iver / cit / gvsig / animation / interval / AnimationDatedInterval.java @ 15489
History | View | Annotate | Download (4.26 KB)
1 |
package com.iver.cit.gvsig.animation.interval; |
---|---|
2 |
|
3 |
import java.sql.Date; |
4 |
import java.text.SimpleDateFormat; |
5 |
import java.util.Calendar; |
6 |
import java.util.Locale; |
7 |
|
8 |
import com.iver.cit.gvsig.animation.IAnimationType; |
9 |
import com.iver.cit.gvsig.animation.dateFilter.DateFilter; |
10 |
import com.iver.utiles.DateTime; |
11 |
import com.iver.utiles.IPersistence; |
12 |
import com.iver.utiles.XMLEntity; |
13 |
|
14 |
public class AnimationDatedInterval implements IAnimationInterval, IPersistence { |
15 |
|
16 |
private Date beginDateInterval; |
17 |
|
18 |
private Date endDateInterval; |
19 |
|
20 |
private String beginDateString = new String(); |
21 |
|
22 |
private String endDateString = new String(); |
23 |
|
24 |
private String sFormat = new String("Y-m-d"); |
25 |
|
26 |
private String className; |
27 |
|
28 |
static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); |
29 |
|
30 |
public Date getBeginDateInterval() { |
31 |
return beginDateInterval;
|
32 |
} |
33 |
|
34 |
public void setBeginDateInterval(Date beginDateInterval) { |
35 |
this.beginDateInterval = beginDateInterval;
|
36 |
} |
37 |
|
38 |
public Date getEndDateInterval() { |
39 |
return endDateInterval;
|
40 |
} |
41 |
|
42 |
public void setEndDateInterval(Date endDateInterval) { |
43 |
this.endDateInterval = endDateInterval;
|
44 |
} |
45 |
|
46 |
public String toString() { |
47 |
String result = "Intervalo de " + this.beginDateInterval + " a " |
48 |
+ this.endDateInterval;
|
49 |
return result;
|
50 |
} |
51 |
|
52 |
public double getEndTime() { |
53 |
return this.endDateInterval.getTime(); |
54 |
} |
55 |
|
56 |
public double getInitialTime() { |
57 |
return this.beginDateInterval.getTime(); |
58 |
} |
59 |
|
60 |
public double getIntervalTime() { |
61 |
return (this.endDateInterval.getTime() - this.beginDateInterval |
62 |
.getTime()); |
63 |
} |
64 |
|
65 |
public void setEndTime(double time) { |
66 |
this.endDateInterval.setTime((long) time); |
67 |
|
68 |
} |
69 |
|
70 |
public void setInitialTime(double time) { |
71 |
this.beginDateInterval.setTime((long) time); |
72 |
|
73 |
} |
74 |
|
75 |
public void setIntervalTime(double time) { |
76 |
// TODO generate method to calculate interval time
|
77 |
|
78 |
} |
79 |
|
80 |
public void apply(double tini, double tend, IAnimationType animationType, |
81 |
Object animated) {
|
82 |
// falta completar la funcion
|
83 |
// System.out.println("PINTANDO OBJETO");
|
84 |
// System.out.println("milisegundos del inicio del intervalo "
|
85 |
// + this.dateToSeconds(this.getBeginDateInterval()));
|
86 |
|
87 |
int day1 = this.getBeginDateInterval().getDate(); |
88 |
int day2 = this.getEndDateInterval().getDate(); |
89 |
int result = linearInterpolate(day1, day2, 0.0, 1.0, tini); |
90 |
// System.out.println("fecha resultante " + result);
|
91 |
int min = (int) (result - 1); |
92 |
// System.out.println("fehca minima " + "2000-01-" + min );
|
93 |
int max = (int) (result + 1); |
94 |
// System.out.println("fehca minima " + "2000-01-" + max );
|
95 |
|
96 |
DateFilter filter = new DateFilter();
|
97 |
filter.setFieldIndex(0); // Date field in com_aut data sample |
98 |
filter.setFieldType(DateFilter.FIELDTYPE_DATESTRING); |
99 |
// filter.setMinDate(Date.valueOf("2000-01-1"));
|
100 |
filter.setMinDate(Date.valueOf("2000-01-" + min)); |
101 |
filter.setMaxDate(Date.valueOf("2000-01-" + max)); |
102 |
|
103 |
animationType.AppliesToObject(filter); |
104 |
|
105 |
} |
106 |
|
107 |
private int linearInterpolate(int minX, int minX2, double timePos, |
108 |
double timePos2, double time) { |
109 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
110 |
|
111 |
double result = ((minX + (minX2 - minX)) * time);
|
112 |
|
113 |
return (int) Math.ceil(result); |
114 |
} |
115 |
|
116 |
private double dateToSeconds(Date date) { |
117 |
Calendar ca = Calendar.getInstance(Locale.US); |
118 |
ca.setTime(date); |
119 |
return ca.getTimeInMillis();
|
120 |
} |
121 |
|
122 |
/*
|
123 |
* IPersistance methods.
|
124 |
*/
|
125 |
|
126 |
public String getClassName() { |
127 |
// TODO Auto-generated method stub
|
128 |
return null; |
129 |
} |
130 |
|
131 |
public XMLEntity getXMLEntity() {
|
132 |
|
133 |
XMLEntity xml = new XMLEntity();
|
134 |
xml.putProperty("className", this.getClassName()); |
135 |
// xml.putProperty("beginDateInterval", beginDateString);
|
136 |
// xml.putProperty("endDateInterval", endDateString);
|
137 |
|
138 |
beginDateString = DateTime.dateToString(beginDateInterval, sFormat); |
139 |
endDateString = DateTime.dateToString(endDateInterval, sFormat); |
140 |
|
141 |
xml.putProperty("begin_date", beginDateString);
|
142 |
xml.putProperty("end_date", endDateString);
|
143 |
|
144 |
return xml;
|
145 |
} |
146 |
|
147 |
public void setXMLEntity(XMLEntity xml) { |
148 |
|
149 |
if (xml.contains("class_name")) |
150 |
className = xml.getStringProperty("class_name");
|
151 |
if (xml.contains("begin_date")) |
152 |
beginDateString = xml.getStringProperty("begin_date");
|
153 |
if (xml.contains("end_date")) |
154 |
endDateString = xml.getStringProperty("end_date");
|
155 |
|
156 |
} |
157 |
} |