001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.mail.gui.config.account;
018:
019: import java.awt.Component;
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022: import java.io.File;
023:
024: import javax.swing.JButton;
025: import javax.swing.JCheckBox;
026: import javax.swing.JComboBox;
027: import javax.swing.JFileChooser;
028: import javax.swing.JLabel;
029: import javax.swing.JTextField;
030:
031: import org.columba.core.gui.base.CheckBoxWithMnemonic;
032: import org.columba.core.gui.base.LabelWithMnemonic;
033: import org.columba.mail.config.SecurityItem;
034: import org.columba.mail.util.MailResourceLoader;
035:
036: import com.jgoodies.forms.builder.DefaultFormBuilder;
037: import com.jgoodies.forms.layout.FormLayout;
038:
039: /**
040: * Shows PGP-related options.
041: */
042: public class SecurityPanel extends DefaultPanel implements
043: ActionListener {
044: private JLabel idLabel;
045:
046: private JTextField idTextField;
047:
048: private JLabel typeLabel;
049:
050: private JComboBox typeComboBox;
051:
052: private JLabel pathLabel;
053:
054: private JButton pathButton;
055:
056: private JCheckBox enableCheckBox;
057:
058: private JCheckBox alwaysSignCheckBox;
059:
060: private JCheckBox alwaysEncryptCheckBox;
061:
062: private SecurityItem item;
063:
064: public SecurityPanel(SecurityItem item) {
065: super ();
066: this .item = item;
067:
068: initComponents();
069: updateComponents(true);
070: layoutComponents();
071:
072: //enableCheckBox.setEnabled(false);
073: }
074:
075: protected void updateComponents(boolean b) {
076: if (b) {
077: idTextField.setText(item.get(SecurityItem.ID));
078: pathButton.setText(item.get(SecurityItem.PATH));
079:
080: enableCheckBox.setSelected(item
081: .getBoolean(SecurityItem.ENABLED));
082:
083: alwaysSignCheckBox.setSelected(item
084: .getBoolean(SecurityItem.ALWAYS_SIGN));
085: alwaysEncryptCheckBox.setSelected(item
086: .getBoolean(SecurityItem.ALWAYS_ENCRYPT));
087:
088: enablePGP(enableCheckBox.isSelected());
089: } else {
090: item.setString(SecurityItem.ID, idTextField.getText());
091: item.setString(SecurityItem.PATH, pathButton.getText());
092:
093: item.setBoolean(SecurityItem.ENABLED, enableCheckBox
094: .isSelected());
095:
096: item.setBoolean(SecurityItem.ALWAYS_SIGN,
097: alwaysSignCheckBox.isSelected());
098: item.setBoolean(SecurityItem.ALWAYS_ENCRYPT,
099: alwaysEncryptCheckBox.isSelected());
100: }
101: }
102:
103: protected void layoutComponents() {
104: // Create a FormLayout instance.
105: FormLayout layout = new FormLayout(
106: "10dlu, max(70dlu;default), 3dlu, fill:max(150dlu;default):grow ",
107:
108: // 2 columns
109: ""); // rows are added dynamically (no need to define them here)
110:
111: // create a form builder
112: DefaultFormBuilder builder = new DefaultFormBuilder(layout,
113: this );
114:
115: // create EmptyBorder between components and dialog-frame
116: builder.setDefaultDialogBorder();
117:
118: // skip the first column
119: builder.setLeadingColumnOffset(1);
120:
121: // Add components to the panel:
122: builder.appendSeparator(MailResourceLoader.getString("dialog",
123: "account", "pgp_options"));
124: builder.nextLine();
125:
126: builder.append(enableCheckBox, 3);
127: builder.nextLine();
128:
129: builder.append(idLabel, 1);
130: builder.append(idTextField);
131: builder.nextLine();
132:
133: builder.append(alwaysSignCheckBox, 3);
134: builder.nextLine();
135:
136: // TODO: reactivate when feature is supported
137: /*
138: * builder.append(alwaysEncryptCheckBox, 3); builder.nextLine();
139: */
140: }
141:
142: protected void initComponents() {
143: enableCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
144: .getString("dialog", "account", "enable_PGP_Support"));
145: enableCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);
146: enableCheckBox.setActionCommand("ENABLE");
147: enableCheckBox.addActionListener(this );
148:
149: idLabel = new LabelWithMnemonic(MailResourceLoader.getString(
150: "dialog", "account", "User_ID"));
151:
152: typeLabel = new JLabel(MailResourceLoader.getString("dialog",
153: "account", "PGP_Version")); //$NON-NLS-1$
154:
155: pathLabel = new JLabel(MailResourceLoader.getString("dialog",
156: "account", "Path_to_Binary")); //$NON-NLS-1$
157:
158: idTextField = new JTextField();
159:
160: typeComboBox = new JComboBox();
161:
162: //typeComboBox.setMargin( new Insets( 0,0,0,0 ) );
163: typeComboBox.insertItemAt("GnuPG", 0);
164: typeComboBox.insertItemAt("PGP2", 1);
165: typeComboBox.insertItemAt("PGP5", 2);
166: typeComboBox.insertItemAt("PGP6", 3);
167: typeComboBox.setSelectedIndex(0);
168: typeComboBox.setEnabled(false);
169:
170: pathButton = new JButton();
171:
172: //pathButton.setMargin( new Insets( 0,0,0,0 ) );
173: pathButton.setActionCommand("PATH");
174: pathButton.addActionListener(this );
175:
176: alwaysSignCheckBox = new CheckBoxWithMnemonic(
177: MailResourceLoader.getString("dialog", "account",
178: "Always_sign_when_sending_messages"));
179: alwaysSignCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);
180: alwaysSignCheckBox.setEnabled(false);
181:
182: alwaysEncryptCheckBox = new CheckBoxWithMnemonic(
183: MailResourceLoader
184: .getString(
185: "dialog", "account", "Always_encrypt_when_sending_messages")); //$NON-NLS-1$
186: alwaysEncryptCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);
187: alwaysEncryptCheckBox.setEnabled(false);
188: }
189:
190: public void enablePGP(boolean b) {
191: //typeComboBox.setEnabled(b);
192: idTextField.setEnabled(b);
193: idLabel.setEnabled(b);
194: typeLabel.setEnabled(b);
195: pathLabel.setEnabled(b);
196: pathButton.setEnabled(b);
197: alwaysSignCheckBox.setEnabled(b);
198: alwaysEncryptCheckBox.setEnabled(b);
199: }
200:
201: public void actionPerformed(ActionEvent e) {
202: String action = e.getActionCommand();
203:
204: if (action.equals("ENABLE")) {
205: enablePGP(enableCheckBox.isSelected());
206: } else if (action.equals("PATH")) {
207: JFileChooser fileChooser = new JFileChooser();
208: fileChooser.setDialogTitle(MailResourceLoader.getString(
209: "dialog", "account", "PGP_Binary")); //$NON-NLS-1$
210: fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
211:
212: int returnVal = fileChooser.showDialog(null,
213: MailResourceLoader.getString(
214: "dialog", "account", "Select_File")); //$NON-NLS-1$
215:
216: if (returnVal == JFileChooser.APPROVE_OPTION) {
217: File file = fileChooser.getSelectedFile();
218: pathButton.setText(file.getPath());
219: }
220: }
221: }
222:
223: public boolean isFinished() {
224: boolean result = true;
225:
226: return result;
227: }
228: }
|