1 import java.awt.*; 2 import java.awt.event.*; 3 import java.awt.image.ImageObserver ; 4 import java.io.Serializable ; 5 import java.util.*; 6 import javax.swing.*; 7 import javax.swing.border.*; 8 import javax.swing.tree.DefaultMutableTreeNode ; 9 import javax.accessibility.Accessible ; 10 import org.jivesoftware.smack.util.StringUtils; 11 12 13 public final class ChatWithDialog extends JDialog implements Accessible , ImageObserver , MenuContainer, RootPaneContainer, Serializable , SwingConstants,WindowConstants{ 14 private final static int GAP=10; 15 16 final JLabel chatLbl=new JLabel(Lang.gs("chat with")); 17 final java.util.Vector data=new java.util.Vector (WhisperIM.MainWindow.Contacts.values()); 18 final JComboBox with=new JComboBox(data); 19 20 final JPanel btnPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT,GAP,GAP)); 21 final JButton chatBtn=new JButton(Lang.gs("menu_chat_chat"),Icons.CHAT); 22 final JButton cancelBtn=new JButton(Lang.gs("cancel"),Icons.CANCEL); 23 24 final BtnClick click=new BtnClick(); 25 26 public ChatWithDialog(){ 27 super(WhisperIM.MainWindow,Lang.gs("menu_chat") ,true); 28 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 29 Container cp=getContentPane(); 30 cp.setLayout(new BorderLayout(GAP,GAP)); 31 32 with.setToolTipText(Lang.gs("chat with_tt")); 33 with.setEditable(true); 34 java.util.Collections.sort(data,new ContactComparator()); 35 if(with.getMaximumRowCount()>with.getItemCount() ){ 36 with.setMaximumRowCount(with.getItemCount()); } 38 with.setSelectedItem(""); 39 cp.add(GUI.panel(chatLbl,with,GAP),BorderLayout.CENTER); 40 41 chatBtn.setDefaultCapable(true); 42 getRootPane().setDefaultButton(chatBtn); 43 cancelBtn.setMnemonic(Lang.s2k("cancel_mn")); 44 chatBtn.addActionListener(click); 45 cancelBtn.addActionListener(click); 46 47 btnPanel.add(chatBtn); 48 btnPanel.add(cancelBtn); 49 cp.add(btnPanel,BorderLayout.SOUTH); 50 getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(WhisperIM.HELP_KEY,0),"help"); getRootPane().getActionMap().put("help",new HelpAction(this,"messages.html#chat")); 53 pack(); 54 setLocationRelativeTo(WhisperIM.MainWindow); 55 addKeyListener(new KeyAction()); 56 addMouseListener(new MouseAction()); 57 } 58 59 public void doChat(){ 60 String address; 62 if(with.getSelectedIndex()==-1){ 63 address=with.getSelectedItem().toString(); 64 } 65 else{ 66 address=( (ContactListItem) with.getSelectedItem()).getID(); 67 } 68 if(address==null || address.equals("")){ 69 GUI.showInfo(this,"menu_chat","no address"); 70 with.requestFocus(); 71 return; 72 } 73 WhisperIM.MainWindow.chatWith(address); 74 dispose(); 75 } 76 77 final class BtnClick implements ActionListener{ 78 public void actionPerformed(ActionEvent ae){ 79 String b=ae.getActionCommand(); 81 if(b.equals(cancelBtn.getText())){ 83 dispose(); 84 return; 85 } 86 if(b.equals(chatBtn.getText())){ 87 doChat(); 88 return; 89 } 90 } 91 } 92 } | Popular Tags |