1 3 package org.jgroups.demos.wb; 4 5 import java.awt.*; 6 import java.awt.event.ActionEvent ; 7 import java.awt.event.ActionListener ; 8 import org.jgroups.blocks.*; 9 10 11 12 public class SendDialog extends Dialog implements ActionListener { 13 private final TextArea msg=new TextArea(""); 14 private final Font default_font=new Font("Helvetica",Font.PLAIN,12); 15 private RpcDispatcher disp=null; 16 private String groupname=null; 17 private Node dest=null; 18 private String sender=null; 19 20 21 22 public SendDialog(Frame parent, Node dest, String src, RpcDispatcher disp, String groupname) { 23 super(parent, "Send message to " + dest.lbl + " at " + dest.addr, true); 24 25 Panel p1=new Panel(), p2=new Panel(); 26 Button send=new Button("Send"), send_all=new Button("Send to all"); 27 Button cancel=new Button("Cancel"); 28 29 this.disp=disp; 30 this.groupname=groupname; 31 this.dest=dest; 32 sender=src; 33 34 send.setFont(default_font); 35 send_all.setFont(default_font); 36 cancel.setFont(default_font); 37 msg.setFont(default_font); 38 39 p1.setLayout(new BorderLayout()); 40 p1.add(msg); 41 42 p2.setLayout(new FlowLayout()); 43 send.addActionListener(this); 44 send_all.addActionListener(this); 45 cancel.addActionListener(this); 46 p2.add(send); p2.add(send_all); p2.add(cancel); 47 48 add("Center", p1); 49 add("South", p2); 50 51 setSize(300, 150); 52 53 Point my_loc=parent.getLocation(); 54 my_loc.x+=50; 55 my_loc.y+=150; 56 setLocation(my_loc); 57 show(); 58 } 59 60 61 62 public String getMessage() { 63 String retval=msg.getText(); 64 return retval.length() > 0 ? retval : null; 65 } 66 67 68 public void actionPerformed(ActionEvent e) { 69 String command=e.getActionCommand(); 70 String retval=msg.getText(); 71 72 if(retval == null || retval.length() < 1) { 73 dispose(); 74 return; 75 } 76 77 try { 78 MethodCall call = new MethodCall("displayMessage", new Object [] {sender, retval}, 79 new String [] {String .class.getName(), String .class.getName()}); 80 if(command == "Send") 81 disp.callRemoteMethod(dest.addr, call, GroupRequest.GET_FIRST, 0); 82 else if(command == "Send to all") 83 disp.callRemoteMethods(null, call, GroupRequest.GET_ALL, 0); 84 } 85 catch(Exception ex) { 86 System.err.println(ex); 87 } 88 89 dispose(); 90 return; 91 } 92 93 94 } 95 | Popular Tags |