1 package org.lucane.applications.reunion.ui; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Dimension ; 5 import java.awt.event.ActionEvent ; 6 import java.awt.event.ActionListener ; 7 import java.awt.event.KeyEvent ; 8 import java.awt.event.KeyListener ; 9 import java.awt.event.WindowEvent ; 10 import java.awt.event.WindowListener ; 11 import java.util.Iterator ; 12 import java.util.Enumeration ; 13 import java.util.Vector ; 14 15 import javax.swing.DefaultListModel ; 16 import javax.swing.JButton ; 17 import javax.swing.JList ; 18 import javax.swing.JPanel ; 19 import javax.swing.JScrollPane ; 20 import javax.swing.JSplitPane ; 21 22 import org.lucane.applications.reunion.Reunion; 23 import org.lucane.applications.reunion.ReunionMessage; 24 import org.lucane.applications.reunion.ReunionUserProperties; 25 import org.lucane.applications.reunion.ReunionUsersProperties; 26 import org.lucane.client.Client; 27 import org.lucane.client.Communicator; 28 import org.lucane.client.widgets.HTMLEditor; 29 import org.lucane.client.widgets.ListBox; 30 import org.lucane.client.widgets.ManagedWindow; 31 import org.lucane.common.ConnectInfo; 32 33 public class MainWindow extends ManagedWindow 34 implements WindowListener , ActionListener , KeyListener 35 { 36 private Reunion plugin; 37 38 private HTMLEditor messages; 39 private HTMLEditor write; 40 private JList users; 41 private JButton btnInvite; 42 43 public MainWindow(Reunion plugin, boolean starter) 44 { 45 super(plugin, plugin.getSubject()); 46 this.plugin = plugin; 47 48 setName("frame"); 49 addWindowListener(this); 50 setPreferredSize(new Dimension (640, 480)); 51 getContentPane().setLayout(new BorderLayout ()); 52 53 this.messages = new HTMLEditor(); 54 messages.setEditable(false); 55 messages.setToolbarVisible(false); 56 57 this.users = new JList (new DefaultListModel ()); 58 this.users.setCellRenderer(new UserRenderer(plugin)); 59 60 JPanel listContainer = new JPanel (new BorderLayout ()); 61 if(starter) 62 { 63 btnInvite = new JButton (plugin.tr("btn.invite"), plugin.getImageIcon("invite.png")); 64 btnInvite.addActionListener(this); 65 listContainer.add(btnInvite, BorderLayout.NORTH); 66 } 67 listContainer.add(new JScrollPane (users), BorderLayout.CENTER); 68 69 JSplitPane split = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, 70 new JScrollPane (messages), listContainer); 71 split.setResizeWeight(1); 72 split.setDividerLocation(520); 73 this.manageWidget(split); 74 getContentPane().add(split, BorderLayout.CENTER); 75 76 messages.addHTML(ReunionMessage.createHTMLInfoMessage(plugin, 77 plugin.tr("subjectMsg") + plugin.getSubject())); 78 79 80 this.write = new HTMLEditor(); 81 write.getEditorPane().addKeyListener(this); 82 getContentPane().add(write, BorderLayout.SOUTH); 83 } 84 85 public void addUser(ReunionUserProperties props) 86 { 87 ((DefaultListModel )users.getModel()).addElement(props); 89 } 90 91 public void removeUser(ReunionUserProperties props) 92 { 93 ((DefaultListModel )users.getModel()).removeElement(props); 94 } 95 96 public void setUsers(ReunionUsersProperties props) 97 { 98 ((DefaultListModel )users.getModel()).clear(); 99 Iterator users = props.getUsers(); 100 while(users.hasNext()) 101 { 102 addUser(props.getUserProperties((String )users.next())); 103 } 104 } 105 106 public void pushMessage(String html) 107 { 108 messages.addHTML(html); 109 } 110 111 public void removeListeners() 112 { 113 this.write.removeKeyListener(this); 114 } 115 116 public void windowActivated(WindowEvent e) {} 118 public void windowClosed(WindowEvent e) {} 119 public void windowDeactivated(WindowEvent e) {} 120 public void windowDeiconified(WindowEvent e) {} 121 public void windowIconified(WindowEvent e) {} 122 public void windowOpened(WindowEvent e) {} 123 public void windowClosing(WindowEvent we) 124 { 125 plugin.closeMeeting(); 126 } 127 128 public void actionPerformed(ActionEvent ae) 130 { 131 Vector userList = new Vector (Client.getInstance().getUserList()); 132 System.out.println("1. " + userList); 133 Enumeration props = ((DefaultListModel )users.getModel()).elements(); 134 while(props.hasMoreElements()) 135 { 136 ReunionUserProperties user = (ReunionUserProperties)props.nextElement(); 137 userList.remove(user.getUser()); 138 } 139 140 ListBox listBox = new ListBox(null, getTitle(), plugin.tr("msg.selectUsers"), userList); 141 Object [] users = listBox.selectItems(); 142 143 if(users != null) 144 { 145 for(int i=0;i<users.length;i++) 146 { 147 ConnectInfo ci = Communicator.getInstance().getConnectInfo((String )users[i]); 148 plugin.inviteUser(ci); 149 } 150 } 151 } 152 153 public void keyReleased(KeyEvent e) {} 155 public void keyTyped(KeyEvent e) {} 156 public void keyPressed(KeyEvent ke) 157 { 158 if(ke.getKeyCode() == KeyEvent.VK_ENTER) 159 { 160 ke.consume(); 161 if(write.getText().equals("")) 162 return; 163 164 plugin.sendTextMessage(write.getText()); 165 write.clear(); 166 } 167 } 168 } | Popular Tags |