⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profileeditordialog.java

📁 网站即时通讯系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  Copyright (C) 2003 Adam Olsen *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 1, or (at your option) *  any later version. *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother;import java.awt.BorderLayout;import java.awt.GridBagConstraints;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.util.Hashtable;import java.util.Iterator;import java.util.Locale;import java.util.ResourceBundle;import javax.swing.*;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import com.valhalla.gui.MJTextField;import com.valhalla.gui.Standard;import com.valhalla.jbother.jabber.BuddyStatus;import com.valhalla.misc.GnuPG;import com.valhalla.misc.SimpleXOR;import com.valhalla.settings.Settings;import com.valhalla.settings.SettingsProperties;/** * Allows a user to edit a profile * * @author synic * @author Andrey Zakirov * @created April 10, 2004 */public class ProfileEditorDialog extends JDialog {    private ResourceBundle resources = ResourceBundle.getBundle(            "JBotherBundle", Locale.getDefault());    private JPanel main;    private JTabbedPane pane = new JTabbedPane();    private MJTextField nameField = new MJTextField();    private MJTextField usernameField = new MJTextField(20);    private MJTextField serverField = new MJTextField(25);    private MJTextField resourceField = new MJTextField(20);    private MJTextField portField = new MJTextField(5);    private JPasswordField passwordField = new JPasswordField(20);    private JCheckBox savePassword = new JCheckBox();    private JCheckBox sslBox = new JCheckBox();    private SettingsProperties settings = new SettingsProperties();    private JCheckBox autoLoginBox = new JCheckBox();    private JCheckBox defaultBox = new JCheckBox();    private JCheckBox reconnectBox = new JCheckBox();    private JButton createButton = new JButton(resources            .getString("createAccountButton"));    private JButton saveButton = new JButton(resources.getString("saveButton"));    private JButton cancelButton = new JButton(resources            .getString("cancelButton"));    private ProfileEditorDialog thisPointer = this;    private File profDir = new File(JBother.settingsDir, "profiles");    private JPanel innerPanel = new JPanel();    private String origProf = null;    private ProfileManager dialog = null;    private boolean exitOnClose = false;    private boolean isCurrentProfile = false;    private JButton gnupgusenoneButton = new JButton(resources            .getString("gnupgUseNone"));    private JButton gnupgselectButton = new JButton(resources            .getString("gnupgSelectKey"));    private JLabel keyinfoLabel = new JLabel(resources            .getString("gnupgNoKeySelected"));    private String gnupgSecretKeyID = null;    private JCheckBox savepassphraseCheck = new JCheckBox();    private JPasswordField gnupgpasswordField = new JPasswordField(15);    private JCheckBox gnupgSignPresenceCheck = new JCheckBox();    private String[] gnupgSecurityVariants = { "Sign and Encrypt",            "Encrypt Only", "Sign Only" };    private JComboBox gnupgSecurityVariantBox = new JComboBox(            gnupgSecurityVariants);    private String tempgnupgSecretKeyID = "";    private JFrame parent;    /**     * Contructs the ProfileEditorDialog     *     * @param dialog     *            the ProfileManager dialog that's calling this editor, or     *            <tt>null</tt> if nothing is calling it     * @param profile     *            the profile to edit, or <tt>null</tt> if it's a new profile     */    public ProfileEditorDialog(JFrame parent,ProfileManager dialog, String profile) {        super(parent, "", true);        this.parent = parent;        this.dialog = dialog;        setModal(false);        setTitle(resources.getString("profileEditor"));        origProf = profile;        main = (JPanel) getContentPane();        main.setLayout(new BorderLayout());        main.setBorder(BorderFactory.createTitledBorder(resources                .getString("profileEditor")));        main.add(pane, BorderLayout.CENTER);        pane.addChangeListener(new ChangeListener() {            public void stateChanged(ChangeEvent e) {                if (pane.getSelectedIndex() == 2) {                    if (!JBotherLoader.isGPGEnabled()) {                        if (Settings.getInstance().getProperty(                                "gnupgSecretKeyID") != null) {                            int result = JOptionPane                                    .showConfirmDialog(                                            thisPointer,                                            "Warning: There is a GnuPG secrety key ID in your profile,\nbut it appears as though GnuPG is not installed on this system.\nWould you like to remove the ID from your profile?",                                            "GnuPG", JOptionPane.YES_NO_OPTION);                            if (result == JOptionPane.YES_OPTION) {                                Settings.getInstance().remove(                                        "gnupgSecretKeyID");                                Settings.getInstance()                                        .remove("gnupgPassPhrase");                                Settings.getInstance().remove(                                        "gnupgSavePassphrase");                            }                        }                        Standard                                .warningMessage(thisPointer, "GnuPG Error",                                        "GnuPG is not executable or sends unknown response.  GnuPG is disabled");                        pane.setSelectedIndex(0);                    }                }            }        });        pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));        JPanel topPanel = new JPanel();        topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));        JPanel namePanel = new JPanel();        namePanel.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));        namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.X_AXIS));        namePanel.add(new JLabel(resources.getString("profileName") + ": "));        namePanel.add(nameField);        topPanel.add(namePanel);        JPanel defaultPanel = new JPanel();        defaultPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));        defaultPanel.setLayout(new BoxLayout(defaultPanel, BoxLayout.X_AXIS));        defaultPanel                .add(new JLabel(resources.getString("setAsDefault") + ": "));        defaultPanel.add(defaultBox);        defaultPanel.add(Box.createHorizontalGlue());        topPanel.add(defaultPanel);        main.add(topPanel, BorderLayout.NORTH);        createAccountPanel();        createOptionsPanel();        createGnuPGPanel();        JPanel buttonPanel = new JPanel();        buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));        buttonPanel.add(Box.createHorizontalGlue());        buttonPanel.add(cancelButton);        buttonPanel.add(saveButton);        main.add(buttonPanel, BorderLayout.SOUTH);        addListeners();        loadProfile(profile);        pack();        setLocationRelativeTo(null);        addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent e) {                cancelHandler();            }        });    }    protected JFrame getDialogParent() { return parent; }    /**     * Sets whether or not this dialog should exit the application when it's     * cancel button has been pressed     *     * @param e     *            true to close the app     */    protected void setExitOnClose(boolean e) {        this.exitOnClose = true;    }    /**     * Sets the isCurrentProfile attribute of the ProfileEditorDialog object     *     * @param i     *            The new isCurrentProfile value     */    public void setIsCurrentProfile(boolean i) {        this.isCurrentProfile = i;    }    /**     * @return the defaultBox     */    protected JCheckBox getDefaultBox() {        return defaultBox;    }    /**     * Adds the event listeners to the buttons     */    private void addListeners() {        PEDialogListener listener = new PEDialogListener();        createButton.addActionListener(listener);        saveButton.addActionListener(listener);        cancelButton.addActionListener(listener);        gnupgusenoneButton.addActionListener(listener);        gnupgselectButton.addActionListener(listener);    }    /**     * Handles events     *     * @author synic     * @created November 30, 2004     */    class PEDialogListener implements ActionListener {        /**         * Description of the Method         *         * @param e         *            Description of the Parameter         */        public void actionPerformed(ActionEvent e) {            if (e.getSource() == createButton) {                createAccountHandler();            } else if (e.getSource() == saveButton) {                saveHandler();            } else if (e.getSource() == cancelButton) {                cancelHandler();            } else if (e.getSource() == gnupgusenoneButton) {                gnupgusenoneHandler();            } else if (e.getSource() == gnupgselectButton) {                gnupgselectHandler();            }        }    }    /**     * Cancels the dialog, and quits if exitOnClose is set to true     */    private void cancelHandler() {        dispose();        if (exitOnClose) {            System.exit(0);        }    }    /**     * Description of the Method     */    private void gnupgusenoneHandler() {        keyinfoLabel.setText(resources.getString("gnupgNoKeySelected"));        settings.remove("gnupgPassPhrase");        this.gnupgSecretKeyID = null;        savepassphraseCheck.setSelected(false);        savepassphraseCheck.setEnabled(false);        gnupgpasswordField.setText("");        gnupgpasswordField.setEnabled(false);        gnupgusenoneButton.setEnabled(false);        gnupgSignPresenceCheck.setSelected(false);        gnupgSignPresenceCheck.setEnabled(false);        gnupgSecurityVariantBox.setEnabled(false);        BuddyList.getInstance().setGnuPGPassword(null);        if (BuddyList.getInstance().checkConnection()) {            settings.setProperty("gnupgPassPhrase", null);        }    }    /**     * Description of the Method     */    private void gnupgselectHandler() {        KeySelectDialog dialog = new KeySelectDialog((JDialog) thisPointer,                "sec");        dialog.showDialog();        if ((dialog.getName() != null) && (dialog.getID() != null)) {            keyinfoLabel.setText(dialog.getName());            this.gnupgSecretKeyID = dialog.getID();            savepassphraseCheck.setEnabled(true);            gnupgpasswordField.setText("");            gnupgpasswordField.setEnabled(savepassphraseCheck.isSelected());            gnupgusenoneButton.setEnabled(true);            gnupgSignPresenceCheck.setSelected(true);            gnupgSignPresenceCheck.setEnabled(true);            gnupgSecurityVariantBox.setEnabled(true);        }    }    /**     * Saves the currently opened profile     */    private void saveHandler() {        try {            Standard.setBundle(resources);            Standard.assure(nameField.getText(), "Profile Name");            Standard.assure(usernameField.getText(), "Username");            if (savePassword.isSelected()) {                Standard.assure(new String(passwordField.getPassword()),                        "Password");            }            Standard.assure(resourceField.getText(), "Resource");            Standard.assure(serverField.getText(), "Server");        } catch (Exception e) {            com.valhalla.Logger.logException(e);            return;        }        settings.setProperty("username", usernameField.getText());        if (savePassword.isSelected()) {            settings.setProperty("password", SimpleXOR.encrypt(new String(                    passwordField.getPassword()), "JBother rules!"));        } else            settings.remove("password");        settings.setProperty("resource", resourceField.getText());        settings.setProperty("defaultServer", serverField.getText());        settings.setProperty("port", portField.getText());        settings.setBoolean("useSSL", sslBox.isSelected());        settings.setBoolean("autoLogin", autoLoginBox.isSelected());        settings.setBoolean("reconnectOnDisconnect", reconnectBox.isSelected());        if (gnupgSecretKeyID != null) {            String gnupgTempPass = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -