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