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  
20  package org.xnap.gui;
21  
22  import java.awt.Font;
23  import java.awt.GridBagLayout;
24  import java.awt.event.MouseAdapter;
25  import java.awt.event.MouseEvent;
26  
27  import javax.swing.BorderFactory;
28  import javax.swing.JLabel;
29  import javax.swing.JPanel;
30  import javax.swing.JScrollPane;
31  import javax.swing.JTextArea;
32  import javax.swing.border.EmptyBorder;
33  
34  import org.xnap.XNap;
35  import org.xnap.gui.component.DefaultDialog;
36  import org.xnap.gui.component.MultiLineLabel;
37  import org.xnap.gui.util.GUIHelper;
38  import org.xnap.gui.util.GridBagHelper;
39  import org.xnap.plugin.PluginInfo;
40  
41  public class PluginInfoPanel extends JPanel {
42  
43      //--- Constant(s) ---
44  
45      //--- Data field(s) ---
46  	
47  	private PluginInfo info;
48  	private JLabel authorsLabel;
49      private MultiLineLabel descriptionLabel;
50  	private JLabel licenseLabel;
51      private JLabel nameLabel;
52  	
53      //--- Constructor(s) ---
54  
55      public PluginInfoPanel() 
56      {
57  		setLayout(new GridBagLayout());
58  
59  		nameLabel = GridBagHelper.addLabel(this, "", true);
60  		nameLabel.setFont(nameLabel.getFont().deriveFont(Font.BOLD));
61  
62  		descriptionLabel = new MultiLineLabel();
63  		GridBagHelper.add(this, descriptionLabel);
64  
65    		GridBagHelper.addLabel(this, XNap.tr("Authors:"));
66  		authorsLabel = GridBagHelper.addLabel(this, "", true);
67  
68  		GridBagHelper.addLabel(this, XNap.tr("License:"));
69  		licenseLabel = GridBagHelper.addLabel(this, "", true);
70  		licenseLabel.addMouseListener(new LicenseListener());
71      }
72  
73      //--- Method(s) ---
74  
75  	/***
76       * Updates the plugin info panel.
77       */
78  	public void setInfo(PluginInfo info)
79      {
80  		this.info = info;
81  		
82  		nameLabel.setText(info.getName() + " " + info.getVersion());
83  		descriptionLabel.setText("\n" + info.getDescription() + 
84  								 "\n\n" + info.getLongDescription() + "\n");
85  		authorsLabel.setText(info.getAuthors());
86  		licenseLabel.setText
87  			("<html><a href=''>" + info.getLicense() + "</a> <br>");
88      }
89  
90  	//--- Inner Class(es) ---
91  	
92  	private class LicenseListener extends MouseAdapter
93  	{
94  		public void mousePressed(MouseEvent e) 
95  		{
96  			DefaultDialog d = new DefaultDialog(DefaultDialog.BUTTON_CLOSE);
97  			
98  			// plugins tab
99  			//JTextArea jtextArea = new JTextArea(15, 40);
100 			JTextArea jtextArea = new JTextArea(30, 80);
101 			jtextArea.setBorder(new EmptyBorder(5, 5, 5, 5));
102 			jtextArea.setEditable (false);
103 			jtextArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
104 			jtextArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
105 			GUIHelper.showFile(jtextArea, info.getLicenseFilename(),
106 							   XNap.tr("File {0} not found!", 
107 									   info.getLicenseFilename()));
108 
109 			d.setTitle(XNap.tr("License"));
110 			d.setMainComponent(new JScrollPane(jtextArea));
111 			d.pack();
112 			d.show(PluginInfoPanel.this);
113 		}
114 	}
115 
116 }