KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > zirc > gui > ActionDialog


1 package zirc.gui ;
2
3 import java.awt.* ;
4 import java.awt.event.* ;
5 import javax.swing.* ;
6 import javax.swing.event.* ;
7
8 import zirc.base.* ;
9 import java.util.* ;
10
11 //zIrc, irc client.
12
// Copyright (C) 2004 CoolBytes(Stephane claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com
13
//
14
// This program is free software; you can redistribute it and/or
15
// modify it under the terms of the GNU General Public License
16
// as published by the Free Software Foundation; either version 2
17
// of the License, or (at your option) any later version.
18
//
19
// This program is distributed in the hope that it will be useful,
20
// but WITHOUT ANY WARRANTY; without even the implied warranty of
21
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
// GNU General Public License for more details.
23

24 /**
25  * <p>Title: ActionDialog</p>
26  * <p>Description: jdialog qui affiche les actions disponibles(op,kick whois etc...)</p>
27  * <p>Copyright: Copyright (c) 2004</p>
28  * <p>Company: CoolBytes(Stephane claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com</p>
29  * @version 1.0
30  */

31
32 public class ActionDialog extends JDialog
33 {
34   private JList JlistAction = new JList() ;
35   private ChatFrame chatFrm;
36   private DefaultListModel lm = new DefaultListModel() ;
37   private IRCconnexion IRCchan ;
38   private String JavaDoc chan ;
39   private JDialog jDialog1 = new JDialog(this) ;
40   private JPanel jPanel1 = new JPanel() ;
41   private JButton jButton_OK = new JButton() ;
42   private JTextField jt_Message = new JTextField() ;
43   private String JavaDoc kickMSG = "" ;
44   private String JavaDoc nick ;
45   private String JavaDoc action ;
46   private JPanel jPanel2 = new JPanel() ;
47   private BorderLayout borderLayout1 = new BorderLayout() ;
48   private BorderLayout borderLayout2 = new BorderLayout() ;
49
50   public ActionDialog(IRCconnexion _IRCchan, String JavaDoc _chan, ChatFrame _chatFrm)
51   {
52     IRCchan = _IRCchan ;
53     chan = _chan ;
54     chatFrm=_chatFrm;
55     try
56     {
57       jbInit() ;
58     }
59     catch (Exception JavaDoc e)
60     {
61       e.printStackTrace() ;
62     }
63   }
64
65   private void jbInit() throws Exception JavaDoc
66   {
67     jDialog1.setSize(new Dimension(150, 107)) ;
68     this.setSize(120, 220) ;
69     JlistAction.setModel(lm) ;
70     JlistAction.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc()
71     {
72       public void valueChanged(ListSelectionEvent e)
73       {
74         JlistAction_valueChanged(e) ;
75       }
76     }) ;
77     this.setResizable(false) ;
78     this.setUndecorated(true) ;
79     this.getContentPane().setLayout(borderLayout2) ;
80     jDialog1.setModal(true) ;
81     jPanel1.setLayout(null) ;
82     jButton_OK.setBounds(new Rectangle(46, 53, 55, 21)) ;
83     jButton_OK.setText("OK") ;
84     jButton_OK.addActionListener(new java.awt.event.ActionListener JavaDoc()
85     {
86       public void actionPerformed(ActionEvent e)
87       {
88         jButton_OK_actionPerformed(e) ;
89       }
90     }) ;
91     jt_Message.setText("") ;
92     jt_Message.setBounds(new Rectangle(4, 21, 141, 25)) ;
93     jPanel2.setLayout(borderLayout1) ;
94     jPanel2.setBorder(BorderFactory.createLineBorder(Color.gray)) ;
95     this.getContentPane().add(jPanel2, BorderLayout.CENTER) ;
96     jPanel2.add(JlistAction, BorderLayout.CENTER) ;
97     jDialog1.getContentPane().add(jPanel1, BorderLayout.CENTER) ;
98     jPanel1.add(jt_Message, null) ;
99     jPanel1.add(jButton_OK, null) ;
100     lm.addElement("\t X") ;
101     lm.addElement("userestremplaceapres") ;
102     lm.addElement("PrivMsg") ;
103     lm.addElement("Op") ;
104     lm.addElement("DeOp") ;
105     lm.addElement("HalfOp") ;
106     lm.addElement("DeHalfOp") ;
107     lm.addElement("Voice") ;
108     lm.addElement("DeVoice") ;
109     lm.addElement("Kick") ;
110     lm.addElement("Ban pour bientot") ;
111     lm.addElement("Whois") ;
112
113     JlistAction.setFont(new Font(IRCchan.FIXEDSYS.getName(), 0, 14)) ;
114
115   }
116
117   public void setUserForAction(String JavaDoc user)
118   {
119     lm.remove(1) ;
120     lm.insertElementAt("\t" + user, 1) ;
121   }
122
123   void JlistAction_valueChanged(ListSelectionEvent e)
124   {
125     if (!e.getValueIsAdjusting())
126     {
127       if (JlistAction.getSelectedIndex() == 0) //!index 0 pour fermer
128
{
129         this.setVisible(false) ;
130       }
131       else
132       {
133         if (JlistAction.getSelectedIndex() > 1) //car le 1 c le nick du user
134
{
135           ChanUser user = new ChanUser(lm.get(1).toString().trim()) ;
136           nick = user.getNameSansRank() ;
137           action = JlistAction.getSelectedValue().toString() ;
138
139           if (action.equals("PrivMsg"))
140           {
141               //aller chercher l objet dans le modele
142
if (user != null)
143               {
144                 //créer une fenetre de chat si nécessaire
145
PrivateFrame frm = IRCchan.GetFenetreDuPrive(nick) ;
146                 if (frm == null)
147                 {
148                   frm = IRCchan.createPrivateFrame(nick) ;
149                 }
150
151                chatFrm.setVisible(true);
152               }
153           }
154           else
155           {
156             if (action.equals("Op"))
157             {
158               IRCchan.sendCommand("MODE" + " " + chan + " " + "+o " + nick) ;
159             }
160             else
161             {
162               if (action.equals("DeOp"))
163               {
164                 IRCchan.sendCommand("MODE" + " " + chan + " " + "-o " + nick) ;
165               }
166               else
167               {
168                 if (action.equals("HalfOp"))
169                 {
170                   IRCchan.sendCommand("MODE" + " " + chan + " " + "+h " + nick) ;
171                 }
172                 else
173                 {
174                   if (action.equals("DeHalfOp"))
175                   {
176                     IRCchan.sendCommand("MODE" + " " + chan + " " + "-h " + nick) ;
177                   }
178                   else
179                   {
180                     if (action.equals("Voice"))
181                     {
182                       IRCchan.sendCommand("MODE" + " " + chan + " " + "+v " + nick) ;
183                     }
184                     else
185                     {
186                       if (action.equals("DeVoice"))
187                       {
188                         IRCchan.sendCommand("MODE" + " " + chan + " " + "-v " + nick) ;
189                       }
190                       else
191                       {
192                         if (action.equals("Kick"))
193                         {
194                           jDialog1.setLocationRelativeTo(this) ;
195                           jDialog1.setVisible(true) ;
196                         }
197                         else
198                         {
199                           if (action.equals("Ban"))
200                           {
201                             //@TODO
202
}
203                           else
204                           {
205                             if (action.equals("Whois"))
206                             {
207                               IRCchan.sendCommand("WHOIS" + " " + nick) ;
208                             }
209                           }
210                         }
211                       }
212                     }
213                   }
214                 }
215               }
216             }
217           }
218         }
219       }
220       JlistAction.clearSelection() ;
221       this.setVisible(false);
222     }
223   }
224
225   void traiteKick()
226   {
227     IRCchan.sendCommand("KICK" + " " + chan + " " + nick + " " + kickMSG) ;
228   }
229
230   void jButton_OK_actionPerformed(ActionEvent e)
231   {
232     kickMSG = jt_Message.getText().replaceAll(" ", "_") ;
233     jDialog1.setVisible(false) ;
234     traiteKick() ;
235   }
236 }
237
Popular Tags