1 import java.awt.*; 2 import java.awt.event.*; 3 import java.awt.image.ImageObserver ; 4 import java.io.Serializable ; 5 import javax.swing.*; 6 import javax.accessibility.Accessible ; 7 8 9 10 public final class InviteDialog extends JDialog implements Accessible , ImageObserver , MenuContainer, RootPaneContainer, Serializable , SwingConstants,WindowConstants{ 11 12 private static final int GAP=10; 13 14 private MUCPanel mucPanel; 15 16 final JPanel panel=new JPanel(new SpringLayout()); 17 final JLabel inviteLbl=new JLabel(Lang.gs("invite")+":"); 18 final java.util.Vector data=new java.util.Vector (WhisperIM.MainWindow.Contacts.values()); 19 final JComboBox who=new JComboBox(data); 20 final JLabel reasonLbl=new JLabel(Lang.gs("reason")); 21 final JTextField reason=new JTextField(15); 22 23 final JPanel btnPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT,GAP,GAP)); 24 final JButton cancelBtn=new JButton(Lang.gs("cancel"),Icons.CANCEL); 25 final JButton inviteBtn=new JButton(Lang.gs("send invitation"),Icons.SUBMIT); 26 27 final BorderLayout layout=new BorderLayout(GAP,GAP); 28 29 final BtnClick click=new BtnClick(); 30 31 public InviteDialog(MUCPanel mucpanel){ 32 super(WhisperIM.MainWindow,Lang.gs("send invitation"),true); 33 this.mucPanel=mucpanel; 34 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 35 final Container cp=getContentPane(); 36 cp.setLayout(layout); 37 38 java.util.Collections.sort(data,new ContactComparator()); 39 if(who.getMaximumRowCount()>who.getItemCount() ){ 40 who.setMaximumRowCount(who.getItemCount()); 41 } 42 who.setToolTipText(Lang.gs("who_tt")); 43 who.setEditable(true); 44 who.setSelectedItem(""); 45 reason.setToolTipText(Lang.gs("invite_reason_tt")); 46 panel.add(inviteLbl); 47 panel.add(who); 48 panel.add(reasonLbl); 49 panel.add(reason); 50 SpringUtilities.makeCompactGrid(panel,2,2,GAP,GAP,GAP,GAP); 51 cp.add(panel,BorderLayout.CENTER); 52 53 cancelBtn.setMnemonic(Lang.s2k("cancel_mn")); 54 inviteBtn.setMnemonic(Lang.s2k("send invitation_mn")); 55 cancelBtn.addActionListener(click); 56 inviteBtn.addActionListener(click); 57 btnPanel.add(cancelBtn); 58 btnPanel.add(inviteBtn); 59 cp.add(btnPanel,BorderLayout.SOUTH); 60 61 inviteBtn.setDefaultCapable(true); 62 getRootPane().setDefaultButton(inviteBtn); 63 64 pack(); 65 addKeyListener(new KeyAction()); 66 addMouseListener(new MouseAction()); 67 } 68 69 70 public void go(){ 71 setLocationRelativeTo(mucPanel); 72 show(); 73 } 74 75 public void doInvite(){ 76 String address; 77 if(who.getSelectedIndex()==-1){ 78 address=who.getSelectedItem().toString().trim(); 79 if(address.equals("") || address.indexOf("@")==-1){ 80 GUI.showInfo(this,"send invitation","need valid id"); 81 who.requestFocus(); 82 return; 83 } 84 } 85 else{ 86 address=( (ContactListItem) who.getSelectedItem()).getID(); 87 } 88 try{ 89 mucPanel.getMultiUserChat().invite(address,reason.getText()); 90 } 91 catch(Exception e){ 92 GUI.showError(this,"send invitation", null ,e.getMessage()); 93 dispose(); 94 return; 95 } 96 mucPanel.announce(Lang.gs("invitation sent")+address); 97 dispose(); 98 } 99 100 final class BtnClick implements ActionListener{ 101 public void actionPerformed(ActionEvent ae){ 102 String b=ae.getActionCommand(); 104 if(b.equals(cancelBtn.getText())){ 106 dispose(); 107 return; 108 } 109 if(b.equals(inviteBtn.getText())){ 110 doInvite(); 111 return; 112 } 113 } 114 } 115 } | Popular Tags |