svn-gvsig-desktop / trunk / libraries / libAnimation / src / com / iver / cit / gvsig / animation / interval / AnimationDatedInterval.java @ 23598
History | View | Annotate | Download (4.95 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
package com.iver.cit.gvsig.animation.interval; |
21 |
|
22 |
import java.sql.Date; |
23 |
import java.text.SimpleDateFormat; |
24 |
import java.util.Calendar; |
25 |
import java.util.Locale; |
26 |
|
27 |
import com.iver.cit.gvsig.animation.IAnimationType; |
28 |
import com.iver.utiles.DateTime; |
29 |
import com.iver.utiles.IPersistence; |
30 |
import com.iver.utiles.XMLEntity; |
31 |
|
32 |
public class AnimationDatedInterval implements IAnimationInterval, IPersistence { |
33 |
|
34 |
private Date beginDateInterval; |
35 |
|
36 |
private Date endDateInterval; |
37 |
|
38 |
private String beginDateString = new String(); |
39 |
|
40 |
private String endDateString = new String(); |
41 |
|
42 |
private String sFormat = new String("Y-m-d"); |
43 |
|
44 |
static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); |
45 |
|
46 |
public Date getBeginDateInterval() { |
47 |
return beginDateInterval;
|
48 |
} |
49 |
|
50 |
public void setBeginDateInterval(Date beginDateInterval) { |
51 |
this.beginDateInterval = beginDateInterval;
|
52 |
} |
53 |
|
54 |
public Date getEndDateInterval() { |
55 |
return endDateInterval;
|
56 |
} |
57 |
|
58 |
public void setEndDateInterval(Date endDateInterval) { |
59 |
this.endDateInterval = endDateInterval;
|
60 |
} |
61 |
|
62 |
public String toString() { |
63 |
String result = "Intervalo de " + this.beginDateInterval + " a " |
64 |
+ this.endDateInterval;
|
65 |
return result;
|
66 |
} |
67 |
|
68 |
public double getEndTime() { |
69 |
return this.endDateInterval.getTime(); |
70 |
} |
71 |
|
72 |
public double getInitialTime() { |
73 |
return this.beginDateInterval.getTime(); |
74 |
} |
75 |
|
76 |
public double getIntervalTime() { |
77 |
return (this.endDateInterval.getTime() - this.beginDateInterval |
78 |
.getTime()); |
79 |
} |
80 |
|
81 |
public void setEndTime(double time) { |
82 |
this.endDateInterval.setTime((long) time); |
83 |
|
84 |
} |
85 |
|
86 |
public void setInitialTime(double time) { |
87 |
this.beginDateInterval.setTime((long) time); |
88 |
|
89 |
} |
90 |
|
91 |
public void setIntervalTime(double time) { |
92 |
// TODO generate method to calculate interval time
|
93 |
} |
94 |
|
95 |
public void apply(double tini, double tend, IAnimationType animationType, |
96 |
Object animated) {
|
97 |
// falta completar la funcion
|
98 |
// System.out.println("PINTANDO OBJETO");
|
99 |
// System.out.println("milisegundos del inicio del intervalo "
|
100 |
// + this.dateToSeconds(this.getBeginDateInterval()));
|
101 |
|
102 |
// int day1 = this.getBeginDateInterval().getDate();
|
103 |
// int day2 = this.getEndDateInterval().getDate();
|
104 |
// int result = linearInterpolate(day1, day2, 0.0, 1.0, tini);
|
105 |
// // System.out.println("fecha resultante " + result);
|
106 |
// int min = (int) (result - 1);
|
107 |
// // System.out.println("fehca minima " + "2000-01-" + min );
|
108 |
// int max = (int) (result + 1);
|
109 |
// // System.out.println("fehca minima " + "2000-01-" + max );
|
110 |
//
|
111 |
// DateFilter filter = new DateFilter();
|
112 |
// filter.setFieldIndex(0); // Date field in com_aut data sample
|
113 |
// filter.setFieldType(DateFilter.FIELDTYPE_DATESTRING);
|
114 |
//// filter.setMinDate(Date.valueOf("2000-01-1"));
|
115 |
// filter.setMinDate(Date.valueOf("2000-01-" + min));
|
116 |
// filter.setMaxDate(Date.valueOf("2000-01-" + max));
|
117 |
|
118 |
animationType.AppliesToObject(animated); |
119 |
|
120 |
} |
121 |
|
122 |
private int linearInterpolate(int minX, int minX2, double timePos, |
123 |
double timePos2, double time) { |
124 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
125 |
|
126 |
double result = ((minX + (minX2 - minX)) * time);
|
127 |
|
128 |
return (int) Math.ceil(result); |
129 |
} |
130 |
|
131 |
private double dateToSeconds(Date date) { |
132 |
Calendar ca = Calendar.getInstance(Locale.US); |
133 |
ca.setTime(date); |
134 |
return ca.getTimeInMillis();
|
135 |
} |
136 |
|
137 |
/*
|
138 |
* IPersistance methods.
|
139 |
*/
|
140 |
|
141 |
public String getClassName() { |
142 |
// TODO Auto-generated method stub
|
143 |
return null; |
144 |
} |
145 |
|
146 |
public XMLEntity getXMLEntity() {
|
147 |
|
148 |
XMLEntity xml = new XMLEntity();
|
149 |
xml.putProperty("className", this.getClassName()); |
150 |
// xml.putProperty("beginDateInterval", beginDateString);
|
151 |
// xml.putProperty("endDateInterval", endDateString);
|
152 |
|
153 |
beginDateString = DateTime.dateToString(beginDateInterval, sFormat); |
154 |
endDateString = DateTime.dateToString(endDateInterval, sFormat); |
155 |
|
156 |
xml.putProperty("begin_date", beginDateString);
|
157 |
xml.putProperty("end_date", endDateString);
|
158 |
|
159 |
return xml;
|
160 |
} |
161 |
|
162 |
public void setXMLEntity(XMLEntity xml) { |
163 |
if (xml.contains("begin_date")) |
164 |
beginDateString = xml.getStringProperty("begin_date");
|
165 |
if (xml.contains("end_date")) |
166 |
endDateString = xml.getStringProperty("end_date");
|
167 |
|
168 |
} |
169 |
} |