package example;
//-*- mode:java; encoding:utf8n; coding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class MainPanel extends JPanel {
    private final JLabel label       = new JLabel();
    private final JScrollPane scroll = new JScrollPane(); //new JScrollPane(label);
    private final JRadioButton r1    = new JRadioButton("scrollRectToVisible");
    private final JRadioButton r2    = new JRadioButton("setViewPosition");
    private static boolean HEAVYWEIGHT_LIGHTWEIGHT_MIXING = false;
    public MainPanel() {
        super(new BorderLayout());
        Box box = Box.createHorizontalBox();
        ButtonGroup bg = new ButtonGroup();
        box.add(r1); bg.add(r1);
        box.add(r2); bg.add(r2);
        r1.setSelected(true);

        label.setIcon(new ImageIcon(getClass().getResource("CRW_3857_JFR.jpg")));
        HandScrollListener hsl = new HandScrollListener();
        //JViewport vport = scroll.getViewport();
        //JDK 1.7.0
        JViewport vport = new JViewport() {
            private boolean flag = false;
            @Override public void revalidate() {
                if(!HEAVYWEIGHT_LIGHTWEIGHT_MIXING && flag) return;
                super.revalidate();
            }
            @Override public void setViewPosition(Point p) {
                if(HEAVYWEIGHT_LIGHTWEIGHT_MIXING) {
                    super.setViewPosition(p);
                }else{
                    flag = true;
                    super.setViewPosition(p);
                    flag = false;
                }
            }
        };
        vport.add(label);
        scroll.setViewport(vport);

        vport.addMouseMotionListener(hsl);
        vport.addMouseListener(hsl);
        add(scroll);
        add(box, BorderLayout.NORTH);
        scroll.setPreferredSize(new Dimension(320, 240));
    }
    class HandScrollListener extends MouseAdapter {
        private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
        private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
        private final Point pp = new Point();
        @Override public void mouseDragged(MouseEvent e) {
            JViewport vport = (JViewport)e.getSource();
            Point cp = e.getPoint();
            Point vp = vport.getViewPosition(); //= SwingUtilities.convertPoint(vport,0,0,label);
            vp.translate(pp.x-cp.x, pp.y-cp.y);
            if(r1.isSelected()) {
                label.scrollRectToVisible(new Rectangle(vp, vport.getSize()));
            }else{
                vport.setViewPosition(vp);
            }
            pp.setLocation(cp);
        }
        @Override public void mousePressed(MouseEvent e) {
            ((JComponent)e.getSource()).setCursor(hndCursor);
            pp.setLocation(e.getPoint());
        }
        @Override public void mouseReleased(MouseEvent e) {
            ((JComponent)e.getSource()).setCursor(defCursor);
        }
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try{
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }catch(Exception e) {
            e.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

@@ -896,67 +896,8 @@
 ));%0A
-        HandScrollListener hsl = new HandScrollListener();%0A
     
@@ -938,24 +938,24 @@
 Viewport();%0A
+
         //JD
@@ -1612,24 +1612,82 @@
 rt(vport);%0A%0A
+//*%0A        MouseAdapter hsl1 = new HandScrollListener();%0A
         vpor
@@ -1706,32 +1706,33 @@
 tionListener(hsl
+1
 );%0A        vport
@@ -1752,19 +1752,165 @@
 ener(hsl
+1
 );%0A
+/*/%0A        MouseAdapter hsl2 = new DragScrollListener();%0A        label.addMouseMotionListener(hsl2);%0A        label.addMouseListener(hsl2);%0A//*/%0A
         
@@ -3789,24 +3789,24 @@
 veTo(null);%0A
-
         fram
@@ -3833,8 +3833,1300 @@
     %7D%0A%7D%0A
+class DragScrollListener extends MouseAdapter %7B%0A    private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);%0A    private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);%0A    private final Point pp = new Point();%0A    @Override public void mouseDragged(MouseEvent e) %7B%0A        final JComponent jc = (JComponent)e.getSource();%0A        Container c = jc.getParent();%0A        if(c instanceof JViewport) %7B%0A            JViewport vport = (JViewport)c;%0A            Point cp = SwingUtilities.convertPoint(jc,e.getPoint(),vport);%0A            Point vp = vport.getViewPosition();%0A            vp.translate(pp.x-cp.x, pp.y-cp.y);%0A            jc.scrollRectToVisible(new Rectangle(vp, vport.getSize()));%0A            pp.setLocation(cp);%0A        %7D%0A    %7D%0A    @Override public void mousePressed(MouseEvent e) %7B%0A        JComponent jc = (JComponent)e.getSource();%0A        Container c = jc.getParent();%0A        if(c instanceof JViewport) %7B%0A            jc.setCursor(hndCursor);%0A            JViewport vport = (JViewport)c;%0A            Point cp = SwingUtilities.convertPoint(jc,e.getPoint(),vport);%0A            pp.setLocation(cp);%0A        %7D%0A    %7D%0A    @Override public void mouseReleased(MouseEvent e) %7B%0A        ((JComponent)e.getSource()).setCursor(defCursor);%0A    %7D%0A%7D%0A

add DragScrollListener