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.BorderLayout;
23  import java.awt.GridBagConstraints;
24  import java.awt.GridBagLayout;
25  import java.awt.event.ActionEvent;
26  
27  import javax.help.CSH;
28  import javax.swing.AbstractAction;
29  import javax.swing.Action;
30  import javax.swing.JButton;
31  import javax.swing.JCheckBox;
32  import javax.swing.JPanel;
33  
34  import org.xnap.XNap;
35  import org.xnap.gui.AbstractSettingsPanel;
36  import org.xnap.gui.Messages;
37  import org.xnap.gui.component.DefaultDialog;
38  import org.xnap.gui.component.DirectoryList;
39  import org.xnap.gui.component.DirectoryPanel;
40  import org.xnap.gui.component.MultiLineLabel;
41  import org.xnap.gui.util.GUIHelper;
42  import org.xnap.gui.util.GridBagHelper;
43  
44  /***
45   * Provides controls for directory settings.
46   */
47  public class FilePrefsPanel extends AbstractSettingsPanel 
48  {
49  
50      //--- Data field(s) ---
51  
52      private DirectoryList dlUploadDirs;
53      private DirectoryPanel jteDownloadDir;
54      private DirectoryPanel jteIncompleteDir;    
55      private JCheckBox jcShareFullPath;
56  
57      //--- Constructor(s) ---
58  
59      public FilePrefsPanel()
60      {
61  		setLayout(new GridBagLayout());
62  
63  		// help
64  		CSH.setHelpIDString(this, "files-files");
65  
66  		// download directory
67  		JPanel jpDl = new JPanel(new GridBagLayout());
68  		jpDl.setBorder
69  			(GUIHelper.createDefaultBorder(XNap.tr("Download Directory")));
70          GridBagHelper.add(this, jpDl);
71          jteDownloadDir = new DirectoryPanel(prefs.getDownloadDir(), 20);
72  		GridBagHelper.add(jpDl, jteDownloadDir);
73  		// advanced button
74  		GridBagHelper.add(jpDl, new JButton(new AdvancedAction()), 
75  						  GridBagHelper.COMPONENT_INSETS, false, 
76  						  GridBagConstraints.NORTHEAST);
77  
78  		// help
79  		CSH.setHelpIDString(jpDl, "files-files-downloaddir");
80  		
81  
82  		// incomplete directory
83  		JPanel jpIncomplete = new JPanel(new GridBagLayout());
84  		jpIncomplete.setBorder
85  			(GUIHelper.createDefaultBorder(XNap.tr("Incomplete Directory")));
86  		GridBagHelper.add(this, jpIncomplete);
87          jteIncompleteDir = new DirectoryPanel(prefs.getIncompleteDir(), 20);
88  		GridBagHelper.add(jpIncomplete, jteIncompleteDir);
89  
90  		// help
91  		CSH.setHelpIDString(jpIncomplete, "files-files-incompletedir");
92  
93  		// upload directory list
94  		JPanel jpUl = new JPanel(new GridBagLayout());
95  		jpUl.setBorder
96  			(GUIHelper.createDefaultBorder(XNap.tr("Shared Directories")));
97          GridBagHelper.add(this, jpUl);
98  
99  		GridBagHelper.add
100 			(jpUl, new MultiLineLabel(Messages.RECURSIVE_SHARE));
101 		dlUploadDirs = new DirectoryList(prefs.getUploadDirs(), 20, 3);
102 		GridBagHelper.add(jpUl, dlUploadDirs);
103 		jcShareFullPath  = new JCheckBox(XNap.tr("Share Full Path"), 
104 										 prefs.getShareFullPath());
105 		GridBagHelper.add(jpUl, jcShareFullPath);
106 
107 		// help
108 		CSH.setHelpIDString(jpUl, "files-files-shareddirs");
109 		CSH.setHelpIDString(jcShareFullPath, "files-files-sharefullpath");
110 
111 
112 		GridBagHelper.addVerticalSpacer(this);
113 		GUIHelper.setMnemonics(this);
114     }
115 
116     //--- Method(s) ---
117 
118     public void apply() 
119     {
120 		prefs.setIncompleteDir(jteIncompleteDir.getDirectory());
121 		prefs.setDownloadDir(jteDownloadDir.getDirectory());
122 		prefs.setUploadDirs(dlUploadDirs.getDirectories());
123 		prefs.setShareFullPath(jcShareFullPath.isSelected());
124     }
125 
126     public String getTitle()
127     {
128 		return XNap.tr("Files");
129     }
130 
131     //--- Inner Class(es) ---
132 
133     /***
134      * 
135      */
136     private class AdvancedAction extends AbstractAction 
137     {
138         public AdvancedAction()
139 		{
140             putValue(Action.NAME, XNap.tr("Advanced") + "...");
141             putValue(Action.SHORT_DESCRIPTION,
142 					 XNap.tr("Shows media download dir dialog."));
143         }
144 
145         public void actionPerformed(ActionEvent event) 
146 		{
147 			MediaDownloadDirDialog dialog = new MediaDownloadDirDialog();
148 			dialog.show(FilePrefsPanel.this);
149         }
150 
151     }
152 
153     private class MediaDownloadDirDialog extends DefaultDialog
154     {
155 
156 		private MediaDownloadDirPanel jpDirs;
157 
158 		public MediaDownloadDirDialog()
159 		{
160 			super(BUTTON_OKAY | BUTTON_CANCEL, false);
161 
162 			setTitle(XNap.tr("Mediatype Download Directories"));
163 			setModal(true);
164 
165 			jpDirs = new MediaDownloadDirPanel();
166 	    
167 			getMainPanel().setLayout(new BorderLayout());
168 			getMainPanel().add(jpDirs, BorderLayout.CENTER);
169 
170 			pack();
171 
172 			//jpDirs.adjustWidth();
173 		}
174 
175 		public boolean apply()
176 		{
177 			jpDirs.apply();
178 			return true;
179 		}
180 
181     }
182 
183 }