Revision 43610 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.swing/org.gvsig.timesupport.swing.impl/src/main/java/org/gvsig/timesupport/swing/impl/panel/TimePanel.java
TimePanel.java | ||
---|---|---|
18 | 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
19 | 19 |
* MA 02110-1301, USA. |
20 | 20 |
* |
21 |
*/ |
|
21 |
*/
|
|
22 | 22 |
|
23 |
/* |
|
23 |
/*
|
|
24 | 24 |
* AUTHORS (In addition to CIT): |
25 | 25 |
* 2010 {Prodevelop} {Task} |
26 |
*/ |
|
26 |
*/
|
|
27 | 27 |
package org.gvsig.timesupport.swing.impl.panel; |
28 | 28 |
|
29 |
|
|
30 | 29 |
import java.awt.Component; |
31 | 30 |
import java.util.List; |
32 | 31 |
|
33 | 32 |
import javax.swing.BoxLayout; |
34 | 33 |
import javax.swing.JPanel; |
34 |
import org.apache.commons.collections4.CollectionUtils; |
|
35 | 35 |
|
36 | 36 |
import org.gvsig.i18n.Messages; |
37 | 37 |
import org.gvsig.timesupport.AbsoluteInstant; |
... | ... | |
48 | 48 |
import org.gvsig.timesupport.swing.impl.rdv.TimeAdjustmentListener; |
49 | 49 |
import org.gvsig.timesupport.swing.impl.rdv.TimeEvent; |
50 | 50 |
import org.gvsig.timesupport.swing.impl.rdv.TimeSlider; |
51 |
|
|
51 | 52 |
/** |
52 | 53 |
* Window main panel (control Relative and Absolute time instances) |
54 |
* |
|
53 | 55 |
* @author <a href="mailto:Pablo.Viciano@uji.es">Pablo Viciano Negre</a> |
54 | 56 |
* @version $Id$ |
55 | 57 |
* |
56 | 58 |
*/ |
57 | 59 |
public class TimePanel extends JPanel implements TimeAdjustmentListener { |
60 |
|
|
58 | 61 |
private static final long serialVersionUID = -1711925095164453822L; |
62 |
|
|
59 | 63 |
/** |
60 | 64 |
* Time mode {Relative or absolute} |
61 | 65 |
*/ |
62 |
public static enum TIME_MODE {RELATIVE, ABSOLUTE}; |
|
66 |
public static enum TIME_MODE { |
|
67 |
RELATIVE, ABSOLUTE |
|
68 |
}; |
|
63 | 69 |
private TIME_MODE _mode; |
64 | 70 |
private TimeSlider slider = null; |
65 | 71 |
private ITemporalComponent jComponentStart = null; |
... | ... | |
77 | 83 |
private Instant instAux = null; |
78 | 84 |
private boolean updateSlider = false; |
79 | 85 |
private static TimeSupportManager timeSupportManager = TimeSupportLocator |
80 |
.getManager(); |
|
86 |
.getManager();
|
|
81 | 87 |
|
82 | 88 |
private TimeAdjustmentListener listener = null; |
83 | 89 |
|
84 |
public TimePanel() |
|
85 |
{ |
|
90 |
public TimePanel() { |
|
86 | 91 |
super(); |
87 | 92 |
_mode = TIME_MODE.RELATIVE; |
88 | 93 |
} |
89 | 94 |
|
90 | 95 |
/** |
91 | 96 |
* Intializes the panel |
92 |
*
|
|
97 |
* |
|
93 | 98 |
* @param start |
94 | 99 |
* @param end |
95 | 100 |
*/ |
96 |
public void initialize(Instant start, Instant end) |
|
97 |
{ |
|
98 |
|
|
101 |
public void initialize(Instant start, Instant end) { |
|
102 |
|
|
99 | 103 |
createComponents(start, end); |
100 | 104 |
startBackupForInterval = start; |
101 | 105 |
endBackupForInterval = end; |
102 | 106 |
} |
103 |
|
|
107 |
|
|
104 | 108 |
/** |
105 | 109 |
* Set instants to all controls |
110 |
* |
|
106 | 111 |
* @param start |
107 | 112 |
* @param end |
108 | 113 |
*/ |
109 | 114 |
public void setInstants(Instant start, Instant end) { |
110 |
startDate = start;
|
|
111 |
endDate = end;
|
|
115 |
startDate = start; |
|
116 |
endDate = end; |
|
112 | 117 |
|
113 |
getJComponentStart().setTimes(Messages.getText("lbl_begin_position"),
|
|
114 |
startDate, startDate, endDate);
|
|
118 |
getJComponentStart().setTimes(Messages.getText("lbl_begin_position"), |
|
119 |
startDate, startDate, endDate); |
|
115 | 120 |
|
116 |
getJComponentEnd().setTimes(Messages.getText("lbl_end_position"),
|
|
117 |
endDate, startDate, endDate);
|
|
121 |
getJComponentEnd().setTimes(Messages.getText("lbl_end_position"), |
|
122 |
endDate, startDate, endDate); |
|
118 | 123 |
|
119 |
|
|
120 |
getTimeSlider().setValues(startDate, endDate); |
|
124 |
getTimeSlider().setValues(startDate, endDate); |
|
121 | 125 |
} |
122 | 126 |
|
123 | 127 |
/** |
124 | 128 |
* Set the time Mode |
129 |
* |
|
125 | 130 |
* @param mode |
126 | 131 |
* @param start |
127 | 132 |
* @param end |
128 | 133 |
*/ |
129 |
public void setTimeMode(TIME_MODE mode, Instant start, Instant end) |
|
130 |
{ |
|
131 |
_mode = mode; |
|
132 |
initialize(start,end); |
|
134 |
public void setTimeMode(TIME_MODE mode, Instant start, Instant end) { |
|
135 |
_mode = mode; |
|
136 |
initialize(start, end); |
|
133 | 137 |
} |
134 |
|
|
138 |
|
|
135 | 139 |
/** |
136 | 140 |
* Get the current TIME_MODE |
141 |
* |
|
137 | 142 |
* @return |
138 | 143 |
*/ |
139 |
public TIME_MODE getTimeMode() |
|
140 |
{ |
|
141 |
return _mode; |
|
144 |
public TIME_MODE getTimeMode() { |
|
145 |
return _mode; |
|
142 | 146 |
} |
143 |
|
|
147 |
|
|
144 | 148 |
/** |
145 | 149 |
* Set the listener to capture all events {@link TimeAdjustmentListener} |
150 |
* |
|
146 | 151 |
* @param listener |
147 | 152 |
*/ |
148 | 153 |
public void setListener(TimeAdjustmentListener listener) { |
... | ... | |
151 | 156 |
|
152 | 157 |
/** |
153 | 158 |
* Get the listener {@link TimeAdjustmentListener} |
159 |
* |
|
154 | 160 |
* @return |
155 | 161 |
*/ |
156 | 162 |
public TimeAdjustmentListener getListener() { |
... | ... | |
159 | 165 |
|
160 | 166 |
/** |
161 | 167 |
* Set if works with instants (true) or interval (false) |
168 |
* |
|
162 | 169 |
* @param changeable |
163 | 170 |
*/ |
164 | 171 |
public void setValueChangeableSlider(boolean changeable) { |
165 |
if(changeable == true) |
|
166 |
{ //Instant |
|
167 |
if(interval != null) |
|
168 |
{ |
|
172 |
if( changeable == true ) { //Instant |
|
173 |
if( interval != null ) { |
|
169 | 174 |
startBackupForInterval = startDate; |
170 | 175 |
startBackupForInterval = endDate; |
171 | 176 |
setInstants(interval.getStart(), interval.getEnd()); |
172 | 177 |
} |
173 |
}else |
|
174 |
{ //Interval |
|
175 |
if(interval != null) |
|
176 |
{ |
|
178 |
} else { //Interval |
|
179 |
if( interval != null ) { |
|
177 | 180 |
setInstants(startBackupForInterval, endBackupForInterval); |
178 | 181 |
} |
179 | 182 |
} |
... | ... | |
182 | 185 |
|
183 | 186 |
/** |
184 | 187 |
* Set the valid instants |
188 |
* |
|
185 | 189 |
* @param instants |
186 | 190 |
*/ |
187 |
public void setInstants(List<Instant> instants) |
|
188 |
{ |
|
191 |
public void setInstants(List<Instant> instants) { |
|
189 | 192 |
this.instants = instants; |
190 | 193 |
instantsPosition = 0; |
191 | 194 |
actual = null; |
192 | 195 |
} |
193 |
|
|
196 |
|
|
194 | 197 |
public void timeChanged(TimeEvent event) { |
195 | 198 |
// TODO Auto-generated method stub |
196 |
if(!isUpdating()) |
|
197 |
{ |
|
198 |
setUpdating(true); |
|
199 |
if (event.getSource() instanceof TimeSlider) { |
|
200 |
if(getTimeSlider().getValueChangeable()) |
|
201 |
{ |
|
202 |
if(this.instants != null && !updateSlider) |
|
203 |
{ |
|
204 |
updateSlider = true; |
|
205 |
if(!getTimeSlider().isValueAdjusting()) |
|
206 |
{ |
|
207 |
getTimeSlider().setCurrentInstant(getApproximateInstant(getTimeSlider().getCurrentInstant())); |
|
208 |
getJComponentStart().setCurrentInstant(getTimeSlider().getCurrentInstant()); |
|
209 |
} |
|
210 |
updateSlider = false; |
|
211 |
}else |
|
212 |
{ |
|
213 |
getJComponentStart().setCurrentInstant(getTimeSlider().getCurrentInstant()); |
|
214 |
} |
|
215 |
|
|
216 |
} |
|
217 |
|
|
218 |
} else if (event.getSource() instanceof ITemporalComponent) { |
|
219 |
|
|
220 |
ITemporalComponent calendar = (ITemporalComponent) event.getSource(); |
|
221 |
if (calendar == getJComponentStart()) { |
|
222 |
if (!getTimeSlider().getValueChangeable()) { |
|
223 |
|
|
224 |
try {// this try is for the daylight saving (it creates |
|
225 |
// exceptions) |
|
226 |
if(!updateSlider) |
|
227 |
getTimeSlider().setStartInstant((Instant)getJComponentStart().getTime()); |
|
228 |
} catch (IllegalArgumentException e) { |
|
229 |
e.printStackTrace(); |
|
230 |
} |
|
231 |
} |
|
232 |
} else { |
|
233 |
if (!getTimeSlider().getValueChangeable()) { |
|
234 |
|
|
235 |
try {// this try is for the daylight saving (it creates |
|
236 |
// exceptions) |
|
237 |
if(!updateSlider) |
|
238 |
getTimeSlider().setEndInstant((Instant)getJComponentEnd().getTime()); |
|
239 |
} catch (IllegalArgumentException e) { |
|
240 |
e.printStackTrace(); |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
updateCalendars(); |
|
245 |
|
|
246 |
} else { |
|
247 |
try {// this try is for the daylight saving (it creates exceptions) |
|
248 |
if(instants == null) |
|
249 |
getTimeSlider().setCurrentInstant((Instant) |
|
250 |
getJComponentStart().getTime()); |
|
251 |
} catch (IllegalArgumentException e) { |
|
252 |
} finally { |
|
253 |
} |
|
254 |
} |
|
255 |
if (getTimeSlider().getValueChangeable() && listener != null) |
|
256 |
listener.timeChanged(new TimeEvent(this)); |
|
257 |
setUpdating(false); |
|
258 |
} |
|
199 |
if( !isUpdating() ) { |
|
200 |
setUpdating(true); |
|
201 |
if( event.getSource() instanceof TimeSlider ) { |
|
202 |
if( getTimeSlider().getValueChangeable() ) { |
|
203 |
if( CollectionUtils.isNotEmpty(this.instants) && !updateSlider ) { |
|
204 |
updateSlider = true; |
|
205 |
if( !getTimeSlider().isValueAdjusting() ) { |
|
206 |
getTimeSlider().setCurrentInstant(getApproximateInstant(getTimeSlider().getCurrentInstant())); |
|
207 |
getJComponentStart().setCurrentInstant(getTimeSlider().getCurrentInstant()); |
|
208 |
} |
|
209 |
updateSlider = false; |
|
210 |
} else { |
|
211 |
getJComponentStart().setCurrentInstant(getTimeSlider().getCurrentInstant()); |
|
212 |
} |
|
213 |
|
|
214 |
} |
|
215 |
|
|
216 |
} else if( event.getSource() instanceof ITemporalComponent ) { |
|
217 |
|
|
218 |
ITemporalComponent calendar = (ITemporalComponent) event.getSource(); |
|
219 |
if( calendar == getJComponentStart() ) { |
|
220 |
if( !getTimeSlider().getValueChangeable() ) { |
|
221 |
|
|
222 |
try {// this try is for the daylight saving (it creates |
|
223 |
// exceptions) |
|
224 |
if( !updateSlider ) { |
|
225 |
getTimeSlider().setStartInstant((Instant) getJComponentStart().getTime()); |
|
226 |
} |
|
227 |
} catch (IllegalArgumentException e) { |
|
228 |
e.printStackTrace(); |
|
229 |
} |
|
230 |
} |
|
231 |
} else { |
|
232 |
if( !getTimeSlider().getValueChangeable() ) { |
|
233 |
|
|
234 |
try {// this try is for the daylight saving (it creates |
|
235 |
// exceptions) |
|
236 |
if( !updateSlider ) { |
|
237 |
getTimeSlider().setEndInstant((Instant) getJComponentEnd().getTime()); |
|
238 |
} |
|
239 |
} catch (IllegalArgumentException e) { |
|
240 |
e.printStackTrace(); |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
updateCalendars(); |
|
245 |
|
|
246 |
} else { |
|
247 |
try {// this try is for the daylight saving (it creates exceptions) |
|
248 |
if( CollectionUtils.isEmpty(this.instants) ) { |
|
249 |
getTimeSlider().setCurrentInstant((Instant) getJComponentStart().getTime()); |
|
250 |
} |
|
251 |
} catch (IllegalArgumentException e) { |
|
252 |
} finally { |
|
253 |
} |
|
254 |
} |
|
255 |
if( getTimeSlider().getValueChangeable() && listener != null ) { |
|
256 |
listener.timeChanged(new TimeEvent(this)); |
|
257 |
} |
|
258 |
setUpdating(false); |
|
259 |
} |
|
259 | 260 |
} |
260 | 261 |
|
261 | 262 |
public void rangeChanged(TimeEvent event) { |
262 | 263 |
// TODO Auto-generated method stub |
263 |
if (event.getSource() instanceof TimeSlider) {
|
|
264 |
if( event.getSource() instanceof TimeSlider ) {
|
|
264 | 265 |
getJComponentStart().setCurrentInstant(getTimeSlider().getStartInstant()); |
265 | 266 |
getJComponentEnd().setCurrentInstant(getTimeSlider().getEndInstant()); |
266 | 267 |
} |
267 |
if (!getTimeSlider().getValueChangeable() && listener != null)
|
|
268 |
if( !getTimeSlider().getValueChangeable() && listener != null ) {
|
|
268 | 269 |
listener.rangeChanged(new TimeEvent(this)); |
270 |
} |
|
269 | 271 |
} |
270 | 272 |
|
271 | 273 |
/** |
... | ... | |
307 | 309 |
|
308 | 310 |
/** |
309 | 311 |
* Get the current interval |
312 |
* |
|
310 | 313 |
* @return |
311 | 314 |
*/ |
312 | 315 |
public Interval getInterval() { |
313 | 316 |
|
314 |
if (datesCorrect()) { |
|
315 |
if(_mode == TIME_MODE.RELATIVE) |
|
316 |
{ |
|
317 |
return timeSupportManager.createRelativeInterval( |
|
318 |
(RelativeInstant)getJComponentStart().getTime(),(RelativeInstant) getJComponentEnd() |
|
319 |
.getTime()); |
|
320 |
}else |
|
321 |
{ |
|
322 |
try { |
|
323 |
AbsoluteInstant start = (AbsoluteInstant) getJComponentStart().getTime(); |
|
324 |
AbsoluteInstant end = (AbsoluteInstant) getJComponentEnd().getTime(); |
|
325 |
return createAbsoluteInterval(start, end); |
|
326 |
} catch (AbsoluteIntervalTypeNotRegisteredException e) { |
|
327 |
// TODO Auto-generated catch block |
|
328 |
e.printStackTrace(); |
|
329 |
return null; |
|
330 |
} |
|
331 |
} |
|
332 |
} else |
|
317 |
if( datesCorrect() ) { |
|
318 |
if( _mode == TIME_MODE.RELATIVE ) { |
|
319 |
return timeSupportManager.createRelativeInterval( |
|
320 |
(RelativeInstant) getJComponentStart().getTime(), (RelativeInstant) getJComponentEnd() |
|
321 |
.getTime()); |
|
322 |
} else { |
|
323 |
try { |
|
324 |
AbsoluteInstant start = (AbsoluteInstant) getJComponentStart().getTime(); |
|
325 |
AbsoluteInstant end = (AbsoluteInstant) getJComponentEnd().getTime(); |
|
326 |
return createAbsoluteInterval(start, end); |
|
327 |
} catch (AbsoluteIntervalTypeNotRegisteredException e) { |
|
328 |
// TODO Auto-generated catch block |
|
329 |
e.printStackTrace(); |
|
330 |
return null; |
|
331 |
} |
|
332 |
} |
|
333 |
} else { |
|
333 | 334 |
return null; |
335 |
} |
|
334 | 336 |
|
335 | 337 |
} |
336 | 338 |
|
337 | 339 |
/** |
338 | 340 |
* Get the current instant |
341 |
* |
|
339 | 342 |
* @return |
340 | 343 |
*/ |
341 | 344 |
public Instant getInstant() { |
342 | 345 |
|
343 |
if (datesCorrect()) {
|
|
346 |
if( datesCorrect() ) {
|
|
344 | 347 |
try {// this try is for the daylight saving (it creates exceptions) |
345 | 348 |
return (Instant) getJComponentStart().getTime(); |
346 | 349 |
} catch (IllegalArgumentException e) { |
347 | 350 |
return null; |
348 | 351 |
} |
349 |
} else |
|
352 |
} else {
|
|
350 | 353 |
return null; |
354 |
} |
|
351 | 355 |
|
352 | 356 |
} |
353 | 357 |
|
354 |
public void setInterval(Interval interval) |
|
355 |
{ |
|
358 |
public void setInterval(Interval interval) { |
|
356 | 359 |
this.interval = interval; |
357 | 360 |
} |
358 |
|
|
361 |
|
|
359 | 362 |
/* |
360 | 363 |
* PRIVATE METHODS |
361 | 364 |
*/ |
362 | 365 |
private void createUI() { |
363 | 366 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
364 |
|
|
365 |
add((Component)getJComponentStart()); |
|
367 |
|
|
368 |
add((Component) getJComponentStart());
|
|
366 | 369 |
add(getTimeSlider()); |
367 |
add((Component)getJComponentEnd()); |
|
368 |
|
|
370 |
add((Component) getJComponentEnd());
|
|
371 |
|
|
369 | 372 |
getTimeSlider().setValueChangeable(false); |
370 | 373 |
|
371 | 374 |
getJComponentStart().setListener(this); |
372 | 375 |
getJComponentEnd().setListener(this); |
373 | 376 |
getTimeSlider().addTimeAdjustmentListener(this); |
374 | 377 |
} |
375 |
|
|
376 |
private void createComponents(Instant start, Instant end) |
|
377 |
{ |
|
378 |
removeAll(); |
|
379 |
revalidate(); |
|
380 |
repaint(); |
|
381 |
jComponentStart = null; |
|
382 |
jComponentEnd = null; |
|
383 |
slider = null; |
|
384 |
setInstants(start, end); |
|
385 |
createUI(); |
|
386 |
|
|
378 |
|
|
379 |
private void createComponents(Instant start, Instant end) { |
|
380 |
removeAll(); |
|
381 |
revalidate(); |
|
382 |
repaint(); |
|
383 |
jComponentStart = null; |
|
384 |
jComponentEnd = null; |
|
385 |
slider = null; |
|
386 |
setInstants(start, end); |
|
387 |
createUI(); |
|
388 |
|
|
387 | 389 |
} |
388 | 390 |
|
389 | 391 |
@SuppressWarnings("unused") |
390 | 392 |
private boolean datesCorrect() { |
391 |
if (getJComponentStart().isEnabled() && getJComponentEnd().isEnabled()) {
|
|
393 |
if( getJComponentStart().isEnabled() && getJComponentEnd().isEnabled() ) {
|
|
392 | 394 |
try { |
393 | 395 |
Instant init = (Instant) getJComponentStart().getTime(); |
394 | 396 |
Instant end = (Instant) getJComponentEnd().getTime(); |
... | ... | |
401 | 403 |
} |
402 | 404 |
|
403 | 405 |
private TimeSlider getTimeSlider() { |
404 |
if (slider == null) |
|
405 |
if(_mode == TIME_MODE.RELATIVE) |
|
406 |
slider = new TimeSlider(false); |
|
407 |
else |
|
408 |
slider = new TimeSlider(true); |
|
406 |
if( slider == null ) { |
|
407 |
if( _mode == TIME_MODE.RELATIVE ) { |
|
408 |
slider = new TimeSlider(false); |
|
409 |
} else { |
|
410 |
slider = new TimeSlider(true); |
|
411 |
} |
|
412 |
} |
|
409 | 413 |
return slider; |
410 | 414 |
} |
411 | 415 |
|
412 | 416 |
private ITemporalComponent getJComponentStart() { |
413 |
if (jComponentStart == null) |
|
414 |
if(_mode == TIME_MODE.RELATIVE) |
|
415 |
jComponentStart = new RelativeTemporalComponent(); |
|
416 |
else |
|
417 |
jComponentStart = new AbsoluteTemporalComponent(); |
|
418 |
|
|
417 |
if( jComponentStart == null ) { |
|
418 |
if( _mode == TIME_MODE.RELATIVE ) { |
|
419 |
jComponentStart = new RelativeTemporalComponent(); |
|
420 |
} else { |
|
421 |
jComponentStart = new AbsoluteTemporalComponent(); |
|
422 |
} |
|
423 |
} |
|
424 |
|
|
419 | 425 |
return jComponentStart; |
420 | 426 |
} |
421 | 427 |
|
422 | 428 |
private ITemporalComponent getJComponentEnd() { |
423 |
if (jComponentEnd == null) |
|
424 |
if(_mode == TIME_MODE.RELATIVE) |
|
425 |
jComponentEnd = new RelativeTemporalComponent(); |
|
426 |
else |
|
427 |
jComponentEnd = new AbsoluteTemporalComponent(); |
|
429 |
if( jComponentEnd == null ) { |
|
430 |
if( _mode == TIME_MODE.RELATIVE ) { |
|
431 |
jComponentEnd = new RelativeTemporalComponent(); |
|
432 |
} else { |
|
433 |
jComponentEnd = new AbsoluteTemporalComponent(); |
|
434 |
} |
|
435 |
} |
|
428 | 436 |
return jComponentEnd; |
429 | 437 |
} |
430 | 438 |
|
431 | 439 |
private void updateCalendars() { |
432 | 440 |
try { |
433 |
Instant start = (Instant)getJComponentStart().getTime(); |
|
434 |
Instant end = (Instant)getJComponentEnd().getTime(); |
|
441 |
Instant start = (Instant) getJComponentStart().getTime();
|
|
442 |
Instant end = (Instant) getJComponentEnd().getTime();
|
|
435 | 443 |
getJComponentStart().setEndTime(end); |
436 | 444 |
getJComponentEnd().setStartTime(start); |
437 | 445 |
} catch (IllegalArgumentException e) { |
438 | 446 |
} |
439 | 447 |
} |
440 |
|
|
441 |
private boolean isUpdating() |
|
442 |
{ |
|
443 |
return eventSynchronized; |
|
448 |
|
|
449 |
private boolean isUpdating() { |
|
450 |
return eventSynchronized; |
|
444 | 451 |
} |
445 |
|
|
446 |
private void setUpdating(boolean value) |
|
447 |
{ |
|
448 |
eventSynchronized = value; |
|
452 |
|
|
453 |
private void setUpdating(boolean value) { |
|
454 |
eventSynchronized = value; |
|
449 | 455 |
} |
450 |
|
|
451 |
private AbsoluteInterval createAbsoluteInterval(AbsoluteInstant start, AbsoluteInstant end) throws AbsoluteIntervalTypeNotRegisteredException |
|
452 |
{ |
|
453 |
long millisStart = start.toStandardDuration().getMillis(); |
|
454 |
long millisEnd = end.toStandardDuration().getMillis(); |
|
455 |
|
|
456 |
long millisInterval = millisEnd - millisStart; |
|
457 |
|
|
458 |
int years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0, millis = 0; |
|
459 |
|
|
460 |
long mod = millisInterval % TimeSlider.MILLIS_BY_YEAR; |
|
461 |
if((millisInterval / TimeSlider.MILLIS_BY_YEAR) > 0) |
|
462 |
{ |
|
463 |
years = (int) (millisInterval / TimeSlider.MILLIS_BY_YEAR); |
|
464 |
millisInterval = mod; |
|
465 |
} |
|
466 |
|
|
467 |
mod = millisInterval % TimeSlider.MILLIS_BY_MONTH; |
|
468 |
if((millisInterval / TimeSlider.MILLIS_BY_MONTH) > 0) |
|
469 |
{ |
|
470 |
months = (int) (millisInterval / TimeSlider.MILLIS_BY_MONTH); |
|
471 |
millisInterval = mod; |
|
472 |
} |
|
473 |
|
|
474 |
mod = millisInterval % TimeSlider.MILLIS_BY_WEEK; |
|
475 |
if((millisInterval / TimeSlider.MILLIS_BY_WEEK) > 0) |
|
476 |
{ |
|
477 |
weeks = (int) (millisInterval / TimeSlider.MILLIS_BY_WEEK); |
|
478 |
millisInterval = mod; |
|
479 |
} |
|
480 |
|
|
481 |
mod = millisInterval % TimeSlider.MILLIS_BY_DAY; |
|
482 |
if ((millisInterval / TimeSlider.MILLIS_BY_DAY) > 0){ |
|
483 |
if((int)(millisInterval / TimeSlider.MILLIS_BY_DAY) > 0) |
|
484 |
{ |
|
485 |
days = (int)(millisInterval / TimeSlider.MILLIS_BY_DAY); |
|
486 |
} |
|
487 |
millisInterval = mod; |
|
488 |
} |
|
489 |
|
|
490 |
mod = millisInterval % TimeSlider.MILLIS_BY_HOUR; |
|
491 |
if ((millisInterval / TimeSlider.MILLIS_BY_HOUR) > 0){ |
|
492 |
hours = (int)(millisInterval / TimeSlider.MILLIS_BY_HOUR); |
|
493 |
millisInterval = mod; |
|
494 |
} |
|
495 |
|
|
496 |
mod = millisInterval % TimeSlider.MILLIS_BY_MINUTE; |
|
497 |
if ((millisInterval / TimeSlider.MILLIS_BY_MINUTE) > 0){ |
|
498 |
seconds =(int)(millisInterval / TimeSlider.MILLIS_BY_MINUTE); |
|
499 |
millisInterval = mod; |
|
500 |
} |
|
501 |
|
|
502 |
mod = millisInterval % TimeSlider.MILLIS_BY_SECOND; |
|
503 |
if ((millisInterval / TimeSlider.MILLIS_BY_SECOND) > 0){ |
|
504 |
seconds = (int)(millisInterval / TimeSlider.MILLIS_BY_SECOND); |
|
505 |
millisInterval = mod; |
|
506 |
} |
|
507 |
|
|
508 |
mod = millisInterval; |
|
509 |
if (mod > 0){ |
|
510 |
millis = (int) mod; |
|
511 |
} |
|
512 |
|
|
513 |
return timeSupportManager.createAbsoluteInterval(years, months, weeks, days, hours, minutes, seconds, millis); |
|
514 |
|
|
515 |
|
|
456 |
|
|
457 |
private AbsoluteInterval createAbsoluteInterval(AbsoluteInstant start, AbsoluteInstant end) throws AbsoluteIntervalTypeNotRegisteredException { |
|
458 |
long millisStart = start.toStandardDuration().getMillis(); |
|
459 |
long millisEnd = end.toStandardDuration().getMillis(); |
|
460 |
|
|
461 |
long millisInterval = millisEnd - millisStart; |
|
462 |
|
|
463 |
int years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0, millis = 0; |
|
464 |
|
|
465 |
long mod = millisInterval % TimeSlider.MILLIS_BY_YEAR; |
|
466 |
if( (millisInterval / TimeSlider.MILLIS_BY_YEAR) > 0 ) { |
|
467 |
years = (int) (millisInterval / TimeSlider.MILLIS_BY_YEAR); |
|
468 |
millisInterval = mod; |
|
469 |
} |
|
470 |
|
|
471 |
mod = millisInterval % TimeSlider.MILLIS_BY_MONTH; |
|
472 |
if( (millisInterval / TimeSlider.MILLIS_BY_MONTH) > 0 ) { |
|
473 |
months = (int) (millisInterval / TimeSlider.MILLIS_BY_MONTH); |
|
474 |
millisInterval = mod; |
|
475 |
} |
|
476 |
|
|
477 |
mod = millisInterval % TimeSlider.MILLIS_BY_WEEK; |
|
478 |
if( (millisInterval / TimeSlider.MILLIS_BY_WEEK) > 0 ) { |
|
479 |
weeks = (int) (millisInterval / TimeSlider.MILLIS_BY_WEEK); |
|
480 |
millisInterval = mod; |
|
481 |
} |
|
482 |
|
|
483 |
mod = millisInterval % TimeSlider.MILLIS_BY_DAY; |
|
484 |
if( (millisInterval / TimeSlider.MILLIS_BY_DAY) > 0 ) { |
|
485 |
if( (int) (millisInterval / TimeSlider.MILLIS_BY_DAY) > 0 ) { |
|
486 |
days = (int) (millisInterval / TimeSlider.MILLIS_BY_DAY); |
|
487 |
} |
|
488 |
millisInterval = mod; |
|
489 |
} |
|
490 |
|
|
491 |
mod = millisInterval % TimeSlider.MILLIS_BY_HOUR; |
|
492 |
if( (millisInterval / TimeSlider.MILLIS_BY_HOUR) > 0 ) { |
|
493 |
hours = (int) (millisInterval / TimeSlider.MILLIS_BY_HOUR); |
|
494 |
millisInterval = mod; |
|
495 |
} |
|
496 |
|
|
497 |
mod = millisInterval % TimeSlider.MILLIS_BY_MINUTE; |
|
498 |
if( (millisInterval / TimeSlider.MILLIS_BY_MINUTE) > 0 ) { |
|
499 |
seconds = (int) (millisInterval / TimeSlider.MILLIS_BY_MINUTE); |
|
500 |
millisInterval = mod; |
|
501 |
} |
|
502 |
|
|
503 |
mod = millisInterval % TimeSlider.MILLIS_BY_SECOND; |
|
504 |
if( (millisInterval / TimeSlider.MILLIS_BY_SECOND) > 0 ) { |
|
505 |
seconds = (int) (millisInterval / TimeSlider.MILLIS_BY_SECOND); |
|
506 |
millisInterval = mod; |
|
507 |
} |
|
508 |
|
|
509 |
mod = millisInterval; |
|
510 |
if( mod > 0 ) { |
|
511 |
millis = (int) mod; |
|
512 |
} |
|
513 |
|
|
514 |
return timeSupportManager.createAbsoluteInterval(years, months, weeks, days, hours, minutes, seconds, millis); |
|
515 |
|
|
516 | 516 |
} |
517 |
|
|
518 |
private Instant getApproximateInstant(Instant instant) |
|
519 |
{ |
|
520 |
|
|
517 |
|
|
518 |
private Instant getApproximateInstant(Instant instant) { |
|
519 |
|
|
521 | 520 |
int index = 0; |
522 |
|
|
523 |
if(instant.isBefore(instants.get(0)))
|
|
521 |
|
|
522 |
if( instant.isBefore(instants.get(0)) ) {
|
|
524 | 523 |
return instants.get(0); |
525 |
|
|
526 |
for(Instant ins : instants) |
|
527 |
{ |
|
528 |
if(ins.isEqual(instant))
|
|
524 |
} |
|
525 |
|
|
526 |
for( Instant ins : instants ) {
|
|
527 |
if( ins.isEqual(instant) ) {
|
|
529 | 528 |
return ins; |
530 |
else if(ins.isAfter(instant)) |
|
531 |
{ |
|
529 |
} else if( ins.isAfter(instant) ) { |
|
532 | 530 |
break; |
533 | 531 |
} |
534 | 532 |
index++; |
535 | 533 |
} |
536 |
if(index == instants.size()) |
|
537 |
return instants.get(instants.size()-1); |
|
538 |
|
|
534 |
if( index == instants.size() ) { |
|
535 |
return instants.get(instants.size() - 1); |
|
536 |
} |
|
537 |
|
|
539 | 538 |
return instants.get(index); |
540 | 539 |
} |
541 | 540 |
} |
Also available in: Unified diff