📄 bsdiscowindow.java
字号:
package edu.ou.kmi.buddyspace.plugins.disco.gui;
/*
* BSDiscoWindow.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2003
*
*
* Created on 13 October 2003, 14:05
*/
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 edu.ou.kmi.buddyspace.core.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.utils.*;
import edu.ou.kmi.buddyspace.plugins.disco.core.*;
import edu.ou.kmi.buddyspace.plugins.disco.xml.*;
/**
* <code>BSDiscoWindow</code> is the disco GUI.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSDiscoWindow extends DockableWindow
implements ActionListener, BSDiscoListener,
MouseListener, HyperlinkListener,
KeyListener {
private BSDiscoBean discoBean = null;
private String jidStr;
private String nodeStr;
private PacketID itemsServedID = new PacketID(null);
private PacketID infoServedID = new PacketID(null);
private Vector history = new Vector();
private int currHistoryNum = -1;
private JPanel mainPanel;
JPanel buttonPanel;
JTextField progressInfo;
JButton browseButton;
JButton closeButton;
JButton dockButton;
JButton bookmarkButton;
JPanel centralPanel;
JScrollPane browseScrollPane;
//JScrollPane thisItemScrollPane;
JScrollPane selectedItemScrollPane;
//BSBrowseItemView thisItemView;
BSDiscoItemView selectedItemView;
JList browseList;
JTextField addressTextField;
JTextField nodeTextField;
JSplitPane mainSplitPane;
JSplitPane rightSplitPane;
JPanel addressPanel;
JButton backButton;
JButton forwardButton;
/** Constructor */
BSDiscoWindow(Window parent, BSDiscoWinManager winMan, String ID,
String title, String jidStr, String nodeStr, Image icon,
BSDiscoBean discoBean, boolean docked) {
super(ID, title, icon, new Dimension(450, 400), docked, winMan);
this.jidStr = jidStr;
this.nodeStr = nodeStr;
this.discoBean = discoBean;
if (discoBean != null)
discoBean.addDiscoListener(this);
initComponents();
if (discoBean != 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);
browseList = new JList();
browseList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
browseList.setCellRenderer(new BSDiscoListCellRenderer());
browseList.addMouseListener(this);
browseList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
/*DiscoItem di = (DiscoItem) browseList.getSelectedValue();
discoverInfoFor(di);*/
}
});
browseScrollPane = new JScrollPane(browseList);
browseScrollPane.setBorder(new TitledBorder("Items in node"));
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
browseButton = new JButton("Browse");
browseButton.addActionListener(this);
gbc = new GridBagConstraints();
gbc.gridx = 3; gbc.gridy = 0; gbc.gridheight = 2;
gbc.anchor = GridBagConstraints.CENTER;
addressPanel.add(browseButton, gbc);
backButton = new JButton("<-");
backButton.addActionListener(this);
gbc = new GridBagConstraints();
gbc.gridx = 4; gbc.gridy = 0; gbc.gridheight = 2;
gbc.anchor = GridBagConstraints.CENTER;
addressPanel.add(backButton, gbc);
forwardButton = new JButton("->");
forwardButton.addActionListener(this);
gbc = new GridBagConstraints();
gbc.gridx = 5; gbc.gridy = 0; gbc.gridheight = 2;
gbc.anchor = GridBagConstraints.CENTER;
addressPanel.add(forwardButton, gbc);
centralPanel = new JPanel(new BorderLayout());
centralPanel.add(addressPanel, BorderLayout.NORTH);
/*thisItemView = new BSBrowseItemView();
thisItemView.addHyperlinkListener(this);
thisItemScrollPane = new JScrollPane(thisItemView);
thisItemScrollPane.setBorder(new TitledBorder("Item details"));*/
selectedItemView = new BSDiscoItemView();
selectedItemView.addHyperlinkListener(this);
selectedItemScrollPane = new JScrollPane(selectedItemView);
selectedItemScrollPane.setBorder(new TitledBorder("Node details"));
/*rightSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, browseScrollPane, selectedItemScrollPane);
rightSplitPane.setDividerLocation(150);*/
//mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, thisItemScrollPane, rightSplitPane);
mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, browseScrollPane, selectedItemScrollPane);
mainSplitPane.setDividerLocation(200);
centralPanel.add(mainSplitPane, BorderLayout.CENTER);
mainPanel.add(checkBoxesPanel, BorderLayout.NORTH);
mainPanel.add(centralPanel, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
backButton.setEnabled(false);
forwardButton.setEnabled(false);
}
/** Handles actions from GUI controls */
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
// close
if (source == closeButton) {
winMan.closeWindow(this);
}
// send message
else if (source == browseButton) {
jidStr = addressTextField.getText();
nodeStr = nodeTextField.getText();
if ("".equals(nodeStr)) nodeStr = null;
discover(jidStr, nodeStr);
}
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() == backButton) {
if (currHistoryNum > 0) {
discoverHistory(currHistoryNum-1);
}
}
else if (evt.getSource() == forwardButton) {
if (history.size()-1 > currHistoryNum) {
discoverHistory(currHistoryNum+1);
}
}
else if (evt.getSource() == bookmarkButton) {
if (winMan != null)
((BSDiscoWinManager)winMan).addBookmark(JID.fromString(jidStr));
}
}
protected void discoverImpl(String jidStr, String nodeStr) {
this.jidStr = jidStr;
this.nodeStr = nodeStr;
winMan.setWindowTitle(this, "Disco " + jidStr +
((nodeStr != null)? (" -> " + nodeStr) : ""));
addressTextField.setText(jidStr);
nodeTextField.setText((nodeStr != null)? nodeStr : "");
//thisItemView.display(null);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -