1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sourceforge.jarduino.gui;
18
19 import java.awt.BorderLayout;
20 import java.awt.Dimension;
21 import javax.swing.JComponent;
22 import javax.swing.JEditorPane;
23 import javax.swing.JPanel;
24 import javax.swing.JScrollPane;
25 import javax.swing.JSplitPane;
26 import javax.swing.JTree;
27 import javax.swing.tree.DefaultMutableTreeNode;
28 import javax.swing.tree.DefaultTreeModel;
29 import javax.swing.tree.TreePath;
30 import javax.swing.tree.TreeSelectionModel;
31
32 import net.sourceforge.jarduino.ArduinoException;
33
34
35
36
37 public class ArduinoPanelHelp {
38
39
40
41 static final int WIDTH = 600;
42
43
44
45
46 private final JSplitPane thePane;
47
48
49
50
51 private final JEditorPane theHelp;
52
53
54
55
56
57 ArduinoPanelHelp() throws ArduinoException {
58
59 theHelp = new JEditorPane();
60 theHelp.setEditable(false);
61 theHelp.setContentType("text/html");
62
63
64 final DefaultMutableTreeNode myRoot = new DefaultMutableTreeNode("Root");
65 for (ArduinoHelp myId : ArduinoHelp.values()) {
66 myRoot.add(new DefaultMutableTreeNode(myId));
67 }
68 final DefaultTreeModel myModel = new DefaultTreeModel(myRoot);
69
70
71 final JTree myTree = new JTree(myModel);
72 myTree.setEditable(false);
73 myTree.setRootVisible(false);
74 myTree.setExpandsSelectedPaths(true);
75
76
77 final TreeSelectionModel mySelect = myTree.getSelectionModel();
78 mySelect.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
79 mySelect.addTreeSelectionListener(e -> {
80 final DefaultMutableTreeNode myNode = (DefaultMutableTreeNode) e.getNewLeadSelectionPath().getLastPathComponent();
81 final ArduinoHelp../../../net/sourceforge/jarduino/gui/ArduinoHelp.html#ArduinoHelp">ArduinoHelp myId = (ArduinoHelp) myNode.getUserObject();
82 theHelp.setText(myId.getHTML());
83 theHelp.setCaretPosition(0);
84 });
85
86
87 final JScrollPane myScroll = new JScrollPane(theHelp);
88 myScroll.setPreferredSize(new Dimension(WIDTH, ArduinoPanelMain.HEIGHT));
89
90
91 final JPanel myPanel = new JPanel(new BorderLayout());
92 myPanel.add(myScroll, BorderLayout.CENTER);
93
94
95 ArduinoHelp.loadAllHelp();
96
97
98 final TreePath myPath = new TreePath(((DefaultMutableTreeNode) myRoot.getFirstChild()).getPath());
99 mySelect.setSelectionPath(myPath);
100
101
102 thePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
103 thePane.setLeftComponent(new JScrollPane(myTree));
104 thePane.setRightComponent(myPanel);
105 thePane.setResizeWeight(ArduinoTableNodeConnect.THIRD_WEIGHT);
106 }
107
108
109
110
111
112 JComponent getComponent() {
113 return thePane;
114 }
115 }