📄 bspubsubwindow.java
字号:
package edu.ou.kmi.buddyspace.plugins.pubsub.gui;
/*
* BSPubsubWindow.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2003
*
*
* Created on 17 October 2003, 9:52
*/
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.net.*;
import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.Extension.*;
import org.jabber.jabberbeans.util.*;
import org.jabber.jabberbeans.sax.Extension.*;
import edu.ou.kmi.buddyspace.core.*;
import edu.ou.kmi.buddyspace.xml.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.utils.*;
import edu.ou.kmi.buddyspace.plugins.pubsub.core.*;
import edu.ou.kmi.buddyspace.plugins.pubsub.xml.*;
/**
* <code>BSPubsubWindow</code> is the pubsub GUI.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSPubsubWindow extends DockableWindow
implements ActionListener, BSPubsubListener,
MouseListener, HyperlinkListener,
KeyListener {
private BSPubsubBean pubsubBean = null;
private String jidStr;
private String nodeStr;
private PacketID servedID = new PacketID(null);
//private Vector history = new Vector();
//private int currHistoryNum = -1;
private JPanel mainPanel;
JPanel buttonPanel;
JTextField progressInfo;
JButton closeButton;
JButton dockButton;
JButton bookmarkButton;
JPanel centralPanel;
JScrollPane outputScrollPane;
JScrollPane inputScrollPane;
JTextArea outputTextArea;
JTextArea inputTextArea;
JTextField addressTextField;
JTextField nodeTextField;
JSplitPane mainSplitPane;
JPanel addressPanel;
JButton getItemsButton;
JButton publishItemButton;
JButton deleteItemButton;
JButton purgeItemsButton;
JButton subscribeButton;
JButton unsubscribeButton;
JButton getSubscrOptionButton;
JButton getAffiliationsButton;
JButton createNodeButton;
JButton deleteNodeButton;
JButton pendingSubscrButton;
JButton configureNodeButton;
JButton getEntitiesButton;
JButton setEntitiesButton;
/** Constructor */
BSPubsubWindow(Window parent, BSPubsubWinManager winMan, String ID,
String title, String jidStr, String nodeStr, Image icon,
BSPubsubBean pubsubBean, boolean docked) {
super(ID, title, icon, new Dimension(450, 400), docked, winMan);
this.jidStr = jidStr;
this.nodeStr = nodeStr;
this.pubsubBean = pubsubBean;
if (pubsubBean != null)
pubsubBean.addPubsubListener(this);
initComponents();
if (pubsubBean != null && jidStr != null)
;//discover(jidStr, nodeStr);
}
/** Inits GUI components */
private void initComponents() {
mainPanel = new JPanel(new BorderLayout());
//*** button panel ***
buttonPanel = new JPanel();
progressInfo = new JTextField("", 20);
progressInfo.setEditable(false);
buttonPanel.add(progressInfo);
closeButton = new JButton();
closeButton.setText("Close");
closeButton.addActionListener(this);
buttonPanel.add(closeButton);
JPanel checkBoxesPanel = new JPanel();
Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
"images/dock.gif" : "images/float.gif"));
dockButton = new JButton(icon);
dockButton.setToolTipText(docked? "Float" : "Dock");
dockButton.addActionListener(this);
checkBoxesPanel.add(dockButton);
if (!OSVersion.isJava1Point4orHigher())
dockButton.setEnabled(false);
icon = new ImageIcon(ClassLoader.getSystemResource("images/bookmark.gif"));
bookmarkButton = new JButton(icon);
bookmarkButton.setToolTipText("Add bookmark");
bookmarkButton.addActionListener(this);
checkBoxesPanel.add(bookmarkButton);
outputTextArea = new JTextArea();
outputTextArea.setEditable(false);
outputTextArea.setWrapStyleWord(true);
outputTextArea.setLineWrap(true);
outputScrollPane = new JScrollPane(outputTextArea);
outputScrollPane.setBorder(new TitledBorder("Request output"));
inputTextArea = new JTextArea();
inputTextArea.setEditable(true);
inputTextArea.setWrapStyleWord(true);
inputTextArea.setLineWrap(true);
inputScrollPane = new JScrollPane(inputTextArea);
inputScrollPane.setBorder(new TitledBorder("Enter request parameter"));
GridBagConstraints gbc;
addressPanel = new JPanel(new GridBagLayout());
// jid
JLabel addressLabel = new JLabel("JID:");
gbc = new GridBagConstraints();
gbc.gridx = 0; gbc.gridy = 0;
addressPanel.add(addressLabel, gbc);
addressTextField = new JTextField();
addressTextField.addKeyListener(this);
gbc = new GridBagConstraints();
gbc.gridx = 1; gbc.gridy = 0; gbc.weightx = 0.5;
gbc.fill = GridBagConstraints.HORIZONTAL;
addressPanel.add(addressTextField, gbc);
// node
JLabel nodeLabel = new JLabel("Node:");
gbc = new GridBagConstraints();
gbc.gridx = 0; gbc.gridy = 1;
addressPanel.add(nodeLabel, gbc);
nodeTextField = new JTextField();
nodeTextField.addKeyListener(this);
gbc = new GridBagConstraints();
gbc.gridx = 1; gbc.gridy = 1; gbc.weightx = 0.5;
gbc.fill = GridBagConstraints.HORIZONTAL;
addressPanel.add(nodeTextField, gbc);
// buttons
JPanel actionButtonPanel = new JPanel();
actionButtonPanel.setLayout(new BoxLayout(actionButtonPanel, BoxLayout.Y_AXIS));
// getItemsButton;
getItemsButton = new JButton("Get items in node");
getItemsButton.addActionListener(this);
actionButtonPanel.add(getItemsButton);
// publishItemButton;
publishItemButton = new JButton("Publish item");
publishItemButton.addActionListener(this);
actionButtonPanel.add(publishItemButton);
// deleteItemButton;
deleteItemButton = new JButton("Delete item");
deleteItemButton.addActionListener(this);
actionButtonPanel.add(deleteItemButton);
// purgeItemsButton;
purgeItemsButton = new JButton("Purge items in node");
purgeItemsButton.addActionListener(this);
actionButtonPanel.add(purgeItemsButton);
// subscribeButton;
subscribeButton = new JButton("Subscribe to node");
subscribeButton.addActionListener(this);
actionButtonPanel.add(subscribeButton);
// unsubscribeButton;
unsubscribeButton = new JButton("Unsubscribe from node");
unsubscribeButton.addActionListener(this);
actionButtonPanel.add(unsubscribeButton);
// getSubscrOptionButton;
getSubscrOptionButton = new JButton("Get subscription options");
getSubscrOptionButton.addActionListener(this);
actionButtonPanel.add(getSubscrOptionButton);
// getAffiliationsButton;
getAffiliationsButton = new JButton("Get my affiliations");
getAffiliationsButton.addActionListener(this);
actionButtonPanel.add(getAffiliationsButton);
// createNodeButton;
createNodeButton = new JButton("Create node");
createNodeButton.addActionListener(this);
actionButtonPanel.add(createNodeButton);
// deleteNodeButton;
deleteNodeButton = new JButton("Delete node");
deleteNodeButton.addActionListener(this);
actionButtonPanel.add(deleteNodeButton);
// pendingSubscrButton;
pendingSubscrButton = new JButton("Get pending subscriptions");
pendingSubscrButton.addActionListener(this);
actionButtonPanel.add(pendingSubscrButton);
// configureNodeButton;
configureNodeButton = new JButton("Get configuration form");
configureNodeButton.addActionListener(this);
actionButtonPanel.add(configureNodeButton);
// getEntitiesButton;
getEntitiesButton = new JButton("Get entities for node");
getEntitiesButton.addActionListener(this);
actionButtonPanel.add(getEntitiesButton);
// setEntitiesButton;
setEntitiesButton = new JButton("Set entities for node");
setEntitiesButton.addActionListener(this);
actionButtonPanel.add(setEntitiesButton);
centralPanel = new JPanel(new BorderLayout());
centralPanel.add(addressPanel, BorderLayout.NORTH);
mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, inputScrollPane, outputScrollPane);
centralPanel.add(mainSplitPane, BorderLayout.CENTER);
centralPanel.add(actionButtonPanel, BorderLayout.EAST);
mainPanel.add(checkBoxesPanel, BorderLayout.NORTH);
mainPanel.add(centralPanel, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
setEntitiesButton.setEnabled(false);
}
/** Handles actions from GUI controls */
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
// close
if (source == closeButton) {
winMan.closeWindow(this);
}
else if (evt.getSource() == dockButton) {
if (winMan != null) {
winMan.setWindowDocked(this, !docked, true);
Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
"images/dock.gif" : "images/float.gif"));
dockButton.setIcon(icon);
dockButton.setToolTipText(docked? "Float" : "Dock");
winMan.selectWindow(this);
}
}
else if (evt.getSource() == bookmarkButton) {
if (winMan != null)
((BSPubsubWinManager)winMan).addBookmark(JID.fromString(jidStr));
}
// pubsub operations
else {
jidStr = addressTextField.getText();
JID jid = JID.fromString(jidStr);
nodeStr = nodeTextField.getText();
if ("".equals(nodeStr)) nodeStr = null;
String inputStr = inputTextArea.getText();
// get items
if (source == getItemsButton) {
DefaultExtension item;
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.requestItems(jid, nodeStr, servedID);
}
}
// publish item
else if (source == publishItemButton) {
DefaultExtension item;
try {item = new DefaultExtension(null, null, inputStr);}
catch (InstantiationException e) {return;}
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.publishItem(item, null, jid, nodeStr, servedID);
}
}
// delete item;
else if (source == deleteItemButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.deleteItem(inputStr, jid, nodeStr, servedID);
}
}
// purge items
else if (source == purgeItemsButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.purgeNode(jid, nodeStr, servedID);
}
}
// subscribe
else if (source == subscribeButton) {
JID myJID = new JID(((BSPubsubWinManager)winMan).mainFrame.username,
((BSPubsubWinManager)winMan).mainFrame.server, null);
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.subscribeToNode(myJID, jid, nodeStr, servedID);
}
}
// unsubscribe
else if (source == unsubscribeButton) {
JID myJID = new JID(((BSPubsubWinManager)winMan).mainFrame.username,
((BSPubsubWinManager)winMan).mainFrame.server, null);
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.unsubscribeFromNode(myJID, jid, nodeStr, servedID);
}
}
// get subscription options
else if (source == getSubscrOptionButton) {
JID myJID = new JID(((BSPubsubWinManager)winMan).mainFrame.username,
((BSPubsubWinManager)winMan).mainFrame.server, null);
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.requestSubscriptionOptions(myJID, jid, nodeStr, servedID);
}
}
// get affiliations
else if (source == getAffiliationsButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.requestAffiliations(jid, servedID);
}
}
// create node
else if (source == createNodeButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.createNode(jid, nodeStr, servedID);
}
}
// delete node
else if (source == deleteNodeButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.deleteNode(jid, nodeStr, servedID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -