KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DeleteRoomDialog


1 import java.awt.*;
2 import java.awt.event.*;
3 import java.awt.image.ImageObserver JavaDoc;
4 import java.io.Serializable JavaDoc;
5 import java.util.*;
6 import javax.swing.*;
7 import javax.accessibility.Accessible JavaDoc;
8
9 import org.jivesoftware.smack.XMPPException;
10 import org.jivesoftware.smackx.*;
11 import org.jivesoftware.smackx.muc.*;
12
13 /** Dialog for deleteing Multi-User-Chat Rooms.*/
14 public final class DeleteRoomDialog extends JDialog implements Accessible JavaDoc, ImageObserver JavaDoc, MenuContainer, RootPaneContainer, Serializable JavaDoc, SwingConstants,WindowConstants{
15     
16     /** Indicates if user clicked on the Delete Room button.*/
17     private boolean hasConfirmed=false;
18     private static final int GAP=5;
19     private String JavaDoc r=""; // reason txt
20
private String JavaDoc a=""; // alternative room location
21

22     final BorderLayout layout=new BorderLayout(GAP,GAP);
23     
24     final JPanel panel=new JPanel(new SpringLayout());
25         final JLabel reasonLbl=new JLabel(Lang.gs("reason"));
26         final JTextField reason=new JTextField(15);
27         final JLabel altLbl=new JLabel(Lang.gs("alternative room"));
28         final JTextField alt=new JTextField(15);
29     
30     final JPanel btnPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT,GAP,GAP));
31         final JButton cancelBtn=new JButton(Lang.gs("cancel"),Icons.CANCEL);
32         final JButton removeBtn=new JButton(Lang.gs("remove room"),Icons.DELETE_CONTACT);
33     
34     final BtnClick click=new BtnClick();
35     
36     
37     public DeleteRoomDialog(){
38         super(WhisperIM.MainWindow,Lang.gs("remove room"),true);
39         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
40         Container cp=getContentPane();
41         cp.setLayout(layout);
42         
43         reason.setToolTipText(Lang.gs("drd_reason_tt"));
44         alt.setToolTipText(Lang.gs("alternative room_tt"));
45         panel.add(reasonLbl);
46         panel.add(reason);
47         panel.add(altLbl);
48         panel.add(alt);
49         SpringUtilities.makeCompactGrid(panel,2,2,GAP,GAP,GAP,GAP);
50         cp.add(panel,BorderLayout.CENTER);
51         
52         cancelBtn.setDefaultCapable(true);
53         cancelBtn.addActionListener(click);
54         cancelBtn.setMnemonic(Lang.s2k("cancel_mn"));
55         removeBtn.addActionListener(click);
56         removeBtn.setMnemonic(Lang.s2k("drd_remove_room_mn"));
57         btnPanel.add(cancelBtn);
58         btnPanel.add(removeBtn);
59         cp.add(btnPanel,BorderLayout.SOUTH);
60         
61         getRootPane().setDefaultButton(cancelBtn);
62         pack();
63         addKeyListener(new KeyAction());
64         addMouseListener(new MouseAction());
65     }
66     
67     public void show(JComponent c){
68         setLocationRelativeTo(c);
69         super.show();
70         reason.requestFocus();
71     }
72     
73     public boolean didUserConfirm(){
74         return hasConfirmed;
75     }
76     
77     public String JavaDoc getReason(){
78         return r;
79     }
80     
81     public String JavaDoc getAlternativeLocation(){
82         return a;
83     }
84     
85     final class BtnClick implements ActionListener{
86         public void actionPerformed(ActionEvent ae){
87             String JavaDoc b=ae.getActionCommand();
88             // call method depending on button clicked
89
if(b.equals(cancelBtn.getText())){
90                 dispose();
91                 return;
92             }
93             if(b.equals(removeBtn.getText())){
94                 hasConfirmed=true;
95                 r=reason.getText();
96                 a=alt.getText();
97                 dispose();
98             }
99         }
100     }
101 }
Popular Tags