ingo@2327: package de.intevation.flys.jfree;
ingo@2327: 
ingo@2327: import java.util.Date;
ingo@2327: 
ingo@2327: import org.jfree.chart.axis.DateAxis;
ingo@2327: import org.jfree.chart.axis.ValueAxis;
ingo@2327: 
ingo@2327: 
ingo@2327: /**
ingo@2327:  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
ingo@2327:  */
ingo@2327: public class TimeBounds implements Bounds {
ingo@2327: 
ingo@2327:     protected long lower;
ingo@2327:     protected long upper;
ingo@2327: 
ingo@2327: 
ingo@2327:     public TimeBounds(long lower, long upper) {
ingo@2327:         this.lower = lower;
ingo@2327:         this.upper = upper;
ingo@2327:     }
ingo@2327: 
ingo@2327: 
ingo@2327:     @Override
ingo@2327:     public Number getLower() {
ingo@2327:         return Long.valueOf(lower);
ingo@2327:     }
ingo@2327: 
ingo@2327: 
ingo@2397:     public Date getLowerAsDate() {
ingo@2397:         return new Date(lower);
ingo@2397:     }
ingo@2397: 
ingo@2397: 
ingo@2327:     @Override
ingo@2327:     public Number getUpper() {
ingo@2327:         return Long.valueOf(upper);
ingo@2327:     }
ingo@2327: 
ingo@2327: 
ingo@2397:     public Date getUpperAsDate() {
ingo@2397:         return new Date(upper);
ingo@2397:     }
ingo@2397: 
ingo@2397: 
ingo@2327:     @Override
ingo@2327:     public void applyBounds(ValueAxis axis) {
ingo@2327:         DateAxis dateAxis = (DateAxis) axis;
ingo@2327: 
ingo@2327:         dateAxis.setMinimumDate(new Date(lower));
ingo@2327:         dateAxis.setMaximumDate(new Date(upper));
ingo@2327:     }
ingo@2327: 
ingo@2327: 
ingo@2327:     @Override
ingo@2399:     public void applyBounds(ValueAxis axis, int percent) {
ingo@2399:         DateAxis dateAxis = (DateAxis) axis;
ingo@2399: 
ingo@2399:         long space = (upper - lower) / 100 * percent;
ingo@2399: 
ingo@2399:         dateAxis.setMinimumDate(new Date(lower-space));
ingo@2399:         dateAxis.setMaximumDate(new Date(upper+space));
ingo@2399:     }
ingo@2399: 
ingo@2399: 
ingo@2399:     @Override
ingo@2327:     public Bounds combine(Bounds bounds) {
ingo@2327:         if (bounds == null) {
ingo@2327:             return this;
ingo@2327:         }
ingo@2327: 
ingo@2327:         TimeBounds other = (TimeBounds) bounds;
ingo@2327: 
ingo@2327:         long otherLower = other.getLower().longValue();
ingo@2327:         long otherUpper = other.getUpper().longValue();
ingo@2327: 
ingo@2327:         return new TimeBounds(
ingo@2327:             otherLower < lower ? otherLower : lower,
ingo@2327:             otherUpper > upper ? otherUpper : upper);
ingo@2327:     }
ingo@2327: 
ingo@2327: 
ingo@2327:     @Override
ingo@2327:     public String toString() {
ingo@2397:         return "TimeBounds=["+ getLowerAsDate() + " ; " + getUpperAsDate() +"]";
ingo@2327:     }
ingo@2327: }
ingo@2327: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :