📄 bspresencedialog.java
字号:
package edu.ou.kmi.buddyspace.gui;
/*
* BSPresenceDialog.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2002
*
*
* Created on 25 September 2002, 9:06
*/
import java.awt.*;
import javax.swing.*;
import java.beans.*; // Property change stuff
//import java.util.*;
//import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.util.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.core.*;
/**
* <code>BSPresenceDialog</code> allows entering of custom-defined presence.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSPresenceDialog extends JDialog {
private JOptionPane optionPane;
public String show = null;
public String status = null;
public final int MIN_PRIORITY = 0;
public final int MAX_PRIORITY = 10;
/** Constructor */
BSPresenceDialog(Frame _parent, BSPresenceBean _presenceBean) {
super(_parent, "Change presence", true);
final Frame parent = _parent;
final BSPresenceBean presenceBean = _presenceBean;
final JComboBox showComboBox = new JComboBox();
showComboBox.addItem(BSMainFrame.SHOW_ONLINE_STR);
showComboBox.addItem(BSMainFrame.SHOW_CHAT_STR);
showComboBox.addItem(BSMainFrame.SHOW_AWAY_STR);
showComboBox.addItem(BSMainFrame.SHOW_XA_STR);
showComboBox.addItem(BSMainFrame.SHOW_DND_STR);
final JComboBox statusComboBox = new JComboBox();
statusComboBox.setEditable(true);
statusComboBox.addItem("");
statusComboBox.addItem("Lunch");
statusComboBox.addItem("Be right back");
statusComboBox.addItem("Meeting");
statusComboBox.addItem("Gone home");
statusComboBox.addItem("Gone to work");
statusComboBox.addItem("Sleeping");
statusComboBox.addItem("Working");
statusComboBox.addItem("Free for chat");
statusComboBox.addItem("Away");
statusComboBox.addItem("Extended away");
statusComboBox.addItem("Do not disturb");
final JComboBox priorityComboBox = new JComboBox();
priorityComboBox.setEditable(false);
for (int i = MIN_PRIORITY; i < MAX_PRIORITY+1; i++)
priorityComboBox.addItem(new Integer(i));
priorityComboBox.setSelectedItem(new Integer(0));
BSPresenceInfo pi = presenceBean.getResourcePresence(
new JID(BSMainFrame.username,
BSMainFrame.server,
BSMainFrame.resource));
if (pi != null) {
String showStr = pi.getShow();
if (showStr == null || BSPresenceInfo.SHOW_ONLINE.equals(showStr))
showComboBox.setSelectedItem(BSMainFrame.SHOW_ONLINE_STR);
else if (BSPresenceInfo.SHOW_CHAT.equals(showStr))
showComboBox.setSelectedItem(BSMainFrame.SHOW_CHAT_STR);
else if (BSPresenceInfo.SHOW_DND.equals(showStr))
showComboBox.setSelectedItem(BSMainFrame.SHOW_DND_STR);
else if (BSPresenceInfo.SHOW_AWAY.equals(showStr))
showComboBox.setSelectedItem(BSMainFrame.SHOW_AWAY_STR);
else if (BSPresenceInfo.SHOW_XA.equals(showStr))
showComboBox.setSelectedItem(BSMainFrame.SHOW_XA_STR);
statusComboBox.setSelectedItem(pi.getStatus());
priorityComboBox.setSelectedItem(new Integer(pi.getPriority()));
}
Object[] fields = {"Show: ", showComboBox,
"Status: ", statusComboBox,
"Priority: ", priorityComboBox};
final String okButton = "OK";
final String cancelButton = "Cancel";
Object[] options = {okButton, cancelButton};
optionPane = new JOptionPane(fields,
JOptionPane.PLAIN_MESSAGE,
JOptionPane.OK_CANCEL_OPTION,
null,
options,
options[0]);
setContentPane(optionPane);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
pack();
setLocationRelativeTo(parent);
// handles actions
optionPane.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (isVisible()
&& (e.getSource() == optionPane)
&& (prop.equals(JOptionPane.VALUE_PROPERTY) ||
prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
Object value = optionPane.getValue();
if (value == JOptionPane.UNINITIALIZED_VALUE) {
// ignore reset
return;
}
// Reset the JOptionPane's value.
// If you don't do this, then if the user
// presses the same button next time, no
// property change event will be fired.
optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
if (value.equals(okButton)) {
if (presenceBean == null) {
JOptionPane.showMessageDialog(parent,
"Cannot send presence",
"Error",
JOptionPane.ERROR_MESSAGE);
setVisible(false);
return;
}
show = (String) showComboBox.getSelectedItem();
status = (String) statusComboBox.getSelectedItem();
int priority = ((Integer) priorityComboBox.getSelectedItem()).intValue();
if (BSMainFrame.SHOW_ONLINE_STR.equals(show))
presenceBean.setMyPresence(true, null, status, priority);
else if (BSMainFrame.SHOW_CHAT_STR.equals(show))
presenceBean.setMyPresence(true, BSPresenceInfo.SHOW_CHAT, status, priority);
else if (BSMainFrame.SHOW_AWAY_STR.equals(show))
presenceBean.setMyPresence(true, BSPresenceInfo.SHOW_AWAY, status, priority);
else if (BSMainFrame.SHOW_XA_STR.equals(show))
presenceBean.setMyPresence(true, BSPresenceInfo.SHOW_XA, status, priority);
else if (BSMainFrame.SHOW_DND_STR.equals(show))
presenceBean.setMyPresence(true, BSPresenceInfo.SHOW_DND, status, priority);
setVisible(false);
return;
}
else if (value.equals(cancelButton)) {
setVisible(false);
}
}
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -