1 package zirc.gui ; 2 3 import java.util.* ; 4 import java.awt.* ; 5 import java.awt.event.* ; 6 import javax.swing.* ; 7 import javax.swing.border.* ; 8 import javax.swing.event.* ; 9 import zirc.base.* ; 10 11 24 31 32 public class ListDialog extends JDialog 33 { 34 private Locale language; 35 private DefaultListModel lm = new DefaultListModel() ; 36 private int nbOfChan = 0 ; 37 private JScrollPane jScrollPane1 = new JScrollPane() ; 38 private JPanel jPanel1 = new JPanel() ; 39 private IRCconnexion chatIRC ; 40 private BorderLayout borderLayout1 = new BorderLayout() ; 41 private JPanel jPanel2 = new JPanel() ; 42 private GridLayout gridLayout1 = new GridLayout() ; 43 private JButton jbCancel = new JButton() ; 44 private JButton jbJoin = new JButton() ; 45 private JPanel jPanel3 = new JPanel() ; 46 private JTextField jtChan = new JTextField() ; 47 private JList chanList = new JList() ; 48 private Border border1 ; 49 50 55 public ListDialog(Frame owner, IRCconnexion chatIRC, Locale _language) 56 { 57 super(owner) ; 58 this.chatIRC = chatIRC ; 59 language=_language; 60 setLanguage(language); 61 this.setFont(new Font(chatIRC.FIXEDSYS.getName(), 0, 15)) ; 62 try 63 { 64 jbInit() ; 65 } 66 catch (Exception e) 67 { 68 e.printStackTrace() ; 69 } 70 } 71 72 private void jbInit() throws Exception 73 { 74 75 border1 = BorderFactory.createLineBorder(Color.gray) ; 76 chanList.setModel(lm) ; 77 this.setTitle(chatIRC.GetUser_serverName() + " listing channels...") ; 78 this.setSize(new Dimension(270, 339)) ; 79 this.addWindowListener(new java.awt.event.WindowAdapter () 80 { 81 public void windowClosed(WindowEvent e) 82 { 83 this_windowClosed(e) ; 84 } 85 86 public void windowActivated(WindowEvent e) 87 { 88 this_windowActivated(e) ; 89 90 } 91 }) ; 92 this.getContentPane().setLayout(borderLayout1) ; 93 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE) ; 94 this.setModal(true) ; 95 this.setResizable(false) ; 96 jPanel1.setLayout(gridLayout1) ; 97 gridLayout1.setRows(2) ; 98 jbCancel.setBorder(border1) ; 99 jbCancel.setText("Annuler") ; 100 jbCancel.addActionListener(new java.awt.event.ActionListener () 101 { 102 public void actionPerformed(ActionEvent e) 103 { 104 jbCancel_actionPerformed(e) ; 105 } 106 }) ; 107 jbJoin.setBorder(border1) ; 108 jbJoin.setText("Joindre") ; 109 jbJoin.addActionListener(new java.awt.event.ActionListener () 110 { 111 public void actionPerformed(ActionEvent e) 112 { 113 jbJoin_actionPerformed(e) ; 114 } 115 }) ; 116 jtChan.setBorder(border1) ; 117 jtChan.setPreferredSize(new Dimension(this.getWidth() - 20, 21)) ; 118 jtChan.setText("") ; 119 jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) ; 120 jScrollPane1.setBorder(border1) ; 121 chanList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) ; 122 chanList.addListSelectionListener(new javax.swing.event.ListSelectionListener () 123 { 124 public void valueChanged(ListSelectionEvent e) 125 { 126 chanList_valueChanged(e) ; 127 } 128 }) ; 129 this.getContentPane().add(jScrollPane1, BorderLayout.CENTER) ; 130 jScrollPane1.getViewport().add(chanList, null) ; 131 this.getContentPane().add(jPanel1, BorderLayout.SOUTH) ; 132 jPanel2.add(jbCancel, null) ; 133 jPanel2.add(jbJoin, null) ; 134 jPanel1.add(jPanel3, null) ; 135 jPanel3.add(jtChan, null) ; 136 jPanel1.add(jPanel2, null) ; 137 chanList.setVisible(false) ; 138 this.setLocationRelativeTo(this.getOwner()) ; 139 } 140 141 150 void jbJoin_actionPerformed(ActionEvent e) 151 { 152 String tmp = "" ; 153 154 if (!jtChan.getText().substring(0, 1).equals("#")) 156 { 157 tmp = "#" ; 158 } 159 StringTokenizer str = new StringTokenizer(jtChan.getText(), " ") ; 160 chatIRC.sendCommand("join " + tmp + str.nextElement()) ; 161 this.setTitle(chatIRC.GetUser_serverName() + " listing channels...") ; 162 lm.clear() ; nbOfChan = 0 ; this.dispose() ; 165 } 166 167 175 void jbCancel_actionPerformed(ActionEvent e) 176 { 177 this.setTitle(chatIRC.GetUser_serverName() + " listing channels...") ; 178 lm.clear() ; nbOfChan = 0 ; this.dispose() ; 181 } 182 183 191 void this_windowClosed(WindowEvent e) 192 { 193 this.setTitle(chatIRC.GetUser_serverName() + " listing channels...") ; 194 lm.clear() ; nbOfChan = 0 ; } 197 198 204 void chanList_valueChanged(ListSelectionEvent e) 205 { 206 try 207 { 208 StringTokenizer str = new StringTokenizer(chanList.getSelectedValue().toString(), " ") ; 209 jtChan.setText(str.nextElement().toString()) ; 210 } 211 catch (NullPointerException ex) 212 {} 213 } 214 215 223 public void addChan(String line) 224 { 225 if (!line.equals("END")) 226 { 227 nbOfChan++ ; 228 lm.addElement(line) ; 229 chanList.setVisible(false) ; 230 chanList.setVisible(true) ; 231 } 232 else 233 { 234 Object [] list = new Object [lm.getSize()] ; 236 for (int i = 0 ; i < list.length ; i++) 237 { 238 list[i] = lm.getElementAt(i) ; 239 } 240 lm.clear() ; 241 Arrays.sort(list) ; 242 for (int i = 0 ; i < list.length ; i++) 243 { 244 lm.addElement(list[i]) ; 245 } 246 chanList.setVisible(false) ; 247 this.setTitle(chatIRC.GetUser_serverName() + " [" + nbOfChan + " channels]") ; 248 chanList.setVisible(true) ; 249 } 250 } 251 252 public void setLanguage(Locale lang) 253 { 254 ResourceBundle messages = ResourceBundle.getBundle("ListDialog", lang) ; 255 jbCancel.setText(messages.getString("jbcancel")) ; 256 jbJoin.setText(messages.getString("jbjoin")) ; 257 } 258 259 void this_windowActivated(WindowEvent e) 260 { 261 262 263 } 264 265 } 266 | Popular Tags |