01: // $Id: SendDialog.java,v 1.6 2006/02/16 08:22:36 belaban Exp $
02:
03: package org.jgroups.demos.wb;
04:
05: import org.jgroups.blocks.GroupRequest;
06: import org.jgroups.blocks.MethodCall;
07: import org.jgroups.blocks.RpcDispatcher;
08:
09: import java.awt.*;
10: import java.awt.event.ActionEvent;
11: import java.awt.event.ActionListener;
12:
13: public class SendDialog extends Dialog implements ActionListener {
14: private final TextArea msg = new TextArea("");
15: private final Font default_font = new Font("Helvetica", Font.PLAIN,
16: 12);
17: private RpcDispatcher disp = null;
18: private Node dest = null;
19: private String sender = null;
20:
21: public SendDialog(Frame parent, Node dest, String src,
22: RpcDispatcher disp) {
23: super (parent, "Send message to " + dest.lbl + " at "
24: + dest.addr, true);
25:
26: Panel p1 = new Panel(), p2 = new Panel();
27: Button send = new Button("Send"), send_all = new Button(
28: "Send to all");
29: Button cancel = new Button("Cancel");
30:
31: this .disp = disp;
32: this .dest = dest;
33: sender = src;
34:
35: send.setFont(default_font);
36: send_all.setFont(default_font);
37: cancel.setFont(default_font);
38: msg.setFont(default_font);
39:
40: p1.setLayout(new BorderLayout());
41: p1.add(msg);
42:
43: p2.setLayout(new FlowLayout());
44: send.addActionListener(this );
45: send_all.addActionListener(this );
46: cancel.addActionListener(this );
47: p2.add(send);
48: p2.add(send_all);
49: p2.add(cancel);
50:
51: add("Center", p1);
52: add("South", p2);
53:
54: setSize(300, 150);
55:
56: Point my_loc = parent.getLocation();
57: my_loc.x += 50;
58: my_loc.y += 150;
59: setLocation(my_loc);
60: show();
61: }
62:
63: public String getMessage() {
64: String retval = msg.getText();
65: return retval.length() > 0 ? retval : null;
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",
79: new Object[] { sender, retval }, new String[] {
80: String.class.getName(),
81: String.class.getName() });
82: if (command.equals("Send"))
83: disp.callRemoteMethod(dest.addr, call,
84: GroupRequest.GET_FIRST, 0);
85: else if (command.equals("Send to all"))
86: disp.callRemoteMethods(null, call,
87: GroupRequest.GET_ALL, 0);
88: } catch (Throwable ex) {
89: System.err.println(ex);
90: }
91:
92: dispose();
93: }
94:
95: }
|