package org.helioviewer.jhv.camera;

import javax.swing.Timer;

import org.helioviewer.jhv.display.Displayer;

import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;

public class Interaction implements MouseListener, KeyListener {

    final Camera camera;
    private final Timer wheelTimer;

    Interaction(Camera _camera) {
        camera = _camera;

        wheelTimer = new Timer(1000/2, e -> Displayer.render(1));
        wheelTimer.setRepeats(false);
    }

    @Override
    public void mouseWheelMoved(MouseEvent e) {
        float r = e.getRotation()[1];
        if (r == 0)
            return;

        camera.zoom(-Displayer.CAMERA_ZOOM_MULTIPLIER_WHEEL * r);

        Displayer.render(0.5);
        wheelTimer.restart();
    }

    @Override
    public void mouseDragged(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getClickCount() == 2) {
            camera.reset();
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void keyPressed(KeyEvent e) {
    }

    @Override
    public void keyReleased(KeyEvent e) {
    }

}

@@ -374,16 +374,23 @@
 private 
+static 
 final Ti
@@ -403,16 +403,62 @@
 eelTimer
+ = new Timer(1000/2, e -%3E Displayer.render(1))
 ;%0A%0A    I
@@ -515,75 +515,8 @@
 era;
-%0A%0A        wheelTimer = new Timer(1000/2, e -%3E Displayer.render(1));
 %0A   

Use only one wheel timer