1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.xnap.gui.plugin;
20
21 import javax.swing.JScrollPane;
22 import javax.swing.event.HyperlinkEvent;
23 import javax.swing.event.HyperlinkListener;
24
25 import org.xnap.XNap;
26 import org.xnap.gui.AboutDialog;
27 import org.xnap.gui.XNapFrame;
28 import org.xnap.gui.component.DefaultDialog;
29 import org.xnap.gui.component.HTMLEditorPane;
30 import org.xnap.plugin.PluginInfo;
31
32 public class PluginDetailsDialog extends DefaultDialog {
33
34
35
36
37
38
39
40 public PluginDetailsDialog(PluginInfo info)
41 {
42 super(BUTTON_CLOSE);
43
44 setTitle(XNap.tr("XNap Plugin Details"));
45
46 HTMLEditorPane htmlPane = new HTMLEditorPane();
47 htmlPane.addHyperlinkListener(new LicenseLinkListener());
48
49 StringBuffer sb = new StringBuffer();
50 HTMLEditorPane.addHeader(sb);
51 addPluginInfo(sb, info);
52 HTMLEditorPane.addFooter(sb);
53 htmlPane.setText(sb.toString());
54
55 setMainComponent(new JScrollPane(htmlPane));
56 pack();
57
58
59 pack();
60 setSize(450, 300);
61 }
62
63
64
65 private static void addParagraph(StringBuffer sb, String text)
66 {
67 if (text != null && text.length() > 0) {
68 sb.append("<p>");
69 sb.append(text);
70 sb.append("</p>");
71 }
72 }
73
74 private static void addParagraph(StringBuffer sb, String description,
75 String text, String filename)
76 {
77 if (filename != null && filename.length() > 0) {
78 addParagraph(sb, description + "<a href=\"" + filename + "\">"
79 + text + "</a>");
80 }
81 else {
82 addParagraph(sb, description + text);
83 }
84 }
85
86 public static void addPluginInfo(StringBuffer content, PluginInfo info)
87 {
88 content.append("<h2>");
89 content.append(info.getName());
90 content.append(" ");
91 content.append(info.getVersion());
92 content.append("</h2>");
93
94 addParagraph(content, info.getDescription());
95 addParagraph(content, info.getLongDescription());
96
97 if (info.getAuthors().length() > 0) {
98 addParagraph(content, "Authors: " + info.getAuthors());
99 }
100
101 if (info.getLicense().length() > 0) {
102 addParagraph
103 (content, "License: ", info.getLicense(),
104 info.getLicenseFilename());
105 }
106 }
107
108 private class LicenseLinkListener implements HyperlinkListener
109 {
110 public void hyperlinkUpdate(HyperlinkEvent e)
111 {
112 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED
113 && e.getDescription() != null) {
114 AboutDialog.showDialog(XNapFrame.getInstance(),
115 e.getDescription());
116 }
117 }
118 }
119 }