📄 bspubsubwindow.java
字号:
}
}
// pending subscriptions
else if (source == pendingSubscrButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.requestAllPendingSubscriptions(jid, servedID);
}
}
// configure node
else if (source == configureNodeButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.requestNodeConfiguration(jid, nodeStr, servedID);
}
}
// get entities
else if (source == getEntitiesButton) {
if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.requestEntities(jid, nodeStr, servedID);
}
}
//setEntitiesButton
else if (source == setEntitiesButton) {
/*if (pubsubBean != null) {
prepareToSendRequest();
pubsubBean.requestEntities(jid, nodeStr, servedID);
}*/
}
}
}
protected void prepareToSendRequest() {
/*this.jidStr = jidStr;
this.nodeStr = nodeStr;
winMan.setWindowTitle(this, "Disco " + jidStr +
((nodeStr != null)? (" -> " + nodeStr) : ""));
addressTextField.setText(jidStr);
nodeTextField.setText((nodeStr != null)? nodeStr : "");*/
outputTextArea.setText("");
progressInfo.setText("Sending request...");
/*backButton.setEnabled(currHistoryNum > 0);
forwardButton.setEnabled(currHistoryNum < history.size()-1);
if (discoBean != null)
discoBean.discoverItems(jidStr, nodeStr, itemsServedID);*/
}
/** Removes this from listeners for pubsub events */
public void cancelListening() {
if (pubsubBean != null)
pubsubBean.removePubsubListener(this);
}
/** <code>MouseListener</code> function - catches double-clicks. */
public void mouseClicked(MouseEvent e) {
// handles only double clicks on JID nodes
if (e.getClickCount() == 2) {
/*DiscoItem di = (DiscoItem) browseList.getSelectedValue();
if (di == null) return;
String jidStr = di.getAttribute("jid");
String nodeStr = di.getAttribute("node");
discover(jidStr, nodeStr);*/
}
}
/** <code>MouseListener</code> function - catches popup clicks. */
public void mousePressed(MouseEvent e) {
//maybeShowPopup(e);
}
/** <code>MouseListener</code> function - catches popup clicks. */
public void mouseReleased(MouseEvent e) {
//maybeShowPopup(e);
}
/** <code>MouseListener</code> function - empty implementation. */
public void mouseEntered(MouseEvent e) { }
/** <code>MouseListener</code> function - empty implementation. */
public void mouseExited(MouseEvent e) { }
/** Called when link action performed - calls performAction of mainFrame */
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (HyperlinkEvent.EventType.ACTIVATED == evt.getEventType()) {
/*String namespace = evt.getDescription();
JID jid;
if (evt.getSource() == thisItemView)
jid = thisItemView.getJID();
else if (evt.getSource() == selectedItemView)
jid = selectedItemView.getJID();
else
jid = selectedItemView.getJID();
((BSDiscoWinManager)winMan).callPerformAction(jid, namespace);*/
}
}
/** Empty implementation */
public void keyTyped(KeyEvent evt) { }
/** Empty implementation */
public void keyReleased(KeyEvent keyEvent) { }
/** Handles key strokes - sends on ENTER */
public void keyPressed(KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
jidStr = addressTextField.getText();
nodeStr = nodeTextField.getText();
if ("".equals(nodeStr)) nodeStr = null;
//discover(jidStr, nodeStr);
}
}
/** <code>BSPubsubListener</code> function. */
public void error(InfoQuery iq, String id) {
if (id == null || !id.equals(servedID.getID()))
return;
String errCode = iq.getErrorCode();
String errMsg = iq.getErrorText();
winMan.selectWindow(this);
progressInfo.setText("Error");
JOptionPane.showMessageDialog(docked? ((BSPubsubWinManager)winMan).mainFrame : frame,
"Error " + errCode + ": " + errMsg + "!",
"Error",
JOptionPane.ERROR_MESSAGE);
progressInfo.setText("");
servedID.setID(null);
}
/** Called when a send fails */
public void sendFailed(InfoQuery iq, String id) {
if (id == null || !id.equals(servedID.getID()))
return;
winMan.selectWindow(this);
progressInfo.setText("Error");
JOptionPane.showMessageDialog(docked? ((BSPubsubWinManager)winMan).mainFrame : frame,
"Request couldn't be sent",
"Error",
JOptionPane.ERROR_MESSAGE);
progressInfo.setText("");
servedID.setID(null);
}
/** Called when empty result (possible of previous "set") received */
public void receivedEmptyResult(InfoQuery iq, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("OK" + "\n\n**********\n\n");
progressInfo.setText("Ready");
}
/** Called when result of affiliations request received. */
public void affiliationsReceived(InfoQuery iq, PubsubAffiliations affs, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("affiliations on " + iq.getFromAddress() + ":\n\n"
+ affs + "\n\n**********\n\n");
progressInfo.setText("Affiliations received");
}
/** Called when result of configure request received. */
public void configureReceived(InfoQuery iq, PubsubOwnerOps configure, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("configuration for node " + configure.getNode() +
" on " + iq.getFromAddress() + ":\n\n"
+ configure + "\n\n**********\n\n");
progressInfo.setText("Configuration form received");
XData form = configure.getForm();
if (form != null) {
String comment = "Form from " + iq.getFromAddress().toString();
BSFormDialog dlg = new BSFormDialog(docked? ((BSPubsubWinManager)winMan).mainFrame : frame,
form, comment, null);
dlg.show();
if (dlg.resultXData == null)
;//error
else if ("cancel".equals(dlg.resultXData.getType()) ||
"submit".equals(dlg.resultXData.getType())) {
// send that back to server
JID jid = iq.getFromAddress();
String node = configure.getNode();
servedID.setID(iq.getIdentifier());
if (!pubsubBean.setNodeConfiguration(dlg.resultXData, jid, node, servedID))
;//error
}
return;
}
}
/** Called when instant node created */
public void instantNodeCreated(InfoQuery iq, String nodeName, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("instant node with name " + nodeName +
" was created on " + iq.getFromAddress() + /*":\n\n"
+ configure +*/ "\n\n**********\n\n");
progressInfo.setText("Instant node created");
}
/** Called when received items event - published or retracted items. */
public void itemsEvent(Message m, PubsubEventItems items, String id) {
outputTextArea.append("items published to node " + items.getNode() +
" on " + m.getFromAddress() + ":\n\n"
+ items + "\n\n**********\n\n");
progressInfo.setText("Published items received");
}
/** Called when result of items request received. */
public void itemsReceived(InfoQuery iq, PubsubItems items, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("items in node " + items.getNode() +
" on " + iq.getFromAddress() + ":\n\n"
+ items + "\n\n**********\n\n");
progressInfo.setText("Items received");
}
/** Called when node deleted event received */
public void nodeDeletedEvent(Message m, String nodeName, String id) {
outputTextArea.append("node " + nodeName +
" on " + m.getFromAddress() + " was deleted"
+ /*items +*/ "\n\n**********\n\n");
progressInfo.setText("Node deleted");
}
/** Called when node entities received. */
public void nodeEntities(InfoQuery iq, PubsubEntities entities, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("entities for node " + entities.getNode() +
" on " + iq.getFromAddress() + ":\n\n"
+ entities + "\n\n**********\n\n");
progressInfo.setText("Entities received");
}
/** Called when result of options request received. */
public void optionsReceived(InfoQuery iq, PubsubOptions options, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("options for node " + options.getNode() +
" on " + iq.getFromAddress() +
" and JID " + options.getJID() + ":\n\n"
+ options + "\n\n**********\n\n");
progressInfo.setText("Options received");
XData form = options.getForm();
if (form != null) {
String comment = "Form from " + iq.getFromAddress().toString();
BSFormDialog dlg = new BSFormDialog(docked? ((BSPubsubWinManager)winMan).mainFrame : frame,
form, comment, null);
dlg.show();
if (dlg.resultXData == null)
;//error
else if ("cancel".equals(dlg.resultXData.getType()) ||
"submit".equals(dlg.resultXData.getType())) {
// send that back to server
JID jid = iq.getFromAddress();
JID myJID = options.getJID();
String node = options.getNode();
servedID.setID(iq.getIdentifier());
if (!pubsubBean.setSubscriptionOptions(dlg.resultXData, myJID, jid,
node, servedID))
;//error
}
return;
}
}
/** Called when result of subscription request received. */
public void subscriptionResult(InfoQuery iq, PubsubEntity entity, String id) {
if (id != null && !id.equals(servedID.getID())) return;
servedID.setID(null);
outputTextArea.append("subscription result for node " + entity.getNode() +
" on " + iq.getFromAddress() +
" and JID " + entity.getJID() + ":\n\n"
+ entity + "\n\n**********\n\n");
progressInfo.setText("Subscription result received");
}
/** Renderer of list of disco items */
class BSDiscoListCellRenderer extends JLabel
implements ListCellRenderer {
/*final static ImageIcon longIcon = new ImageIcon("component.gif");
final static ImageIcon shortIcon = new ImageIcon("service.gif");*/
protected Border noFocusBorder;
/**
* Constructor.
*/
public BSDiscoListCellRenderer() {
super();
if (noFocusBorder == null) {
noFocusBorder = new EmptyBorder(1, 1, 1, 1);
}
setOpaque(true);
setBorder(noFocusBorder);
}
public Component getListCellRendererComponent(
JList list,
Object value, // value to display
int index, // cell index
boolean isSelected, // is the cell selected
boolean cellHasFocus) { // the list and the cell have the focus
setComponentOrientation(list.getComponentOrientation());
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
}
else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
//setIcon(null);
/*DiscoItem di = (DiscoItem) value;
String name = di.getAttribute("name");
String jidStr = di.getAttribute("jid");
String node = di.getAttribute("node");
String txt = ((name != null)? name : "");
if (jidStr != null) {
txt += " (" + jidStr;
if (node == null) txt += ")";
}
if (node != null) {
if (jidStr != null) txt += " - " + node + ")";
else txt += " (" + node + ")";
}*/
String txt = "nazdarek";
setText(txt);
setEnabled(list.isEnabled());
setFont(list.getFont());
setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
return this;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -