private void register() { if (session != null && session.isConnected()) { onlineUsers.clear(); // get the current list Message msg = session.sendMessage("", "list", ""); System.out.println("LIST: " + msg.getBody()); StringTokenizer st = new StringTokenizer(msg.getBody(), "\n"); while (st.hasMoreTokens()) { onlineUsers.addElement(new HostItem(st.nextToken())); } session.postMessage("", "register", ""); } }
public void receiveMsg(Message msg) { // System.out.println(msg.getSubject() + " : " + msg.getBody()); String subject = msg.getSubject(); if (subject != null) { if (subject.equals("online")) { onlineUsers.addElement(new HostItem(msg.getBody())); displayMessage(msg.getBody() + " : Online", onlineClientAttrSet); } else if (subject.equals("offline")) { onlineUsers.removeElement(new HostItem(msg.getBody())); displayMessage(msg.getBody() + " : Offline", offlineClientAttrSet); } else if (subject.equals("eavesdrop enabled")) { Object[] values = jListOnlineUsers.getSelectedValues(); if (values == null) return; for (int i = 0; i < values.length; i++) { ((HostItem) values[i]).eavesDroppingEnabled = true; } jListOnlineUsers.updateUI(); } else if (subject.equals("eavesdrop disabled")) { Object[] values = jListOnlineUsers.getSelectedValues(); if (values == null) return; for (int i = 0; i < values.length; i++) { ((HostItem) values[i]).eavesDroppingEnabled = false; } jListOnlineUsers.updateUI(); } else if (subject.equals("globaleavesdrop enabled")) { displayMessage("Global Eavesdropping Enabled", onlineClientAttrSet); } else if (subject.equals("globaleavesdrop disabled")) { displayMessage("Global Eavesdropping Disabled", offlineClientAttrSet); } else { String to = msg.getTo(); String from = msg.getFrom() == null ? "server" : msg.getFrom(); String body = msg.getBody() != null ? msg.getBody() : ""; if (jTextFieldUser.getText().equals(to)) { // this message is sent to us displayMessage(subject, from, body, incomingMsgAttrSet); } else { // this is an eavesdrop message displayMessage(subject, to, from, body, eavesdropAttrSet); } } } else { subject = ""; String to = msg.getTo(); String from = msg.getFrom() == null ? "server" : msg.getFrom(); String body = msg.getBody() != null ? msg.getBody() : ""; if (jTextFieldUser.getText().equals(to)) { // this message is sent to us displayMessage(subject, from, body, incomingMsgAttrSet); } else { // this is an eavesdrop message displayMessage(subject, to, from, body, eavesdropAttrSet); } } }
private void disconnect() { if (session != null && session.isConnected()) { session.disconnect(); } jToggleButtonConnect.setSelected(false); jToggleButtonConnect.setText("Connect"); jToggleButtonRegister.setSelected(false); onlineUsers.clear(); jToggleButtonRegister.setText("Register"); }
public void addElement(Object o) { Comparable a = (Comparable) o; int i = 0; for (i = 0; i < getSize(); i++) { if (a.compareTo(getElementAt(i)) < 0) { break; } } super.add(i, o); }
private void deregister() { onlineUsers.clear(); if (session != null && session.isConnected()) { session.postMessage("", "deregister", ""); } }
public void setElements(Vector v) { clear(); Object arr[] = v.toArray(); Arrays.sort(arr); for (int i = 0; i < arr.length; i++) super.addElement(arr[i]); }