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.prefs;
21  
22  import java.awt.GridBagLayout;
23  import java.awt.event.ActionEvent;
24  import java.io.IOException;
25  
26  import javax.swing.AbstractAction;
27  import javax.swing.Action;
28  import javax.swing.JPanel;
29  
30  import org.xnap.XNap;
31  import org.xnap.gui.AbstractSettingsPanel;
32  import org.xnap.gui.action.PackageDialogAction;
33  import org.xnap.gui.component.DirectoryList;
34  import org.xnap.gui.component.XNapButton;
35  import org.xnap.gui.pkg.EditSourcesPanel;
36  import org.xnap.gui.util.GUIHelper;
37  import org.xnap.gui.util.GridBagHelper;
38  import org.xnap.pkg.XNapPackageManager;
39  
40  /***
41   * Provides controls for personal settings.
42   */
43  public class PackagePrefsPanel extends AbstractSettingsPanel {
44      
45      //--- Data field(s) ---
46  
47  	private EditSourcesPanel editSourcesPanel;
48  	private DirectoryList includePathList;
49  
50      //--- Constructor(s) ---
51  	
52      public PackagePrefsPanel()
53      {
54  		setLayout(new GridBagLayout());
55  
56  		// sources list
57  		editSourcesPanel = new EditSourcesPanel();
58  		GridBagHelper.add(this, editSourcesPanel);
59  
60  		// jar include path
61  		JPanel includePathPanel = new JPanel(new GridBagLayout());
62  		// share full path
63  		includePathPanel.setBorder
64  			(GUIHelper.createDefaultBorder(XNap.tr("Jar Include Path")));
65          GridBagHelper.add(this, includePathPanel);
66  		includePathList = new DirectoryList(prefs.getJarIncludePath(), 20, 3);
67  		GridBagHelper.add(includePathPanel, includePathList);
68  
69  		GridBagHelper.addVerticalSpacer(this);
70  
71  		GridBagHelper.addComponent
72  			(this, new XNapButton(new PackageDialogAction()));
73  		GridBagHelper.addComponent
74  			(this, new XNapButton(new DiscoverPackagesAction()));
75  
76  		GUIHelper.setMnemonics(this);
77      }
78  
79      //--- Method(s) ---
80  
81      public void apply() throws IOException
82      {
83  		editSourcesPanel.apply();
84  		prefs.setJarIncludePath(includePathList.getDirectories());
85      }
86  
87  	public String getDescription()
88  	{
89  		return XNap.tr("Package manager settings.");
90  	}
91  
92      public String getTitle()
93      {
94  		return XNap.tr("Packages");
95      }
96  
97      // --- Inner Class(es) ---
98  
99      private class DiscoverPackagesAction extends AbstractAction {
100 
101         public DiscoverPackagesAction() 
102 		{
103             putValue(Action.NAME, XNap.tr("Search For Packages"));
104             putValue(Action.SHORT_DESCRIPTION, 
105 					 XNap.tr("Searches for locally installed packages."));
106         }
107 
108         public void actionPerformed(ActionEvent event) 
109 		{
110 			XNapPackageManager.getInstance().discover();
111         }
112 
113     }
114 
115 }
116 
117 
118