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

public final class MainPanel extends JPanel {
    private MainPanel() {
        super(new GridLayout(2, 1));

        JTree tree1 = new JTree();
        JTree tree2 = new JTree();
        expandTree(tree1);
        expandTree(tree2);

        MouseAdapter ma = new DragScrollListener();
        tree2.addMouseMotionListener(ma);
        tree2.addMouseListener(ma);

        add(makeTitledComponent(tree1, "Default"));
        add(makeTitledComponent(tree2, "Drag scroll"));
        setPreferredSize(new Dimension(320, 240));
    }
    private static void expandTree(JTree tree) {
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
        Enumeration<?> e = root.breadthFirstEnumeration();
        while (e.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
            if (node.isLeaf()) {
                continue;
            }
            int row = tree.getRowForPath(new TreePath(node.getPath()));
            tree.expandRow(row);
        }
    }
    private static JComponent makeTitledComponent(JComponent c, String title) {
        JScrollPane scroll = new JScrollPane(c);
        scroll.setBorder(BorderFactory.createTitledBorder(title));
        return scroll;
    }
    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 (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.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);
    }
}

class DragScrollListener 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) {
        Component c = e.getComponent();
        Container p = SwingUtilities.getUnwrappedParent(c);
        if (p instanceof JViewport) {
            JViewport vport = (JViewport) p;
            Point cp = SwingUtilities.convertPoint(c, e.getPoint(), vport);
            Point vp = vport.getViewPosition();
            vp.translate(pp.x - cp.x, pp.y - cp.y);
            ((JComponent) c).scrollRectToVisible(new Rectangle(vp, vport.getSize()));
            pp.setLocation(cp);
        }
    }
    @Override public void mousePressed(MouseEvent e) {
        Component c = e.getComponent();
        c.setCursor(hndCursor);
        Container p = SwingUtilities.getUnwrappedParent(c);
        if (p instanceof JViewport) {
            JViewport vport = (JViewport) p;
            Point cp = SwingUtilities.convertPoint(c, e.getPoint(), vport);
            pp.setLocation(cp);
        }
    }
    @Override public void mouseReleased(MouseEvent e) {
        e.getComponent().setCursor(defCursor);
    }
}

@@ -882,16 +882,34 @@
         
+Collections.list((
 Enumerat
@@ -918,30 +918,23 @@
 n%3C?%3E
- e =
+)
  root.
-breadthFirst
+preorder
 Enum
@@ -946,263 +946,146 @@
 on()
-;%0A        while (e.hasMoreElements()) %7B%0A            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();%0A            if (node.isLeaf()) %7B%0A                continue;%0A            %7D%0A            int row = tree.getRowForPath(new TreePath(
+).stream()%0A          .filter(DefaultMutableTreeNode.class::isInstance)%0A          .map(node -%3E new TreePath(((DefaultMutableTreeNode) 
 node
+)
 .get
@@ -1088,25 +1088,24 @@
 .getPath()))
-;
 %0A           
@@ -1107,40 +1107,67 @@
     
-  tree.expandRow(row);%0A        %7D
+.forEach(path -%3E tree.expandRow(tree.getRowForPath(path)));
 %0A   
@@ -2632,37 +2632,65 @@
     
-if (p instanceof JViewport) %7B
+Optional.ofNullable(SwingUtilities.getUnwrappedParent(c))
 %0A   
@@ -2688,34 +2688,40 @@
 t(c))%0A          
-  
+.filter(
 JViewport vport 
@@ -2713,39 +2713,90 @@
 Viewport
- vport = (JViewport) p;
+.class::isInstance).map(JViewport.class::cast)%0A          .ifPresent(v -%3E %7B
 %0A       
@@ -2849,36 +2849,32 @@
  e.getPoint(), v
-port
 );%0A            P
@@ -2884,20 +2884,16 @@
 t vp = v
-port
 .getView
@@ -3024,20 +3024,16 @@
 le(vp, v
-port
 .getSize
@@ -3070,33 +3070,37 @@
 on(cp);%0A        
-%7D
+  %7D);
 %0A    %7D%0A    @Over
@@ -3221,38 +3221,44 @@
 r);%0A        
-Container p = 
+Optional.ofNullable(
 SwingUtiliti
@@ -3273,33 +3273,33 @@
 wrappedParent(c)
-;
+)
 %0A        if (p i
@@ -3295,200 +3295,165 @@
     
-if (p instanceof JViewport) %7B%0A            JViewport vport = (JViewport) p;%0A            Point cp = SwingUtilities.convertPoint(c, e.getPoint(), vport);%0A            pp.setLocation(cp);%0A        %7D
+  .filter(JViewport.class::isInstance).map(JViewport.class::cast)%0A          .ifPresent(v -%3E pp.setLocation(SwingUtilities.convertPoint(c, e.getPoint(), v)));
 %0A   

use Optional.ifPresent(...) instead of if (...)