📄 bscomposemsgwin.java
字号:
gridBagConstraints.weighty = 0;
headerPanel.add(subjectLabel, gridBagConstraints);
subjectTextField = new JTextField();
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
headerPanel.add(subjectTextField, gridBagConstraints);
/*gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 7;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.weightx = 1;
gridBagConstraints.weighty = 1;
gridBagConstraints.fill = GridBagConstraints.BOTH;
headerPanel.add(msgScrollPane, gridBagConstraints);*/
JSplitPane mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
headerPanel, msgScrollPane);
mainSplitPane.setDividerLocation(110);
//mainSplitPane.setDividerLocation(0.2);
//mainPanel.add(headerPanel, BorderLayout.NORTH);
//mainPanel.add(msgScrollPane, BorderLayout.CENTER);
//mainPanel.add(headerPanel, BorderLayout.CENTER);
mainPanel.add(mainSplitPane, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
setLayout(new BorderLayout());
add(checkBoxesPanel, BorderLayout.NORTH);
add(mainPanel, BorderLayout.CENTER);
}
/*protected void initAddDialogs() {
Enumeration jids = (rosterBean != null)? rosterBean.entries():
new Vector().elements();
addJIDDialog = new BSChooseJIDDialog((Frame)mainFrame, "Add recipient JID", jids);
Iterator groups = (rosterBean != null)? rosterBean.getGroups():
new TreeSet().iterator();
addGroupDialog = new BSChooseGroupDialog((Frame)mainFrame, "Add group of recipients", groups);
}*/
/** Sets message subject */
public void setSubject(String subject) {
subjectTextField.setText((subject != null)? subject : "");
}
/** Sets message body */
public void setBody(String body) {
msgTextArea.setText((body != null)? body : "");
}
/** Adds all jids from jidList as recipients */
public void addRecipients(Enumeration jidList) {
DefaultListModel lm = (DefaultListModel)recipientList.getModel();
// for all from jidList
while (jidList.hasMoreElements()) {
JID jid = (JID) jidList.nextElement();
if (!lm.contains(jid)) {
lm.addElement(jid);
}
}
recipientList.revalidate();
}
/** Adds jid as recipient */
public void addRecipientJID(JID jid) {
DefaultListModel lm = (DefaultListModel)recipientList.getModel();
if (!lm.contains(jid)) {
lm.addElement(jid);
recipientList.revalidate();
}
}
/** Adds group as recipient */
public void addRecipientGroup(String group) {
addRecipientGroup(group, false);
}
/** Adds group as recipient */
public void addRecipientGroup(String group, boolean onlyOnline) {
if (rosterBean == null) return;
Enumeration jidEnum = rosterBean.getJIDsInGroup(group);
if (onlyOnline) jidEnum = getOnlineJIDs(jidEnum);
addRecipients(jidEnum);
}
/** Returns subset of the JIDs which are online; or all of them when
* presenceBean not available */
protected Enumeration getOnlineJIDs(Enumeration jidEnum) {
if (presenceBean != null && jidEnum != null) {
Vector onlines = new Vector();
while (jidEnum.hasMoreElements()) {
JID jid = (JID) jidEnum.nextElement();
BSPresenceInfo pi = presenceBean.getResourcePresence(jid);
if (pi != null && pi.isOnline())
onlines.add(jid);
}
jidEnum = onlines.elements();
}
return jidEnum;
}
/** Returns subset of the RosterItems which are online; or all of them when
* presenceBean not available */
protected Enumeration getOnlineRosterItems(Enumeration riEnum) {
if (presenceBean != null && riEnum != null) {
Vector onlines = new Vector();
while (riEnum.hasMoreElements()) {
RosterItem ri = (RosterItem) riEnum.nextElement();
BSPresenceInfo pi = presenceBean.getResourcePresence(ri.getJID());
if (pi != null && pi.isOnline())
onlines.add(ri);
}
riEnum = onlines.elements();
}
return riEnum;
}
/** Sends message */
protected void sendMessage() {
String msg = msgTextArea.getText();
String subject = subjectTextField.getText();
// getSelectedValues()
Enumeration jidEnum = ((DefaultListModel)recipientList.getModel()).elements();
if (winMan != null)
((BSMsgWinManager)winMan).sendMessage(jidEnum, msg, subject);
winMan.closeWindow(this);
// stores msg to history
/*History.storeMessage(new JID(BSMainFrame.username, BSMainFrame.server, null),
jid, local, null, msg);*/
}
/** Handles actions from buttons */
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == closeButton) {
if (winMan != null)
//winMan.closeTab(this);
winMan.closeWindow(this);
}
else if (evt.getSource() == sendButton) {
sendMessage();
}
else if (evt.getSource() == addJIDButton) {
Enumeration jids = (rosterBean != null)? rosterBean.entries():
new Vector().elements();
BSChooseJIDDialog addJIDDialog
= new BSChooseJIDDialog(getUsedFrame(), "Add recipient JID", jids);
addJIDDialog.show();
if (addJIDDialog.jid != null)
addRecipientJID(addJIDDialog.jid);
}
else if (evt.getSource() == addOnlineJIDButton) {
Enumeration jids = (rosterBean != null)? rosterBean.entries():
new Vector().elements();
jids = getOnlineRosterItems(jids);
BSChooseJIDDialog addJIDDialog
= new BSChooseJIDDialog(getUsedFrame(), "Add recipient JID", jids);
addJIDDialog.show();
if (addJIDDialog.jid != null)
addRecipientJID(addJIDDialog.jid);
}
else if (evt.getSource() == addGroupButton) {
Iterator groups = (rosterBean != null)? rosterBean.getGroups():
new TreeSet().iterator();
BSChooseGroupDialog addGroupDialog
= new BSChooseGroupDialog(getUsedFrame(), "Add group of recipients", groups, false);
addGroupDialog.show();
if (addGroupDialog.group != null)
addRecipientGroup(addGroupDialog.group, addGroupDialog.onlyOnline);
}
else if (evt.getSource() == removeJIDsButton) {
DefaultListModel lm = (DefaultListModel) recipientList.getModel();
Object[] delJids = recipientList.getSelectedValues();
for (int i=0; i<delJids.length; i++)
lm.removeElement(delJids[i]);
recipientList.clearSelection();
recipientList.revalidate();
}
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);
}
}
}
protected Frame getUsedFrame() {
return docked? ((BSMsgWinManager)winMan).mainFrame : frame;
}
public void cancelListening() { }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -