Browse Source

Tidy up rendering for the tree to make it not look terrible

Fixes issue 2643: Expose plugin licences

Change-Id: Ib5b7e6cdf2b12c3f08009316f8d716583d724543
Reviewed-on: http://gerrit.dmdirc.com/774
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 years ago
parent
commit
0f591a3c5f

+ 64
- 0
src/com/dmdirc/addons/ui_swing/dialogs/about/LicenceRenderer.java View File

@@ -0,0 +1,64 @@
1
+/*
2
+ * 
3
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
+ * 
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * 
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ * 
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+
24
+package com.dmdirc.addons.ui_swing.dialogs.about;
25
+
26
+import com.dmdirc.plugins.PluginInfo;
27
+
28
+import java.awt.Component;
29
+
30
+import javax.swing.JLabel;
31
+import javax.swing.JTree;
32
+import javax.swing.tree.DefaultMutableTreeNode;
33
+import javax.swing.tree.DefaultTreeCellRenderer;
34
+
35
+/**
36
+ * Simple renderer to show licence info in the tree.
37
+ */
38
+public class LicenceRenderer extends DefaultTreeCellRenderer {
39
+
40
+    /**
41
+     * A version number for this class. It should be changed whenever the class
42
+     * structure is changed (or anything else that would prevent serialized
43
+     * objects being unserialized with the new class).
44
+     */
45
+    private static final long serialVersionUID = 1;
46
+
47
+    /** {@inheritDoc} */
48
+    @Override
49
+    public Component getTreeCellRendererComponent(JTree tree, Object value,
50
+            boolean sel, boolean expanded, boolean leaf, int row,
51
+            boolean hasFocus) {
52
+        final JLabel label = (JLabel) super.getTreeCellRendererComponent(tree,
53
+                value, sel, expanded, leaf, row, hasFocus);
54
+        label.setIcon(null);
55
+        label.setBackground(tree.getBackground());
56
+        label.setForeground(tree.getForeground());
57
+        label.setOpaque(false);
58
+        if (((DefaultMutableTreeNode) value).getUserObject() instanceof PluginInfo) {
59
+            setText(((PluginInfo) ((DefaultMutableTreeNode) value).getUserObject()).
60
+                    getNiceName());
61
+        }
62
+        return label;
63
+    }
64
+}

+ 9
- 2
src/com/dmdirc/addons/ui_swing/dialogs/about/LicencesPanel.java View File

@@ -28,6 +28,7 @@ import com.dmdirc.plugins.PluginInfo;
28 28
 
29 29
 import java.awt.Font;
30 30
 import java.awt.Rectangle;
31
+import javax.swing.BorderFactory;
31 32
 
32 33
 import javax.swing.JEditorPane;
33 34
 import javax.swing.JPanel;
@@ -40,6 +41,7 @@ import javax.swing.text.html.HTMLDocument;
40 41
 import javax.swing.text.html.HTMLEditorKit;
41 42
 import javax.swing.tree.DefaultMutableTreeNode;
42 43
 import javax.swing.tree.DefaultTreeModel;
44
+import net.miginfocom.layout.PlatformDefaults;
43 45
 
44 46
 import net.miginfocom.swing.MigLayout;
45 47
 
@@ -62,8 +64,6 @@ public final class LicencesPanel extends JPanel implements TreeSelectionListener
62 64
     private JEditorPane licence;
63 65
     /** Licence list. */
64 66
     private JTree list;
65
-    /** Selected index. */
66
-    private int selectedIndex;
67 67
 
68 68
     /** Creates a new instance of LicencesPanel. */
69 69
     public LicencesPanel() {
@@ -111,7 +111,14 @@ public final class LicencesPanel extends JPanel implements TreeSelectionListener
111 111
                 super.scrollRectToVisible(rect);
112 112
             }
113 113
         };
114
+        list.setBorder(BorderFactory.createEmptyBorder(
115
+                (int) PlatformDefaults.getUnitValueX("related").getValue(),
116
+                (int) PlatformDefaults.getUnitValueX("related").getValue(),
117
+                (int) PlatformDefaults.getUnitValueX("related").getValue(),
118
+                (int) PlatformDefaults.getUnitValueX("related").getValue()));
119
+        list.setCellRenderer(new LicenceRenderer());
114 120
         list.setRootVisible(false);
121
+        list.setOpaque(false);
115 122
         new TreeScroller(list);
116 123
         new LicenceLoader(list, listModel).execute();
117 124
         licence = new JEditorPane();

Loading…
Cancel
Save