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.plugin;
21  
22  import java.awt.Component;
23  import java.awt.event.ActionEvent;
24  
25  import javax.swing.AbstractAction;
26  import javax.swing.Action;
27  
28  import org.xnap.XNap;
29  import org.xnap.gui.component.DefaultDialog;
30  import org.xnap.gui.component.XNapButton;
31  import org.xnap.gui.util.*;
32  
33  public class PluginDialog extends DefaultDialog {
34  
35      //--- Constant(s) ---
36  
37      //--- Data field(s) ---
38  
39      private static PluginDialog me = null;
40  
41  	private PluginPanel panel;
42      private Action updateListAction = new UpdateListAction();
43  
44      //--- Constructor(s) ---
45  
46      private PluginDialog() 
47      {
48  		super(BUTTON_OKAY | BUTTON_CANCEL);
49  
50  		initialize();
51  
52  		pack();
53  		setSize(550, 400);
54  
55   		panel.update();
56      }
57  
58      public void initialize()
59      {
60          setTitle(XNap.tr("Plugins"));
61  
62  		// plugin list
63  		panel = new PluginPanel(true);
64  		setMainComponent(panel);
65  
66  		// JDK 1.4 binds the escape key for JTree objects to some
67  		// wired function that results in a NullPointerException
68  		GUIHelper.bindEscapeKey(panel.getPluginTree(), null);
69  
70  		// buttons
71  		getButtonPanel().add(new XNapButton(updateListAction), 0);
72  	}
73  
74      //--- Method(s) ---
75  
76      public static void showDialog(Component c)
77      {
78  		if (me == null) {
79  			me = new PluginDialog();
80  		}
81  		me.show(c);
82      }
83  
84  	public boolean apply()
85  	{
86  		panel.apply();
87  		return PluginInstallerDialog.commit(this);
88  	}
89  
90  	public void close()
91  	{
92  		dispose();
93  		me = null;
94  	}
95  
96      // --- Inner Class(es) ---
97  
98      private class UpdateListAction extends AbstractAction {
99  
100         public UpdateListAction() 
101 		{
102             putValue(Action.NAME, XNap.tr("Update List"));
103             putValue(Action.SHORT_DESCRIPTION, 
104 					 XNap.tr("Updates the list packages from the internet."));
105         }
106 
107         public void actionPerformed(ActionEvent event) 
108 		{
109 			panel.updatePackageManager();
110         }
111 
112     }
113 	
114 }