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

📄 bsgroupchatplugin.java

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

/*
 * BSGroupchatPlugin.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2004
 *
 *
 * Created on 5 March 2004, 14:31
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import org.jabber.jabberbeans.util.*;

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

import edu.ou.kmi.buddyspace.plugins.*;
import edu.ou.kmi.buddyspace.plugins.groupchat.core.*;

import edu.ou.kmi.buddyspace.plugins.conference.*;
import edu.ou.kmi.buddyspace.plugins.conference.core.*;
import edu.ou.kmi.buddyspace.plugins.conference.gui.*;

/**
 * <code>BSGroupchatPlugin</code> is main class of groupchat plugin to BuddySpace.
 * It provides methods for plugin loading and user interaction.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class BSGroupchatPlugin extends BSPlugin
                          implements ActionListener {
    
    final static String DEF_CONF_SERVER              = "";
    public static final String PREF_NAME_CONF_SERVER = "confServer";
    public static String confServer                  = DEF_CONF_SERVER;
    
    private BSGroupchatBean groupchatBean;
    private BSConfWinManager confWinMan;
    private JMenuItem joinMenuItem;
    
    private JTextField confServerTextField ;
    
    /** Constructor */
    public BSGroupchatPlugin(BSMainFrame mainFrame, JTabbedPane tabbedPane, BSCore core) {
        super(mainFrame, tabbedPane, core);
    }
    
    /** Inits the plugin core */
    protected void initCore() {
        groupchatBean = new BSGroupchatBean();
    }
    
    /** Inits plugin GUI */
    protected void initGUI() {
        confWinMan = new BSConfWinManager(mainFrame, tabbedPane);
    }
    
    /** Adds GUI controls into main window */
    protected void addGUIControls() {
        joinMenuItem = new JMenuItem("Groupchat");
        joinMenuItem.addActionListener(this);
        joinMenuItem.setEnabled(false);
        mainFrame.addPluginJabberMenuItem(joinMenuItem);
    }
    
    /** Connects BuddySpace beans */
    protected void connectBeans() {
        if (core != null) {
            
            confWinMan.setRosterBean(core.getRosterBean());
            confWinMan.setPresenceBean(core.getPresenceBean());
            confWinMan.setConfBean(groupchatBean);
            
            groupchatBean.setPresenceBean(core.getPresenceBean());
            
            groupchatBean.setMessengerBean(core.getMessengerBean());
            
            BSInfoQueryBean iqBean = core.getInfoQueryBean();
            if (iqBean != null)
                groupchatBean.setIQBean(iqBean.getIQBean());
        }
    }
    
    /** Handles connection change to connected */
    public void connected() {
        super.connected();
        joinMenuItem.setEnabled(true);
    }
    
    /** Handles connection change to disconnected */
    public void disconnected() {
        confWinMan.closeAllWindows();
        groupchatBean.disconnected();
        joinMenuItem.setEnabled(false);
    }
    
    /** Handles action from GUI controls in main window */
    public void actionPerformed(ActionEvent evt) {
        if (evt.getSource() == joinMenuItem) {
            BSConfJoinDialog dlg = new BSConfJoinDialog(mainFrame, confWinMan, 
                                       confServer, mainFrame.username);
            dlg.setVisible(true);
        }
    }
    
    /** Loads preferences. */
    protected void loadPreferences() {
        String[] names = {PREF_NAME_CONF_SERVER};
        String[] defaults = {DEF_CONF_SERVER};
        Vector prefs = mainFrame.loadPreferences(names, defaults);
        if (prefs != null && prefs.size() == 1)
            confServer = (String) prefs.elementAt(0);
    }
    
    /** Returns components and their names for display in preferences dialog */
    public void getPreferencesTab(Vector components, Vector names) {
        GridBagConstraints gbc;
        
        JPanel preferencesPanel = new JPanel(new GridBagLayout());
        
        JLabel label = new JLabel("Default conferencing server:");
        gbc = new GridBagConstraints();
        gbc.gridy = 1;
        gbc.anchor = GridBagConstraints.WEST;
        preferencesPanel.add(label, gbc);
        confServerTextField = new JTextField(confServer);
        gbc = new GridBagConstraints();
        gbc.gridy = 2;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.weightx = 1;
        preferencesPanel.add(confServerTextField, gbc);
        
        components.add(preferencesPanel);
        names.add(new String("Conferencing"));
    }
    
    /** Stores preferences from preferences tab.
     */
    public boolean storePreferences() {
        confServer = confServerTextField.getText();
        String[] names = {PREF_NAME_CONF_SERVER};
        String[] values = {confServer};
        mainFrame.addAndSavePreferences(names, values);
        
        return true;
    }
    
    /** Updates LAF of all plug-ins  */
    public void updateLAF() {
        confWinMan.updateLAF();
    }
    
    
    /** Returns if there are some new messages (alerts) */
    public boolean isNewMessage() {
        return ((BSConfWinManager)confWinMan).isNewMessage();
    }
    
    
    /** 
     * Performs action within given namespace for given JID.
     * Returns if action was performed.
     */
    public boolean performAction(JID jid, String namespace) {
        if (jid != null && ("groupchat".equals(namespace) 
                         // just as substitution of old BSConfPlugin
                         || "jabber:iq:conference".equals(namespace))) {
            if (!mainFrame.isConnected()) {
                JOptionPane.showMessageDialog(mainFrame, 
                                      "Cannot start groupchat - not connected.",
                                      "Error", 
                                      JOptionPane.ERROR_MESSAGE);
                return false;
            }
            //confWinMan.joinRoom(jid.getUsername(), jid.getServer(), mainFrame.username);
            BSConfJoinDialog dlg = new BSConfJoinDialog(mainFrame, confWinMan, 
                                       jid.getServer(), mainFrame.username);
            dlg.setRoomName(jid.getUsername());
            dlg.setVisible(true);
            return true;
        }
        else
            return false;
    }
    
    
    /** Adds supported namespaces and their names */
    public void getSupportedNamespaces(Vector namespaces, Vector names) {
        namespaces.addElement(new String("groupchat"));
        names.addElement(new String("Groupchat"));
    }
    
    
    /** Opens windows specified in vector. */
    public void openTheWindows(Vector openWindows, boolean connected) { 
        if (confWinMan != null)
            confWinMan.openTheWindows(openWindows, connected);
    }
    
    
    /** Add its open windows into the vector (for opening when starting next time). */
    public void addOpenWindows(Vector openWindows, boolean connected) { 
        if (confWinMan != null)
            confWinMan.addOpenWindows(openWindows, connected);
    }
    
}

⌨️ 快捷键说明

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