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

📄 bschoosegroupdialog.java

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

/*
 * BSChooseGroupDialog.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 15 November 2002, 13:19
 */

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 BSChooseGroupDialog extends JDialog {
    private JOptionPane optionPane;
    public String group = null;
    public boolean onlyOnline = false;
    
    /** Constructor */
    BSChooseGroupDialog(Frame _parent, String title, Iterator rosterGroups) {
        this(_parent, title, rosterGroups, false, false);
    }
    
    /** Constructor */
    BSChooseGroupDialog(Frame _parent, String title, Iterator rosterGroups, boolean onlyOnline) {
        this(_parent, title, rosterGroups, true, onlyOnline);
    }
        
    /** Constructor */
    BSChooseGroupDialog(Frame _parent, String title, Iterator rosterGroups, 
                        boolean _showOnlyOnlineCheckBox, boolean onlyOnline) {
        super(_parent, title, true);
        
        final Frame parent = _parent;
        final boolean showOnlyOnlineCheckBox = _showOnlyOnlineCheckBox;
        this.onlyOnline = onlyOnline;
        
        // fills groups hashtable
        final JComboBox groupComboBox = new JComboBox();
        Iterator groups = rosterGroups;
        TreeSet tmpSet = new TreeSet();
        while(groups.hasNext()) {
            String groupName = (String) groups.next();
            //groupComboBox.addItem(groupName);
            tmpSet.add(groupName);
        }
        // fills sorted groups combo box
        while (!tmpSet.isEmpty()) {
            Object o = tmpSet.first();
            groupComboBox.addItem(o);
            tmpSet.remove(o);
        }
        groupComboBox.setEditable(false);

        Vector fieldsVector = new Vector();
        fieldsVector.add("Group: ");
        fieldsVector.add(groupComboBox);
        
        final JCheckBox onlyOnlineCheckBox = new JCheckBox("Only online people", onlyOnline);
        if (showOnlyOnlineCheckBox)
            fieldsVector.add(onlyOnlineCheckBox);
        
        /*Object[] fields = {"Group: ", groupComboBox};
                           //, "Jen tak: ", jenTak};*/
        
        final String okButton = "OK";
        final String cancelButton = "Cancel";
        Object[] options = {okButton, cancelButton};

        optionPane = new JOptionPane(fieldsVector.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)) {
                        group = (String) groupComboBox.getSelectedItem();
                        if (group == null || group.equals("")) {
                            JOptionPane.showMessageDialog(parent, "Invalid JID", 
                                                          "Error", 
                                                          JOptionPane.ERROR_MESSAGE);
                            group = null;
                            return;
                        }
                        if (showOnlyOnlineCheckBox)
                            BSChooseGroupDialog.this.onlyOnline = onlyOnlineCheckBox.isSelected();
                        else BSChooseGroupDialog.this.onlyOnline = false;
                        setVisible(false);
                    }
                    else if (value.equals(cancelButton)) {
                        group = null;
                        setVisible(false);
                    }
                }
            }
        });
    }
}

⌨️ 快捷键说明

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