~ubuntu-branches/ubuntu/quantal/freeguide/quantal

« back to all changes in this revision

Viewing changes to src/program/gui/options/PrivacyOptionPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2006-09-30 10:14:18 UTC
  • mfrom: (1.2.3 upstream) (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060930101418-pkilk36yy22nbt3r
Tags: 0.10.4-2
Update the watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  FreeGuide J2
3
 
 *
4
 
 *  Copyright (c) 2001-2004 by Andy Balaam and the FreeGuide contributors
5
 
 *
6
 
 *  freeguide-tv.sourceforge.net
7
 
 *
8
 
 *  Released under the GNU General Public License
9
 
 *  with ABSOLUTELY NO WARRANTY.
10
 
 *
11
 
 *  See the file COPYING for more information.
12
 
 */
13
 
 
14
 
package freeguide.gui.options;
15
 
 
16
 
import freeguide.gui.dialogs.*;
17
 
import freeguide.lib.general.*;
18
 
import java.awt.*;
19
 
import java.awt.event.*;
20
 
import javax.swing.*;
21
 
import javax.swing.event.*;
22
 
 
23
 
/*
24
 
 *  A panel full of options about privacy and checking for new version of
25
 
 *  FreeGuide
26
 
 *
27
 
 * @author     Andy Balaam
28
 
 * @created    12 Dec 2003
29
 
 * @version    1
30
 
 */
31
 
 
32
 
public class PrivacyOptionPanel extends OptionPanel implements ActionListener {
33
 
 
34
 
        public PrivacyOptionPanel( FGDialog parent ) {
35
 
                super( parent );
36
 
        }
37
 
                        
38
 
        public void doConstruct() {
39
 
                
40
 
                // Make the objects
41
 
                
42
 
                JLabel checkLabel = newLeftJLabel(
43
 
                        "Check for new versions?" );
44
 
                Object[] options = new Object[2];
45
 
                options[0] = "Yes";
46
 
                options[1] = "No";
47
 
                checkComboBox = newRightJComboBox( options );
48
 
                checkLabel.setLabelFor(checkComboBox);
49
 
                checkLabel.setDisplayedMnemonic(KeyEvent.VK_V);
50
 
                
51
 
                JLabel provideLabel = newLeftJLabel(
52
 
                        "Provide info:" );
53
 
                options = new Object[3];
54
 
                options[0] = "None";
55
 
                options[1] = "IP";
56
 
                options[2] = "Nickname:";
57
 
                provideComboBox = newRightJComboBox( options );
58
 
                provideLabel.setLabelFor(provideComboBox);
59
 
                provideLabel.setDisplayedMnemonic(KeyEvent.VK_P);
60
 
                
61
 
                JLabel nicknameLabel = newLeftJLabel( "Nickname:" );
62
 
                nicknameTextField = newRightJTextField();
63
 
                nicknameLabel.setLabelFor(nicknameTextField);
64
 
                nicknameLabel.setDisplayedMnemonic(KeyEvent.VK_N);
65
 
                
66
 
                infoButton = newRightJButton( "More Info" );
67
 
                infoButton.setMnemonic(KeyEvent.VK_M);
68
 
                
69
 
                // Lay them out in a GridBag layout
70
 
                GridBagEasy gbe = new GridBagEasy( this );
71
 
                
72
 
                gbe.default_insets = new Insets( 1, 1, 1, 1 );
73
 
                gbe.default_ipadx = 5;
74
 
                gbe.default_ipady = 5;
75
 
                
76
 
                gbe.addFWX  ( checkLabel     , 0, 0, gbe.FILL_HOR   , 0.2 );
77
 
                gbe.addFWX  ( checkComboBox  , 1, 0, gbe.FILL_HOR   , 0.8 );
78
 
                
79
 
                gbe.addFWX  ( provideLabel   , 0, 1, gbe.FILL_HOR   , 0.2 );
80
 
                gbe.addFWX  ( provideComboBox, 1, 1, gbe.FILL_HOR   , 0.8 );
81
 
                
82
 
                gbe.addFWX  ( nicknameLabel    , 0, 2, gbe.FILL_HOR , 0.2 );
83
 
                gbe.addFWX  ( nicknameTextField, 1, 2, gbe.FILL_HOR , 0.8 );
84
 
                
85
 
                gbe.addAWX  ( infoButton     , 1, 3, gbe.ANCH_WEST  , 0.8 );
86
 
                
87
 
                // Events
88
 
                checkComboBox.addActionListener(this);
89
 
                provideComboBox.addActionListener(this);
90
 
                infoButton.addActionListener(this);
91
 
                
92
 
                // Load in the values from config
93
 
                load();
94
 
                
95
 
        }
96
 
        
97
 
        protected void doLoad( String prefix ) {
98
 
 
99
 
                String privacy = misc.get( prefix + "privacy", "no" );
100
 
                
101
 
                if( privacy.startsWith("yes_nick:") ) {
102
 
                        checkComboBox.setSelectedIndex(0);
103
 
                        provideComboBox.setSelectedIndex(2);
104
 
                        nicknameTextField.setText( privacy.substring( 9 ) );
105
 
                } else if( privacy.equals("yes_ip") ) {
106
 
                        checkComboBox.setSelectedIndex(0);
107
 
                        provideComboBox.setSelectedIndex(1);
108
 
                } else if( privacy.equals("yes_nothing") ) {
109
 
                        checkComboBox.setSelectedIndex(0);
110
 
                        provideComboBox.setSelectedIndex(0);
111
 
                } else if( privacy.equals("no") ) {
112
 
                        checkComboBox.setSelectedIndex(1);
113
 
                }
114
 
                
115
 
        }
116
 
        
117
 
        
118
 
        
119
 
        /**
120
 
         * Saves the values in this option pane.
121
 
         *
122
 
         * @return false since nothing changes the view
123
 
         */
124
 
        public boolean doSave() {
125
 
        
126
 
                if( checkComboBox.getSelectedIndex() == 1 ) {
127
 
                        misc.put( "privacy", "no" );
128
 
                } else {
129
 
                        
130
 
                        switch( provideComboBox.getSelectedIndex() ) {
131
 
                        case 0:
132
 
                                misc.put( "privacy", "yes_nothing" );
133
 
                                break;
134
 
                        case 1:
135
 
                                misc.put( "privacy", "yes_ip" );
136
 
                                break;
137
 
                        case 2:
138
 
                                misc.put( "privacy", "yes_nick:"
139
 
                                        + nicknameTextField.getText() );
140
 
                                break;
141
 
                        
142
 
                        }
143
 
                }
144
 
                
145
 
                return false;
146
 
                
147
 
        }
148
 
        
149
 
        public void actionPerformed(ActionEvent e) {
150
 
 
151
 
                if( e.getSource() == infoButton ) {
152
 
                        
153
 
                        new PrivacyInfoDialog().setVisible( true );
154
 
                        
155
 
                } else {
156
 
                
157
 
                        boolean check = ( checkComboBox.getSelectedIndex() == 0 );
158
 
                        boolean provide = ( provideComboBox.getSelectedIndex() == 2 );
159
 
                
160
 
                        provideComboBox.setEnabled( check );
161
 
                        nicknameTextField.setFocusable( check && provide );
162
 
                        
163
 
                }
164
 
                
165
 
        }
166
 
        
167
 
        /**
168
 
         * Used to find the name of this panel when displayed in a JTree.
169
 
         */
170
 
        public String toString() {
171
 
                
172
 
                return "Privacy";
173
 
                
174
 
        }
175
 
 
176
 
        // ----------------------------------
177
 
        
178
 
        private JComboBox checkComboBox;
179
 
        private JComboBox provideComboBox;
180
 
        private JButton infoButton;
181
 
        private JTextField nicknameTextField;
182
 
        
183
 
}
184