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 zirc.msg.* ; 10 import zirc.threads.* ; 11 12 25 32 33 public class ChatFrame extends AbstractChatFrame 34 { 35 36 private final ImageIcon chatIMG = new ImageIcon("fichiers/images/chatIcon.png") ; 37 38 private String Chanel ; 40 41 private IRCconnexion IRCchat ; 43 44 ActionDialog ActionDLG ; 46 47 private JList userList = new JList() ; 49 private DefaultListModel lm = new DefaultListModel() ; 50 51 private JSplitPane splitPane = new JSplitPane() ; 52 private JScrollPane scrollPane = new JScrollPane() ; 53 54 private boolean departAnnonce = false ; 56 57 public ChatFrame(IRCconnexion _IRCchat, String _chan) 58 { 59 super(_IRCchat) ; 60 this.setFrameIcon(chatIMG) ; 61 IRCchat = _IRCchat ; 62 Chanel = _chan ; 63 this.setName(Chanel) ; 64 jPanel3.remove(jScrollPane1) ; 65 jPanel3.add(splitPane) ; 66 splitPane.setLeftComponent(jScrollPane1) ; 67 splitPane.setRightComponent(scrollPane) ; 68 jScrollPane1.setVerticalScrollBarPolicy(jScrollPane1.VERTICAL_SCROLLBAR_ALWAYS) ; 69 scrollPane.setHorizontalScrollBarPolicy(scrollPane.HORIZONTAL_SCROLLBAR_NEVER) ; 70 splitPane.setBorder(null) ; 71 scrollPane.getViewport().add(userList) ; 72 scrollPane.setBorder(null) ; 73 splitPane.setDividerLocation(this.getWidth() * 4 / 5) ; 74 splitPane.setDividerSize(4) ; 75 userList.setModel(lm) ; 76 userList.setBorder(BorderFactory.createLineBorder(Color.gray)) ; 77 userList.setFont(new Font(IRCchat.FIXEDSYS.getName(), 0, 15)) ; ActionDLG = new ActionDialog(IRCchat, this.getChan(), this) ; 79 userList.addListSelectionListener(new javax.swing.event.ListSelectionListener () 80 { 81 public void valueChanged(ListSelectionEvent e) 82 { 83 userList_valueChanged(e) ; 84 } 85 }) ; 86 87 splitPane.addComponentListener(new java.awt.event.ComponentAdapter () 88 { 89 public void componentResized(ComponentEvent e) 90 { 91 splitPane_componentResized(e) ; 92 } 93 }) ; 94 95 userList.addMouseListener(new java.awt.event.MouseAdapter () 96 { 97 public void mouseClicked(MouseEvent e) 98 { 99 userList_mouseClicked(e) ; 100 } 101 }) ; 102 } 103 104 void splitPane_componentResized(ComponentEvent e) 105 { 106 splitPane.setDividerLocation(this.getWidth() * 4 / 5) ; 107 } 108 109 public String getChan() 111 { 112 return Chanel ; 113 } 114 115 119 public void addNewUserInChan(String user) 121 { 122 IRCchat.ajouteTache(new AddUserInChanThread(this, user)) ; 123 } 124 125 public void addNewUserInChan(ChanUser user) 127 { 128 IRCchat.ajouteTache(new AddUserInChanThread(this, user)) ; 129 } 130 131 public void addUserListInChan(String users) 133 { 134 IRCchat.ajouteTache(new AddUserListInChanThread(this, users)) ; 135 } 136 137 public void removeUserFromChan(String user) 139 { 140 IRCchat.ajouteTache(new RemoveUserInChanThread(this, user)) ; 141 } 142 143 public DefaultListModel getListModel() 144 { 145 return lm ; 146 } 147 148 public void setListModel(DefaultListModel _lm) 149 { 150 userList.setModel(_lm) ; 151 } 152 153 private void userList_valueChanged(ListSelectionEvent e) 154 { 155 156 } 157 158 void this_internalFrameClosed(InternalFrameEvent e) 159 { 160 super.this_internalFrameClosed(e) ; 161 destroy() ; 162 } 163 164 public void destroy() 165 { 166 167 if (!departAnnonce) 169 { 170 IRCchat.sendCommand("PART " + this.getTitle() + " " + IRCchat.getPartMSG()) ; 171 } 172 173 IRCchat.removeChan(this) ; 174 175 try 176 { 177 setClosed(true) ; 178 } 179 catch (java.beans.PropertyVetoException e) 180 { 181 System.out.println("propertyVeto...") ; 182 } 183 } 184 185 public void destroyForKick() 186 { 187 IRCchat.removeChan(this) ; 188 189 try 190 { 191 setClosed(true) ; 192 } 193 catch (java.beans.PropertyVetoException e) 194 { 195 System.out.println("propertyVeto...") ; 196 } 197 } 198 199 public void setDepartAnnonce(boolean _flag) 201 { 202 departAnnonce = _flag ; 203 } 204 205 void jTextField1_actionPerformed(ActionEvent e) 206 { 207 String txt = jTextField1.getText() ; 208 209 if (txt.length() > 0) 210 { 211 212 if (txt.charAt(0) == '/') 213 { 214 216 System.err.println(txt.substring(0, 4)) ; 217 if (txt.length() > 3 && txt.substring(0, 4).equalsIgnoreCase("/msg")) 219 { 220 IRCchat.sendCommand("PRIV" + txt.substring(1)) ; 221 } 222 else 223 { 224 if (txt.length() > 3 && txt.substring(0, 4).equalsIgnoreCase("/ctcp")) 225 { IRCchat.sendCommand("PRIVMSG " + txt.substring(5)) ; 227 } 228 else 229 { 230 IRCchat.sendCommand(txt.substring(1)) ; 231 } 232 } 233 } 234 else 235 { 236 String send = "PRIVMSG " + Chanel + " :" + txt ; 238 IRCchat.sendCommand(send) ; 239 240 MSGprivMsg msg = new MSGprivMsg(IRCchat, ":" + IRCchat.GetUser_nickName() + "!", Chanel, send) ; 242 msg.reagit() ; 243 msg.affiche() ; 244 } 245 } 246 247 jTextField1.setText("") ; 248 249 } 250 251 public void userList_mouseClicked(MouseEvent e) 252 { 253 ActionDLG.setLocationRelativeTo(userList) ; 254 ActionDLG.setLocation(ActionDLG.getX() + ActionDLG.getWidth() / 2, ActionDLG.getY()) ; 255 ActionDLG.setUserForAction(userList.getSelectedValue().toString()) ; 256 ActionDLG.setVisible(true) ; 257 } 258 259 public JList getUserList() 260 { 261 return userList ; 262 } 263 264 void this_internalFrameActivated(InternalFrameEvent e) 266 { 267 super.this_internalFrameActivated(e) ; 268 splitPane.setDividerLocation(this.getWidth() * 4 / 5) ; 269 } 270 } 271 | Popular Tags |