package org.helioviewer.jhv.timelines.draw;

import org.helioviewer.jhv.time.TimeUtils;

public class TimeAxis {

    private long start;
    private long end;

    public TimeAxis(long _min, long _max) {
        start = _min;
        end = _max;
    }

    public long start() {
        return start;
    }

    public long end() {
        return end;
    }

    public int value2pixel(int x0, int w, long val) {
        return (int) ((double) w * (val - start) / (end - start) + x0);
    }

    public long pixel2value(int x0, int w, int x) {
        return (long) (start + (end - start) * (x - x0) / (double) w);
    }

    void move(int w, double pixelDistance) {
        double diff = (double) (end - start) / w;
        move(pixelDistance * diff);
    }

    void move(double diff) {
        start += diff;
        end += diff;
        adaptBounds();
    }

    void zoom(int x0, int w, int x, double factor) {
        double multiplier = (end - start) * factor / w;
        double ratio = (x - x0) / (double) w;
        start -= multiplier * ratio;
        end += multiplier * (1. - ratio);
        adaptBounds();
    }

    void set(long _start, long _end) {
        start = _start;
        end = _end;
        adaptBounds();
    }

    private void adaptBounds() {
        long now = System.currentTimeMillis();
        long intervalLength = Math.min(end - start, now - TimeUtils.MINIMAL_DATE.milli);
        if (intervalLength < TimeUtils.MINUTE_IN_MILLIS) { // or intervalLength <= 0, via wheel zoomin
            end = start + TimeUtils.MINUTE_IN_MILLIS;
            intervalLength = TimeUtils.MINUTE_IN_MILLIS;
        }
        if (end > now) {
            start = now - intervalLength;
            end = now;
        }
        if (start < TimeUtils.MINIMAL_DATE.milli) {
            start = TimeUtils.MINIMAL_DATE.milli;
        }
    }

}

@@ -669,22 +669,20 @@
         
-double
+long
  diff = 
@@ -682,23 +682,38 @@
 diff = (
-double)
+long) (pixelDistance *
  (end - 
@@ -718,24 +718,25 @@
 - start) / w
+)
 ;%0A        mo
@@ -738,32 +738,16 @@
    move(
-pixelDistance * 
 diff);%0A 
@@ -766,22 +766,20 @@
 id move(
-double
+long
  diff) %7B
@@ -933,16 +933,25 @@
 iplier =
+ factor *
  (end - 
@@ -960,17 +960,8 @@
 art)
- * factor
  / w
@@ -1025,16 +1025,24 @@
 tart -= 
+(long) (
 multipli
@@ -1051,16 +1051,17 @@
  * ratio
+)
 ;%0A      
@@ -1069,16 +1069,24 @@
  end += 
+(long) (
 multipli
@@ -1098,24 +1098,25 @@
 (1. - ratio)
+)
 ;%0A        ad
@@ -1843,16 +1843,81 @@
 .milli;%0A
+            end = TimeUtils.MINIMAL_DATE.milli + intervalLength;%0A
         

Revert last; don't use narrowing compound assignments