|
@@ -23,28 +23,30 @@
|
23
|
23
|
package com.dmdirc.addons.ui_swing.dialogs.about;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
26
|
|
-import com.dmdirc.addons.ui_swing.components.GenericListModel;
|
27
|
|
-import com.dmdirc.addons.ui_swing.components.ListScroller;
|
|
26
|
+import com.dmdirc.addons.ui_swing.components.TreeScroller;
|
|
27
|
+import com.dmdirc.plugins.PluginInfo;
|
28
|
28
|
|
29
|
29
|
import java.awt.Font;
|
|
30
|
+import java.awt.Rectangle;
|
30
|
31
|
|
31
|
32
|
import javax.swing.JEditorPane;
|
32
|
|
-import javax.swing.JList;
|
33
|
33
|
import javax.swing.JPanel;
|
34
|
34
|
import javax.swing.JScrollPane;
|
35
|
|
-import javax.swing.ListSelectionModel;
|
|
35
|
+import javax.swing.JTree;
|
36
|
36
|
import javax.swing.UIManager;
|
37
|
|
-import javax.swing.event.ListSelectionEvent;
|
38
|
|
-import javax.swing.event.ListSelectionListener;
|
|
37
|
+import javax.swing.event.TreeSelectionEvent;
|
|
38
|
+import javax.swing.event.TreeSelectionListener;
|
39
|
39
|
import javax.swing.text.html.HTMLDocument;
|
40
|
40
|
import javax.swing.text.html.HTMLEditorKit;
|
|
41
|
+import javax.swing.tree.DefaultMutableTreeNode;
|
|
42
|
+import javax.swing.tree.DefaultTreeModel;
|
41
|
43
|
|
42
|
44
|
import net.miginfocom.swing.MigLayout;
|
43
|
45
|
|
44
|
46
|
/**
|
45
|
47
|
* Licences panel.
|
46
|
48
|
*/
|
47
|
|
-public final class LicencesPanel extends JPanel implements ListSelectionListener {
|
|
49
|
+public final class LicencesPanel extends JPanel implements TreeSelectionListener {
|
48
|
50
|
|
49
|
51
|
/**
|
50
|
52
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -55,11 +57,11 @@ public final class LicencesPanel extends JPanel implements ListSelectionListener
|
55
|
57
|
/** Licence scroll pane. */
|
56
|
58
|
private JScrollPane scrollPane;
|
57
|
59
|
/** Licence list model */
|
58
|
|
- private GenericListModel<Licence> listModel;
|
|
60
|
+ private DefaultTreeModel listModel;
|
59
|
61
|
/** Licence textpane. */
|
60
|
62
|
private JEditorPane licence;
|
61
|
63
|
/** Licence list. */
|
62
|
|
- private JList list;
|
|
64
|
+ private JTree list;
|
63
|
65
|
/** Selected index. */
|
64
|
66
|
private int selectedIndex;
|
65
|
67
|
|
|
@@ -70,15 +72,13 @@ public final class LicencesPanel extends JPanel implements ListSelectionListener
|
70
|
72
|
initComponents();
|
71
|
73
|
addListeners();
|
72
|
74
|
layoutComponents();
|
73
|
|
-
|
74
|
|
- list.setSelectedIndex(0);
|
75
|
75
|
}
|
76
|
76
|
|
77
|
77
|
/**
|
78
|
78
|
* Adds the listeners to the components.
|
79
|
79
|
*/
|
80
|
80
|
private void addListeners() {
|
81
|
|
- list.addListSelectionListener(this);
|
|
81
|
+ list.addTreeSelectionListener(this);
|
82
|
82
|
}
|
83
|
83
|
|
84
|
84
|
/**
|
|
@@ -93,11 +93,27 @@ public final class LicencesPanel extends JPanel implements ListSelectionListener
|
93
|
93
|
/** Initialises the components. */
|
94
|
94
|
private void initComponents() {
|
95
|
95
|
setOpaque(UIUtilities.getTabbedPaneOpaque());
|
96
|
|
- listModel = new GenericListModel<Licence>();
|
97
|
|
- list = new JList(listModel);
|
98
|
|
- list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
99
|
|
- new ListScroller(list);
|
100
|
|
- new LicenceLoader(listModel).execute();
|
|
96
|
+ listModel = new DefaultTreeModel(new DefaultMutableTreeNode());
|
|
97
|
+ list = new JTree(listModel) {
|
|
98
|
+
|
|
99
|
+ /**
|
|
100
|
+ * A version number for this class. It should be changed whenever the class
|
|
101
|
+ * structure is changed (or anything else that would prevent serialized
|
|
102
|
+ * objects being unserialized with the new class).
|
|
103
|
+ */
|
|
104
|
+ private static final long serialVersionUID = 1;
|
|
105
|
+
|
|
106
|
+ /** {@inheritDoc} */
|
|
107
|
+ @Override
|
|
108
|
+ public void scrollRectToVisible(final Rectangle aRect) {
|
|
109
|
+ final Rectangle rect = new Rectangle(0, aRect.y, aRect.width,
|
|
110
|
+ aRect.height);
|
|
111
|
+ super.scrollRectToVisible(rect);
|
|
112
|
+ }
|
|
113
|
+ };
|
|
114
|
+ list.setRootVisible(false);
|
|
115
|
+ new TreeScroller(list);
|
|
116
|
+ new LicenceLoader(list, listModel).execute();
|
101
|
117
|
licence = new JEditorPane();
|
102
|
118
|
licence.setEditorKit(new HTMLEditorKit());
|
103
|
119
|
final Font font = UIManager.getFont("Label.font");
|
|
@@ -110,15 +126,22 @@ public final class LicencesPanel extends JPanel implements ListSelectionListener
|
110
|
126
|
|
111
|
127
|
/** {@inheritDoc} */
|
112
|
128
|
@Override
|
113
|
|
- public void valueChanged(final ListSelectionEvent e) {
|
114
|
|
- if (!e.getValueIsAdjusting()) {
|
115
|
|
- if (list.getSelectedIndex() == -1) {
|
116
|
|
- list.setSelectedIndex(selectedIndex);
|
117
|
|
- } else {
|
118
|
|
- licence.setText(listModel.get(list.getSelectedIndex()).getBody());
|
119
|
|
- UIUtilities.resetScrollPane(scrollPane);
|
120
|
|
- }
|
121
|
|
- selectedIndex = list.getSelectedIndex();
|
|
129
|
+ public void valueChanged(final TreeSelectionEvent e) {
|
|
130
|
+ list.scrollPathToVisible(e.getPath());
|
|
131
|
+ final Object userObject = ((DefaultMutableTreeNode) e.getPath().
|
|
132
|
+ getLastPathComponent()).getUserObject();
|
|
133
|
+ if (userObject instanceof Licence) {
|
|
134
|
+ licence.setText(((Licence) userObject).getBody());
|
|
135
|
+ } else if (userObject instanceof PluginInfo) {
|
|
136
|
+ final PluginInfo pi = (PluginInfo) userObject;
|
|
137
|
+ licence.setText("Name: " + pi.getNiceName() + "<br>"
|
|
138
|
+ + "Description: " + pi.getDescription() + "<br>"
|
|
139
|
+ + "Author: " + pi.getAuthor() + "<br>"
|
|
140
|
+ + "Version: " + pi.getFriendlyVersion());
|
|
141
|
+ } else {
|
|
142
|
+ licence.setText("Name: DMDirc<br>"
|
|
143
|
+ + "Desciption: The intelligent IRC client");
|
122
|
144
|
}
|
|
145
|
+ UIUtilities.resetScrollPane(scrollPane);
|
123
|
146
|
}
|
124
|
|
-}
|
|
147
|
+}
|