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

public final class MainPanel extends JPanel {
    private MainPanel() {
        super(new BorderLayout());
        JTree tree = new JTree(makeModel()) {
            @Override public void updateUI() {
                setCellRenderer(null);
                super.updateUI();
                setCellRenderer(new ChapterNumberingTreeCellRenderer());
                setRootVisible(false);
            }
        };
        add(new JScrollPane(tree));
        setPreferredSize(new Dimension(320, 240));
    }
    private static TreeModel makeModel() {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
        root.add(new DefaultMutableTreeNode("Introductiion"));
        root.add(makePart());
        root.add(makePart());
        return new DefaultTreeModel(root);
    }
    private static DefaultMutableTreeNode makePart() {
        DefaultMutableTreeNode c1 = new DefaultMutableTreeNode("Chapter");
        c1.add(new DefaultMutableTreeNode("Section"));
        c1.add(new DefaultMutableTreeNode("Section"));
        c1.add(new DefaultMutableTreeNode("Section"));

        DefaultMutableTreeNode c2 = new DefaultMutableTreeNode("Chapter");
        c2.add(new DefaultMutableTreeNode("aaaaaaaa"));
        c2.add(new DefaultMutableTreeNode("bbbb"));
        c2.add(new DefaultMutableTreeNode("cc"));

        DefaultMutableTreeNode p1 = new DefaultMutableTreeNode("Part");
        p1.add(c1);
        p1.add(c2);
        return p1;
    }
    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 ChapterNumberingTreeCellRenderer extends DefaultTreeCellRenderer {
    private static final String MARK = "\u00a7"; //"§";
    @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        JLabel l = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        if (value instanceof DefaultMutableTreeNode) {
            TreeNode[] tn = ((DefaultMutableTreeNode) value).getPath();
            String s = IntStream.range(1, tn.length).mapToObj(i -> {
                TreeNode n = tn[i];
                TreeNode p = n.getParent();
                return String.valueOf(1 + p.getIndex(n));
            }).collect(Collectors.joining("."));
            l.setText(String.format("%s%s %s", MARK, s, value));
//             String[] arr = new String[tn.length - 1];
//             for (int i = 1; i < tn.length; i++) {
//                 TreeNode n = tn[i];
//                 TreeNode p = n.getParent();
//                 arr[i - 1] = String.valueOf(1 + p.getIndex(n));
//             }
//             l.setText(String.format("%s%s %s", MARK, String.join(".", arr), value));
        }
        return l;
    }
}

@@ -3068,104 +3068,52 @@
 gth)
-.mapToObj(i -%3E %7B%0A                TreeNode n = tn%5Bi%5D;%0A                TreeNode p = n.getParent();
+ // ignore the root node by skipping index 0
 %0A   
@@ -3123,24 +3123,30 @@
         
-  return
+.mapToObj(i -%3E
  String.
@@ -3149,33 +3149,41 @@
 ing.valueOf(1 + 
-p
+tn%5Bi - 1%5D
 .getIndex(n));%0A 
@@ -3176,20 +3176,24 @@
 etIndex(
-n));
+tn%5Bi%5D)))
 %0A       
@@ -3197,18 +3197,18 @@
         
-%7D)
+  
 .collect
@@ -3303,376 +3303,8 @@
 ));%0A
-//             String%5B%5D arr = new String%5Btn.length - 1%5D;%0A//             for (int i = 1; i %3C tn.length; i++) %7B%0A//                 TreeNode n = tn%5Bi%5D;%0A//                 TreeNode p = n.getParent();%0A//                 arr%5Bi - 1%5D = String.valueOf(1 + p.getIndex(n));%0A//             %7D%0A//             l.setText(String.format(%22%25s%25s %25s%22, MARK, String.join(%22.%22, arr), value));%0A
     

make it one line, add comment