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  
24  import javax.swing.*;
25  import javax.swing.JCheckBox;
26  import javax.swing.JPanel;
27  import javax.swing.JRadioButton;
28  
29  import org.xnap.XNap;
30  import org.xnap.gui.AbstractSettingsPanel;
31  import org.xnap.gui.component.ValidatedTextField;
32  import org.xnap.gui.util.GUIHelper;
33  import org.xnap.gui.util.GridBagHelper;
34  
35  /***
36   * Provides controls for application appearance settings.
37   */
38  public class ApplicationPrefsPanel extends AbstractSettingsPanel {
39      
40      //--- Data field(s) ---
41  
42      private JCheckBox jcShowIcons;
43      private JCheckBox jcShowSplash;
44      private JCheckBox jcShowTooltips;
45  	private JCheckBox jcbUseSubMenuForPluginMenus;
46  
47      private ValidatedTextField jteMaxConsoleLines;
48      private ValidatedTextField jteHistorySize;
49  
50      private JRadioButton jrbFocusAlways;
51      private JRadioButton jrbFocusNever;
52  
53      //--- Constructor(s) ---
54  
55      public ApplicationPrefsPanel()
56      {
57  		setLayout(new GridBagLayout());
58  
59          jcShowSplash = new JCheckBox(XNap.tr("Show Splash Screen", 1),
60                                       prefs.getShowSplash());
61  		GridBagHelper.add(this, jcShowSplash);
62  
63          jcShowIcons = new JCheckBox(XNap.tr("Display Icons", 1), 
64  									prefs.getShowIcons());
65  		GridBagHelper.add(this, jcShowIcons);
66  
67  		jcShowTooltips = new JCheckBox(XNap.tr("Show Tooltips",1),
68  									   prefs.getShowToolTips());
69  		GridBagHelper.add(this, jcShowTooltips);
70  
71  		jcbUseSubMenuForPluginMenus = new JCheckBox
72  			(XNap.tr("Add plugin menus to plugin menu", 1),
73  			 prefs.getUseSubMenuForPluginMenus());
74  		GridBagHelper.add(this, jcbUseSubMenuForPluginMenus);
75  
76  		JPanel jpSizes = new JPanel(new GridBagLayout());
77  		jpSizes.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Number of Lines")));
78  		GridBagHelper.add(this, jpSizes);
79  
80          JLabel l = GridBagHelper.addLabel(jpSizes, XNap.tr("Console"));
81          jteMaxConsoleLines = new ValidatedTextField
82  			(prefs.getMaxConsoleLines() + "", 5, 
83  			 ValidatedTextField.NUMBERS_INT);
84  		l.setLabelFor(jteMaxConsoleLines);
85          GridBagHelper.add(jpSizes, jteMaxConsoleLines, false);
86  
87  		l = GridBagHelper.addLabel(jpSizes, XNap.tr("History"));
88          jteHistorySize = new ValidatedTextField
89  			(prefs.getSearchHistorySize() + "", 5, 
90  			 ValidatedTextField.NUMBERS_INT);
91  		l.setLabelFor(jteHistorySize);
92          GridBagHelper.add(jpSizes, jteHistorySize, false);
93  
94  		JPanel jpFocusPolicies = new JPanel(new GridBagLayout());
95  		jpFocusPolicies.setBorder
96  			(GUIHelper.createDefaultBorder(XNap.tr("Global Focus Policy")));
97  		GridBagHelper.add(this, jpFocusPolicies);
98  
99  		ButtonGroup bg = new ButtonGroup();
100 		jrbFocusAlways = new JRadioButton(XNap.tr("Auto Focus New Windows"),
101 										  prefs.getFocusOnAllEvents());
102 		bg.add(jrbFocusAlways);
103 		GridBagHelper.add(jpFocusPolicies, jrbFocusAlways);
104 
105 		jrbFocusNever = new JRadioButton(XNap.tr("Never Switch Focus"),
106 										 !prefs.getFocusOnAllEvents());
107 		bg.add(jrbFocusNever);
108 		GridBagHelper.add(jpFocusPolicies, jrbFocusNever);
109 
110 		GridBagHelper.addVerticalSpacer(this);
111 		GUIHelper.setMnemonics(this);
112     }
113 
114     public void apply() 
115     {
116 		prefs.setShowIcons(jcShowIcons.isSelected());
117 		prefs.setShowSplash(jcShowSplash.isSelected());
118 		prefs.setShowToolTips(jcShowTooltips.isSelected());
119 		prefs.setUseSubMenuForPluginMenus
120 			(jcbUseSubMenuForPluginMenus.isSelected());
121 
122 		prefs.setMaxConsoleLines(jteMaxConsoleLines.getIntValue());
123 		prefs.setSearchHistorySize(jteHistorySize.getIntValue());
124 
125 		prefs.setFocusOnAllEvents(jrbFocusAlways.isSelected());
126     }
127 
128     public String getTitle()
129     {
130 		return XNap.tr("Application");
131     }
132 
133 }