📄 bsbrowseplugin.java
字号:
package edu.ou.kmi.buddyspace.plugins.browse;
/*
* BSBrowsePlugin.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2002
*
*
* Created on 19 November 2002, 9:24
*/
import java.util.*;
import javax.swing.*;
//import java.awt.*;
import java.awt.event.*;
import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.util.*;
import org.jabber.jabberbeans.Extension.*;
import edu.ou.kmi.buddyspace.core.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.plugins.*;
import edu.ou.kmi.buddyspace.plugins.browse.core.*;
import edu.ou.kmi.buddyspace.plugins.browse.gui.*;
/**
* <code>BSBrowsePlugin</code> is main class of browsing plugin to BuddySpace.
* It provides methods for plugin loading and user interaction.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSBrowsePlugin extends BSPlugin
implements ActionListener, BrowseListener {
private BSBrowseBean browseBean;
private BSBrowseWinManager browseWinMan;
private JMenu browseMenu;
private PacketID servedID = new PacketID(null);
private boolean initialRequest = false;
private BrowseItem agents = null;
/** Constructor */
public BSBrowsePlugin(BSMainFrame mainFrame, JTabbedPane tabbedPane, BSCore core) {
super(mainFrame, tabbedPane, core);
}
/** Inits the plugin core */
protected void initCore() {
browseBean = new BSBrowseBean();
}
/** Inits plugin GUI */
protected void initGUI() {
browseWinMan = new BSBrowseWinManager(mainFrame, tabbedPane);
}
/** Adds GUI controls into main window */
protected void addGUIControls() {
browseMenu = new JMenu("Browse services");
browseMenu.setEnabled(false);
mainFrame.addPluginJabberMenuItem(browseMenu);
}
/** Connects BuddySpace beans */
protected void connectBeans() {
if (core != null) {
browseWinMan.setBrowseBean(browseBean);
BSConnectionBean connBean = core.getConnectionBean();
if (connBean != null)
browseBean.setConnection(connBean.getConnection());
}
}
/** Handles connection change to connected */
public void connected() {
super.connected();
initMenu();
browseMenu.setEnabled(true);
BSConnectionBean connBean = core.getConnectionBean();
if (connBean != null)
browseBean.setConnection(connBean.getConnection());
browseBean.addBrowseListener(this);
initialRequest = true;
JID serverJID = new JID(null, mainFrame.server, null);
browseBean.browseTo(serverJID.toString(), servedID, false);
}
/** Handles connection change to disconnected */
public void disconnected() {
browseBean.setConnection(null);
browseBean.removeBrowseListener(this);
browseWinMan.closeAllWindows();
browseBean.disconnected();
browseMenu.setEnabled(false);
browseMenu.removeAll();
}
/** Handles action from GUI controls in main window */
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof BSJIDActionMenuItem) {
BSJIDActionMenuItem mi = (BSJIDActionMenuItem)evt.getSource();
if (mi.getNamespace() != null &&
mi.getNamespace().equals("jabber:iq:browse")) {
JID jid = mi.getJID();
browseWinMan.openNewWindow((jid != null)? jid.toString() : null);
}
else {
mainFrame.performAction(mi.getJID(), mi.getNamespace());
}
}
}
/**
* If namespace is <code>jabber:iq:browse</code>
* browses given JID and returns true otherwise returns false.
*/
public boolean performAction(JID jid, String namespace) {
if (namespace != null && namespace.equals("jabber:iq:browse")) {
if (!mainFrame.isConnected()) {
JOptionPane.showMessageDialog(mainFrame,
"Cannot browse - not connected.",
"Error",
JOptionPane.ERROR_MESSAGE);
return false;
}
browseWinMan.openNewWindow((jid != null)? jid.toString() : null);
return true;
}
else
return false;
}
/** Adds supported namespaces and their names */
public void getSupportedNamespaces(Vector namespaces, Vector names) {
namespaces.addElement(new String("jabber:iq:browse"));
names.addElement(new String("Jabber browse"));
}
/** Handles received error while browsing */
public void error(InfoQuery iq, String id) {
if (id == null && !id.equals(servedID.getID())) return;
servedID.setID(null);
browseBean.removeBrowseListener(this);
String errCode = iq.getErrorCode();
String errMsg = iq.getErrorText();
if (initialRequest)
initialRequest = false;
else {
JOptionPane.showMessageDialog(mainFrame,
"Error " + errCode + ": " + errMsg + "!",
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
/** Handles received data while browsing */
public void received(BrowseItem browseItem, String id) {
if (id == null && !id.equals(servedID.getID())) return;
if (initialRequest) {
initialRequest = false;
servedID.setID(null);
browseBean.removeBrowseListener(this);
agents = browseItem;
initMenu();
}
}
/** Inits browse menu for BSMainFrame.
* The menu includes <code>agents</code> and register shortcuts.
*/
protected void initMenu() {
BSJIDActionMenuItem menuItem;
browseMenu.removeAll();
JID serverJID = new JID(null, mainFrame.server, null);
menuItem = new BSJIDActionMenuItem("Home server", serverJID,
"jabber:iq:browse");
menuItem.addActionListener(this);
browseMenu.add(menuItem);
browseMenu.addSeparator();
if (agents != null) {
Enumeration agentsEnum = agents.children();
while (agentsEnum.hasMoreElements()) {
BrowseItem bi = (BrowseItem) agentsEnum.nextElement();
/*menuItem = new BSJIDActionMenuItem(bi.getName(), bi.getJID(),
"jabber:iq:browse");
browseMenu.add(menuItem);
menuItem.addActionListener(this);*/
JMenu subMenu = new JMenu(bi.getName());
browseMenu.add(subMenu);
// adds the browse menu item
menuItem = new BSJIDActionMenuItem("Browse", bi.getJID(),
"jabber:iq:browse");
subMenu.add(menuItem);
menuItem.addActionListener(this);
// if jabber:iq:register namespace supported, adds register menu item
Enumeration namespaces = bi.namespaces();
while (namespaces.hasMoreElements()) {
String ns = (String)namespaces.nextElement();
if (ns != null && ns.equals("jabber:iq:register")) {
menuItem = new BSJIDActionMenuItem("Register", bi.getJID(),
"jabber:iq:register");
subMenu.add(menuItem);
menuItem.addActionListener(this);
break;
}
}
}
}
browseMenu.addSeparator();
menuItem = new BSJIDActionMenuItem("Custom...", null, "jabber:iq:browse");
menuItem.addActionListener(this);
browseMenu.add(menuItem);
}
/** Loads preferences. Empty implementation. */
protected void loadPreferences() {}
/** Returns components and their names for display in preferences dialog.
* Empty implementation - returns null.
*/
public void getPreferencesTab(Vector components, Vector names) {}
/** Stores preferences from preferences tab.
* Empty implementation.
*/
public boolean storePreferences() {
return true;
}
/** Updates LAF of all plug-ins */
public void updateLAF() {
browseWinMan.updateLAF();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -