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  
23  import java.awt.Component;
24  import java.awt.GridBagLayout;
25  
26  import javax.swing.JCheckBox;
27  import javax.swing.*;
28  
29  import org.xnap.XNap;
30  import org.xnap.gui.AbstractSettingsPanel;
31  import org.xnap.gui.action.EnableAction;
32  import org.xnap.gui.component.ValidatedTextField;
33  import org.xnap.gui.component.XNapCheckBox;
34  import org.xnap.gui.util.GUIHelper;
35  import org.xnap.gui.util.GridBagHelper;
36  
37  public class AdvancedTransferPrefsPanel extends AbstractSettingsPanel {
38      
39      //--- Data field(s) ---
40  
41      private ValidatedTextField jteMinimumShares;
42      private JCheckBox jcbMininumShares;
43      private ValidatedTextField jteMinimumSharesMessage;
44      private JCheckBox jcbMininumSharesMessage;
45  	private EnableAction autoClearTransfersAction;
46  	private ValidatedTextField autoClearTransfersIntervalTextField;
47  
48      //--- Constructor(s) ---
49  
50      public AdvancedTransferPrefsPanel()
51      {
52  		setLayout(new GridBagLayout());
53  
54  		// auto clear finished 
55  		JPanel optionsPanel = new JPanel(new GridBagLayout());
56  		optionsPanel.setBorder
57  			(GUIHelper.createDefaultBorder(XNap.tr("Options")));
58  		GridBagHelper.add(this, optionsPanel);
59  
60          autoClearTransfersIntervalTextField = new ValidatedTextField
61  			(prefs.getAutoClearTransfersInterval() / 60 + "", 5, 
62  			 ValidatedTextField.NUMBERS_INT);
63  		autoClearTransfersAction
64  			= new EnableAction
65  				(XNap.tr("Automatically clear finished transfers every"),
66  				 new Component[] { autoClearTransfersIntervalTextField },
67  				 prefs.getAutoClearTransfers());
68  		GridBagHelper.addComponent
69  			(optionsPanel, new XNapCheckBox(autoClearTransfersAction));
70  		GridBagHelper.addComponent
71  			(optionsPanel, autoClearTransfersIntervalTextField);
72  		GridBagHelper.addLabel(optionsPanel, XNap.tr("min"));
73  		// XXX: workaroung to ensure left alignment
74  		GridBagHelper.add(optionsPanel, new JLabel());
75  
76  		// minimum shares of peer to be allowed to download
77  		JPanel jpMinimumShares = new JPanel(new GridBagLayout());
78  		jpMinimumShares.setBorder
79  			(GUIHelper.createDefaultBorder("Minimum Shares to be allowed to download"));
80  		GridBagHelper.add(this, jpMinimumShares);
81  
82  		jteMinimumShares = 
83  			new ValidatedTextField(prefs.getMinimumShares() + "", 5, 
84  								   ValidatedTextField.NUMBERS_INT);
85  		EnableAction ac 
86  			= new EnableAction(XNap.tr("Minimum"),
87  							   new Component[] { jteMinimumShares },
88  							   prefs.getUseMinimumShares());
89  		jcbMininumShares = new XNapCheckBox(ac);
90  		jcbMininumShares.setSelected(prefs.getUseMinimumShares());
91  		GridBagHelper.addComponent(jpMinimumShares, jcbMininumShares);
92  		GridBagHelper.add(jpMinimumShares, jteMinimumShares, false);
93  
94  		// minimum shares message
95  		jteMinimumSharesMessage =
96  			new ValidatedTextField(prefs.getMinimumSharesMessage(), 20,
97  								   ValidatedTextField.ANYTHING);
98  		ac = new EnableAction(XNap.tr("Message"), 
99  							  new Component[] { jteMinimumSharesMessage },
100 							  prefs.getSendMinimumSharesMessage());
101 		jcbMininumSharesMessage = new XNapCheckBox(ac);
102 
103 		GridBagHelper.addComponent(jpMinimumShares, jcbMininumSharesMessage);
104 		GridBagHelper.add(jpMinimumShares, jteMinimumSharesMessage);		
105 
106 		GridBagHelper.addVerticalSpacer(this);
107 		GUIHelper.setMnemonics(this);
108     }
109 
110     public void apply() 
111     {
112 		prefs.setAutoClearTransfers(autoClearTransfersAction.isSelected());
113 		prefs.setAutoClearTransfersInterval
114 			(autoClearTransfersIntervalTextField.getIntValue() * 60);
115 		prefs.setUseMinimumShares(jcbMininumShares.isSelected());
116 		prefs.setMinimumShares(jteMinimumShares.getIntValue());
117 		prefs.setSendMinimumSharesMessage
118 			(jcbMininumSharesMessage.isSelected());
119 		prefs.setMinimumSharesMessage(jteMinimumSharesMessage.getText());
120     }
121 
122     public String getTitle()
123     {
124 		return XNap.tr("Advanced");
125     }
126 
127 }