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

📄 bsconfjoindialog.java

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

/*
 * BSConfJoinDialog.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 17 September 2002, 09:24
 */

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.*;
import edu.ou.kmi.buddyspace.core.*;

/**
 * <code>BSConfJoinDialog</code> allows input of parameters for conference join.
 * It calls <code>BSConfWinManager</code> to join desired conference room.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */

public class BSConfJoinDialog extends JDialog {
    private JOptionPane optionPane;
    private JTextField roomTextField;
    
    /** Constructor */
    public BSConfJoinDialog(Frame _parent, BSConfWinManager _winMan, 
                     String confServer, String nick) {
                         
        this(_parent, _winMan, confServer, "", nick, false);
    }
    
    
    /** Constructor */
    public BSConfJoinDialog(Frame _parent, BSConfWinManager _winMan, 
                     String confServer, String roomName, String nick,
                     boolean onlyNickEditable) {
                         
        super(_parent, "Join conference", true);
        
        final Frame parent = _parent;
        final BSConfWinManager winMan = _winMan;
        
        roomTextField = new JTextField(roomName);
        final JTextField serverTextField = new JTextField(confServer);
        final JTextField nickTextField = new JTextField(nick);
        if (onlyNickEditable) {
            serverTextField.setEditable(false);
            roomTextField.setEditable(false);
        }
        
        Object[] fields = {"You can create a new group chat 'room'\n" +
                           "or join an existing one, if you know its name.",
                           " ",
                           "Room name: ", roomTextField,
                           "Conference server: ", serverTextField,
                           "Nickname: ", nickTextField};
        
        final String okButton = "OK";
        final String cancelButton = "Cancel";
        Object[] options = {okButton, cancelButton};

        optionPane = new JOptionPane(fields, 
                                     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)) {
                        if (winMan == null) {
                            JOptionPane.showMessageDialog(parent, 
                                          "Cannot use conferencing",
                                          "Error", 
                                          JOptionPane.ERROR_MESSAGE);
                            setVisible(false);
                            return;
                        }
                        String nick = nickTextField.getText();
                        String server = serverTextField.getText();
                        String roomName = roomTextField.getText();
                        if (nick == null || nick.equals("") || 
                            server == null || server.equals("") || 
                            roomName == null || roomName.equals("")) {
                            JOptionPane.showMessageDialog(parent, 
                                          "Invalid nickname, server or room name",
                                          "Error", 
                                          JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                        roomName = processRoomName(roomName);
                        //if (nick.equals("") || server.equals("") || roomName.equals(""))
                        winMan.joinRoom(roomName, server, nick);
                        setVisible(false);
                    }
                    else if (value.equals(cancelButton)) {
                        setVisible(false);
                    }
                }
            }
        });
    }
    
    
    /** Returns processed (hopefully) legal room name */
    private String processRoomName(String roomName) {
        roomName = roomName.replace(' ', '_');
        roomName = roomName.replace('@', '%');
        return roomName;
    }
    
    /** Sets the room name */
    public void setRoomName(String roomName) {
        if (roomName != null)
            roomTextField.setText(roomName);
    }
}

⌨️ 快捷键说明

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