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

📄 bsregdialog.java

📁 一款即时通讯软件
💻 JAVA
字号:
package edu.ou.kmi.buddyspace.gui;

/*
 * BSRegDialog.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 21 Novemebr 2002, 21:13
 */

import java.awt.*;
import javax.swing.*;
import java.beans.*; // Property change stuff
import java.util.*;

import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.util.*;

import edu.ou.kmi.buddyspace.gui.*;

/**
 * Dialog for specifying JID.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */

public class BSRegDialog extends JDialog {
    private JOptionPane optionPane;
    public Hashtable resultRegInfos = null;
    
    /** Constructor */
    BSRegDialog(Frame _parent, String title, Hashtable _regInfos) {
        super(_parent, title, true);
        
        final Frame parent = _parent;
        final Hashtable regInfos = _regInfos;
        
        Vector fields = new Vector();
        final Hashtable textFields = new Hashtable();
        
        // instructions
        JLabel label;
        label = new JLabel("Instructions:");
        fields.add(label);
        String instructionsText = (String) regInfos.get(new String("instructions"));
        if (instructionsText == null)
            instructionsText = new String("Please fill in following information");
        JTextArea instrTextArea = new JTextArea(instructionsText, 5, 25);
        instrTextArea.setBackground(getBackground());
        instrTextArea.setForeground(getForeground());
        instrTextArea.setEditable(false);
        instrTextArea.setLineWrap(true);
        instrTextArea.setWrapStyleWord(true);
        JScrollPane instrScrollPane = new JScrollPane(instrTextArea);
        fields.add(instrScrollPane);
        
        label = new JLabel(" ");
        fields.add(label);
        
        JTextField textField;
        
        String v;
        if (null != (v = (String)regInfos.get(new String("username")))) {
            label = new JLabel("username");
            fields.add(label);
            textField = new JTextField(v);
            fields.add(textField);
            textFields.put("username", textField);
        }
        if (null != (v = (String)regInfos.get(new String("password")))) {
            label = new JLabel("password");
            fields.add(label);
            textField = new JPasswordField(v);
            fields.add(textField);
            textFields.put("password", textField);
        }
        if (null != (v = (String)regInfos.get(new String("nick")))) {
            label = new JLabel("nickname");
            fields.add(label);
            textField = new JTextField(v);
            fields.add(textField);
            textFields.put("nick", textField);
        }
        if (null != (v = (String)regInfos.get(new String("nickname")))) {
            label = new JLabel("nickname");
            fields.add(label);
            textField = new JTextField(v);
            fields.add(textField);
            textFields.put("nickname", textField);
        }
        
        Enumeration keyes = regInfos.keys();
        while (keyes.hasMoreElements()) {
            String k = (String) keyes.nextElement();

            if (!k.equals("instructions") && !k.equals("key") &&
                !k.equals("registered") && !k.equals("username") &&
                !k.equals("password") && !k.equals("nick") &&
                !k.equals("nickname")) {
                    
                label = new JLabel();
                label.setText(k);
                fields.add(label);

                // *** if password use JPasswordField ***
                v = (String) regInfos.get(k);
                if (k.equals("password"))
                    textField = new JPasswordField();
                else 
                    textField = new JTextField();
                if (v != null) textField.setText(v);
                fields.add(textField);
                
                textFields.put(k, textField);
            }
        }
        
        label = new JLabel(" ");
        fields.add(label);
        
        /*final JCheckBox removeRegCheckBox;
        if (regInfos.keySet().contains(new String("registered"))) {
            removeRegCheckBox = new JCheckBox("Delete registration", true);
            fields.add(removeRegCheckBox);
        }
        else
            removeRegCheckBox = null;*/
        final JRadioButton removeButton;
        final JRadioButton reRegButton;
        if (regInfos.keySet().contains(new String("registered"))) {
            removeButton = new JRadioButton("Un-register from this service", true);
            reRegButton = new JRadioButton("Re-register for this service", false);
            ButtonGroup group = new ButtonGroup();
            group.add(removeButton);
            group.add(reRegButton);
            fields.add(removeButton);
            fields.add(reRegButton);
        }
        else {
            reRegButton = null;
            removeButton = null;
        }
        
        final String okButton = "OK";
        final String cancelButton = "Cancel";
        Object[] options = {okButton, cancelButton};

        optionPane = new JOptionPane(fields.toArray(), 
                                     JOptionPane.PLAIN_MESSAGE,
                                     JOptionPane.OK_CANCEL_OPTION,
                                     null,
                                     options,
                                     options[0]);
        setContentPane(optionPane);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        pack();
        setLocationRelativeTo(parent);
        
        // handles actions
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();
			
                if (isVisible() 
                    && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
                      prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if (value.equals(okButton)) {
                        resultRegInfos = (Hashtable) regInfos.clone();
                        
                        Enumeration keyes = resultRegInfos.keys();
                        while (keyes.hasMoreElements()) {
                            String k = (String) keyes.nextElement();

                            if (!k.equals("instructions") && !k.equals("key") &&
                                !k.equals("registered")) {

                                JTextField textField = (JTextField) textFields.get(k);
                                if (textField != null)
                                    resultRegInfos.put(k, textField.getText());
                            }
                        }
                        
                        // delete registration check box
                        /*if (removeRegCheckBox != null && removeRegCheckBox.isSelected())
                            resultRegInfos.put(new String("remove"), new String(""));*/
                        if (removeButton != null && removeButton.isSelected())
                            resultRegInfos.put(new String("remove"), new String(""));
                        
                        setVisible(false);
                    }
                    else if (value.equals(cancelButton)) {
                        //jid = null;
                        setVisible(false);
                    }
                }
            }
        });
    }
}

⌨️ 快捷键说明

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