View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Constant(s) ---
35  
36      //--- Data field(s) ---
37  
38      //--- Constructor(s) ---
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      //--- Method(s) ---
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 }