📄 inviteuserdialog.java
字号:
/* * Copyright (C) 2003 Adam Olsen This program is free software; you can * redistribute it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either version 1, or * (at your option) any later version. This program is distributed in the hope * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. You should have received a copy of * the GNU General Public License along with this program; if not, write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother.groupchat;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Enumeration;import java.util.Hashtable;import java.util.Locale;import java.util.ResourceBundle;import javax.swing.BorderFactory;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import org.jivesoftware.smack.packet.Presence;import com.valhalla.gui.MJTextField;import com.valhalla.jbother.BuddyList;import com.valhalla.jbother.jabber.BuddyStatus;public class InviteUserDialog extends JDialog { private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault()); private JPanel main; private JButton okButton = new JButton(resources.getString("okButton")); private JButton cancelButton = new JButton(resources .getString("cancelButton")); private JComboBox jidBox = new JComboBox(); private MJTextField reason = new MJTextField(15); private ChatRoomPanel window; public InviteUserDialog(ChatRoomPanel window) { super(BuddyList.getInstance().getTabFrame(), "", true); this.window = window; main = (JPanel) getContentPane(); main.setBorder(BorderFactory.createTitledBorder(resources .getString("inviteUser"))); GridBagLayout grid = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); main.setLayout(grid); jidBox.setEditable(true); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.weighty = 0; c.weightx = 1.0; JLabel jidLabel = new JLabel(resources.getString("buddyId")); JLabel reasonLabel = new JLabel(resources .getString("enterReasonForInvite")); grid.setConstraints(jidLabel, c); c.gridy++; grid.setConstraints(jidBox, c); c.gridy++; grid.setConstraints(reasonLabel, c); c.gridy++; grid.setConstraints(reason, c); main.add(jidLabel); main.add(reasonLabel); main.add(jidBox); main.add(reason); Presence.Mode mode; jidBox.addItem(""); Hashtable users = BuddyList.getInstance().getBuddyStatuses(); for (Enumeration e = users.keys(); e.hasMoreElements();) { String jid = (String) e.nextElement(); BuddyStatus buddy = (BuddyStatus) users.get(jid); if (jid.indexOf("@") > -1 && buddy.getPresence(buddy.getHighestResource()) != null) { jidBox.addItem(jid); } } JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.add(Box.createHorizontalGlue()); buttons.add(okButton); buttons.add(cancelButton); buttons.add(Box.createHorizontalGlue()); buttons.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5)); c.gridy++; grid.setConstraints(buttons, c); main.add(buttons); addListeners(); pack(); setLocationRelativeTo(null); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { cancelHandler(); } }); Dimension dim = getSize(); setSize(350, (int) dim.getHeight()); setResizable(false); setVisible(true); } private void addListeners() { okButton.addActionListener(new OKDialogListener()); cancelButton.addActionListener(new CancelDialogListener()); } class OKDialogListener implements ActionListener { public void actionPerformed(ActionEvent e) { okHandler(); } } class CancelDialogListener implements ActionListener { public void actionPerformed(ActionEvent e) { cancelHandler(); } } private void okHandler() { String jid = (String) jidBox.getSelectedItem(); if (jid != null && !jid.equals("")) { window.inviteUser(jid, reason.getText()); } dispose(); } private void cancelHandler() { dispose(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -