package org.helioviewer.gl3d.camera;

import java.awt.Point;
import java.awt.event.MouseEvent;

import org.helioviewer.base.math.Vector2dDouble;
import org.helioviewer.base.physics.Constants;
import org.helioviewer.jhv.display.Displayer;
import org.helioviewer.viewmodel.view.RegionView;
import org.helioviewer.viewmodel.view.ViewHelper;
import org.helioviewer.viewmodel.view.opengl.GL3DSceneGraphView;

/**
 * Standard panning interaction, moves the camera proportionally to the mouse
 * movement when dragging
 *
 * @author Simon Spoerri (simon.spoerri@fhnw.ch)
 *
 */
public class GL3DPanInteraction extends GL3DDefaultInteraction {

    private Point lastMousePoint;

    protected GL3DPanInteraction(GL3DSolarRotationTrackingTrackballCamera camera, GL3DSceneGraphView sceneGraph) {
        super(camera, sceneGraph);
    }

    @Override
    public void mousePressed(MouseEvent e, GL3DCamera camera) {
        this.lastMousePoint = e.getPoint();
    }

    @Override
    public void mouseDragged(MouseEvent e, GL3DCamera camera) {
        int x = e.getPoint().x - this.lastMousePoint.x;
        int y = e.getPoint().y - this.lastMousePoint.y;
        if (sceneGraphView.getAdapter(RegionView.class).getRegion() != null) {
            Vector2dDouble imageDisplacement = ViewHelper.convertScreenToImageDisplacement(x, y, sceneGraphView.getAdapter(RegionView.class).getRegion(), ViewHelper.calculateViewportImageSize(sceneGraphView));
            camera.translation.x += imageDisplacement.getX();
            camera.translation.y += imageDisplacement.getY();
        } else {
            camera.translation.x += x / 100.0 * Constants.SunRadius;
            camera.translation.y -= y / 100.0 * Constants.SunRadius;
        }
        this.lastMousePoint = e.getPoint();
        camera.updateCameraTransformation();

        Displayer.display();
    }

    @Override
    public void mouseReleased(MouseEvent e, GL3DCamera camera) {
        Displayer.display();
    }

}

@@ -258,148 +258,461 @@
 wer.
-viewmodel.view.RegionView;%0Aimport org.helioviewer.viewmodel.view.ViewHelper;%0Aimport org.helioviewer.viewmodel.view.opengl.GL3DSceneGraphView
+jhv.layers.LayersModel;%0Aimport org.helioviewer.viewmodel.region.Region;%0Aimport org.helioviewer.viewmodel.view.RegionView;%0Aimport org.helioviewer.viewmodel.view.View;%0Aimport org.helioviewer.viewmodel.view.ViewHelper;%0Aimport org.helioviewer.viewmodel.view.ViewportView;%0Aimport org.helioviewer.viewmodel.view.opengl.GL3DSceneGraphView;%0Aimport org.helioviewer.viewmodel.viewport.Viewport;%0Aimport org.helioviewer.viewmodel.viewportimagesize.ViewportImageSize
 ;%0A%0A/
@@ -1454,24 +1454,25 @@
 oint.y;%0A
+%0A
         
 if (scen
@@ -1467,286 +1467,633 @@
     
-if (sceneGraphView.getAdapter(RegionView.class).getRegion() != null) %7B%0A            Vector2dDouble imageDisplacement = ViewHelper.convertScreenToImageDisplacement(x, y, sceneGraphView.getAdapter(RegionView.class).getRegion(), ViewHelper.calculateViewportImageSize(sceneGraphView)
+View view = LayersModel.getSingletonInstance().getActiveView();%0A%0A        Region region;%0A        RegionView regionView = view.getAdapter(RegionView.class);%0A%0A        Viewport viewport;%0A        ViewportView viewportView = view.getAdapter(ViewportView.class);%0A%0A        if (regionView != null && (region = regionView.getRegion()) != null &&%0A            viewportView != null && (viewport = viewportView.getViewport()) != null) %7B%0A%0A            ViewportImageSize vis = ViewHelper.calculateViewportImageSize(viewport, region);%0A            Vector2dDouble imageDisplacement = ViewHelper.convertScreenToImageDisplacement(x, y, region, vis
 );%0A 

Fix pan