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: package org.columba.mail.gui.util;
017:
018: import java.awt.BorderLayout;
019: import java.awt.GridBagConstraints;
020: import java.awt.GridBagLayout;
021: import java.awt.GridLayout;
022: import java.awt.Insets;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.awt.event.KeyEvent;
026: import java.text.MessageFormat;
027:
028: import javax.swing.BorderFactory;
029: import javax.swing.JButton;
030: import javax.swing.JCheckBox;
031: import javax.swing.JComponent;
032: import javax.swing.JDialog;
033: import javax.swing.JLabel;
034: import javax.swing.JPanel;
035: import javax.swing.JPasswordField;
036: import javax.swing.KeyStroke;
037:
038: import org.columba.core.gui.base.ButtonWithMnemonic;
039: import org.columba.core.gui.frame.FrameManager;
040: import org.columba.core.resourceloader.ImageLoader;
041: import org.columba.mail.util.MailResourceLoader;
042:
043: public class PGPPassphraseDialog implements ActionListener {
044: private char[] password;
045:
046: // private JFrame frame;
047: private JDialog dialog;
048:
049: private boolean bool = false;
050:
051: private JPasswordField passwordField;
052:
053: // private JTextField loginTextField;
054: private JCheckBox checkbox;
055:
056: private boolean save;
057:
058: private JButton okButton;
059:
060: private JButton cancelButton;
061:
062: private JButton helpButton;
063:
064: // private JComboBox loginMethodComboBox;
065: // String loginMethod;
066: public PGPPassphraseDialog() {
067: }
068:
069: protected JPanel createButtonPanel() {
070: JPanel bottom = new JPanel();
071: bottom.setLayout(new BorderLayout());
072:
073: // bottom.setLayout( new BoxLayout( bottom, BoxLayout.X_AXIS ) );
074: bottom.setBorder(BorderFactory
075: .createEmptyBorder(17, 12, 11, 11));
076:
077: // bottom.add( Box.createHorizontalStrut());
078: cancelButton = new ButtonWithMnemonic(MailResourceLoader
079: .getString("global", "cancel"));
080:
081: //$NON-NLS-1$ //$NON-NLS-2$
082: cancelButton.addActionListener(this );
083: cancelButton.setActionCommand("CANCEL"); //$NON-NLS-1$
084:
085: okButton = new ButtonWithMnemonic(MailResourceLoader.getString(
086: "global", "ok"));
087:
088: //$NON-NLS-1$ //$NON-NLS-2$
089: okButton.addActionListener(this );
090: okButton.setActionCommand("OK"); //$NON-NLS-1$
091: okButton.setDefaultCapable(true);
092: dialog.getRootPane().setDefaultButton(okButton);
093:
094: helpButton = new ButtonWithMnemonic(MailResourceLoader
095: .getString("global", "help"));
096:
097: //$NON-NLS-1$ //$NON-NLS-2$
098: JPanel buttonPanel = new JPanel();
099: buttonPanel.setLayout(new GridLayout(1, 3, 5, 0));
100: buttonPanel.add(okButton);
101: buttonPanel.add(cancelButton);
102: buttonPanel.add(helpButton);
103:
104: // bottom.add( Box.createHorizontalGlue() );
105: bottom.add(buttonPanel, BorderLayout.EAST);
106:
107: return bottom;
108: }
109:
110: public void showDialog(String userID, String password, boolean save) {
111:
112: // JButton[] buttons = new JButton[2];
113: JLabel hostLabel = new JLabel(MessageFormat.format(
114: MailResourceLoader.getString("dialog", "password",
115: "enter_passphrase"), new Object[] { userID }));
116:
117: passwordField = new JPasswordField(password, 40);
118:
119: checkbox = new JCheckBox(MailResourceLoader.getString("dialog",
120: "password", "save_passphrase"));
121: checkbox.setSelected(save);
122:
123: dialog = new JDialog(FrameManager.getInstance()
124: .getActiveFrame(), true);
125: dialog.setTitle(MailResourceLoader.getString("dialog",
126: "password", "dialog_title_passphrase"));
127:
128: JPanel centerPanel = new JPanel();
129: centerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5,
130: 5));
131:
132: dialog.getContentPane().add(centerPanel, BorderLayout.CENTER);
133:
134: GridBagLayout mainLayout = new GridBagLayout();
135: centerPanel.setLayout(mainLayout);
136:
137: GridBagConstraints mainConstraints = new GridBagConstraints();
138:
139: JLabel iconLabel = new JLabel(ImageLoader
140: .getMiscIcon("signature-nokey.png"));
141: mainConstraints.anchor = GridBagConstraints.NORTHWEST;
142: mainConstraints.weightx = 1.0;
143: mainConstraints.gridwidth = GridBagConstraints.RELATIVE;
144: mainConstraints.fill = GridBagConstraints.HORIZONTAL;
145: mainLayout.setConstraints(iconLabel, mainConstraints);
146: centerPanel.add(iconLabel);
147:
148: mainConstraints.gridwidth = GridBagConstraints.REMAINDER;
149: mainConstraints.anchor = GridBagConstraints.WEST;
150: mainConstraints.insets = new Insets(0, 5, 0, 0);
151: mainLayout.setConstraints(hostLabel, mainConstraints);
152: centerPanel.add(hostLabel);
153:
154: mainConstraints.insets = new Insets(5, 5, 0, 0);
155: mainLayout.setConstraints(passwordField, mainConstraints);
156: centerPanel.add(passwordField);
157:
158: mainConstraints.insets = new Insets(5, 5, 0, 0);
159: mainLayout.setConstraints(checkbox, mainConstraints);
160: centerPanel.add(checkbox);
161:
162: JPanel bottomPanel = new JPanel();
163: bottomPanel.setLayout(new BorderLayout());
164:
165: JPanel buttonPanel = createButtonPanel();
166: bottomPanel.add(buttonPanel, BorderLayout.CENTER);
167:
168: dialog.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
169: dialog.getRootPane().setDefaultButton(okButton);
170: dialog.getRootPane().registerKeyboardAction(this , "CANCEL",
171: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
172: JComponent.WHEN_IN_FOCUSED_WINDOW);
173: dialog.pack();
174: dialog.setLocationRelativeTo(null);
175: dialog.setVisible(true);
176: dialog.requestFocus();
177: passwordField.requestFocus();
178: }
179:
180: public char[] getPassword() {
181: return password;
182: }
183:
184: public boolean success() {
185: return bool;
186: }
187:
188: public boolean getSave() {
189: return save;
190: }
191:
192: public void actionPerformed(ActionEvent e) {
193: String action = e.getActionCommand();
194:
195: if (action.equals("OK")) {
196: password = passwordField.getPassword();
197:
198: // user = loginTextField.getText();
199: save = checkbox.isSelected();
200:
201: // loginMethod = (String) loginMethodComboBox.getSelectedItem();
202: bool = true;
203: dialog.dispose();
204: } else if (action.equals("CANCEL")) {
205: bool = false;
206: dialog.dispose();
207: }
208: }
209: }
|