~ubuntu-branches/ubuntu/oneiric/libjboss-remoting-java/oneiric

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/samples/chat/client/JoinFrame.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jboss.remoting.samples.chat.client;
 
2
 
 
3
import java.awt.GridBagConstraints;
 
4
import java.awt.GridBagLayout;
 
5
import java.awt.Insets;
 
6
import java.awt.event.ActionEvent;
 
7
import java.util.Date;
 
8
 
 
9
import javax.swing.JButton;
 
10
import javax.swing.JLabel;
 
11
import javax.swing.JTextField;
 
12
 
 
13
import org.jboss.remoting.samples.chat.exceptions.JoinConnectionException;
 
14
 
 
15
/**
 
16
 * <p>Title: Chat4</p>
 
17
 * <p>Description: </p>
 
18
 * <p>Copyright: Copyright (c) 2003</p>
 
19
 * <p>Company: </p>
 
20
 * @author not attributable
 
21
 * @version 1.0
 
22
 */
 
23
 
 
24
interface JoinConnectionStrategy
 
25
{
 
26
    void join(ChatInfo chatInfo, ChatMember newMember)
 
27
        throws JoinConnectionException;
 
28
}  
 
29
 
 
30
 
 
31
public class JoinFrame extends CloseableFrame {
 
32
  JLabel jLabel1 = new JLabel();
 
33
  JTextField IDField = new JTextField();
 
34
  JButton OKButton = new JButton();
 
35
  JButton CancelButton = new JButton();
 
36
 
 
37
  private ChatInfo chatInfo;
 
38
  private JoinConnectionStrategy jcs;
 
39
  GridBagLayout gridBagLayout1 = new GridBagLayout();
 
40
 
 
41
 
 
42
  public JoinFrame(
 
43
      ChatInfo chatInfo,
 
44
      JoinConnectionStrategy jcs,
 
45
      Closeable parent)
 
46
  {
 
47
    super(parent);
 
48
    this.chatInfo = chatInfo;
 
49
    this.jcs = jcs;
 
50
 
 
51
    try {
 
52
      jbInit();
 
53
    }
 
54
    catch(Exception e) {
 
55
      e.printStackTrace();
 
56
    }
 
57
  }
 
58
 
 
59
 
 
60
  private void jbInit() throws Exception {
 
61
    jLabel1.setFont(new java.awt.Font("SansSerif", 1, 12));
 
62
    jLabel1.setText("Your ID:");
 
63
    this.getContentPane().setLayout(gridBagLayout1);
 
64
    IDField.setText("");
 
65
    OKButton.setFont(new java.awt.Font("SansSerif", 1, 12));
 
66
    OKButton.setText("OK");
 
67
    OKButton.addActionListener(new JoinFrame_OKButton_actionAdapter(this));
 
68
    CancelButton.setFont(new java.awt.Font("SansSerif", 1, 12));
 
69
    CancelButton.setText("Cancel");
 
70
    CancelButton.addActionListener(new JoinFrame_CancelButton_actionAdapter(this));
 
71
    this.setTitle("Join a Chat Room");
 
72
    this.getContentPane().add(jLabel1,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
 
73
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(96, 82, 0, 0), 22, 5));
 
74
    this.getContentPane().add(IDField,  new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0
 
75
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(96, 0, 0, 39), 215, 0));
 
76
    this.getContentPane().add(CancelButton,  new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
 
77
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(47, 16, 43, 139), 0, 0));
 
78
    this.getContentPane().add(OKButton,  new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
 
79
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(49, 108, 43, 0), 22, 0));
 
80
 
 
81
    pack();
 
82
    center();
 
83
  }
 
84
 
 
85
 
 
86
  public static void main(String[] args)
 
87
  {
 
88
      try
 
89
      {
 
90
        ChatMember chatMember = new ChatMember();
 
91
        chatMember.set_name("xyz");
 
92
        ChatInfo chatInfo = new ChatInfo();
 
93
        chatInfo.set_currentMembers(3);
 
94
        chatInfo.set_description("abc");
 
95
        chatInfo.set_origin(new Date());
 
96
          JoinFrame joinFrame = new JoinFrame(
 
97
                          chatInfo,
 
98
                          new DummyJoinConnectionStrategy(),
 
99
                          null);
 
100
          joinFrame.show();
 
101
      }
 
102
      catch (JoinConnectionException ce)
 
103
      {
 
104
          System.out.println("unable to create chat frame");
 
105
      }
 
106
  }
 
107
 
 
108
  void OKButton_actionPerformed(ActionEvent e) {
 
109
    try
 
110
    {
 
111
        notifyOnClose(this);
 
112
        ChatMember chatMember = new ChatMember();
 
113
        chatMember.set_name(IDField.getText());
 
114
        jcs.join(chatInfo, chatMember);
 
115
    }
 
116
    catch (JoinConnectionException jce)
 
117
    {
 
118
        System.out.println("OK button catches exception:");
 
119
        System.out.println(jce);
 
120
    }
 
121
  }
 
122
 
 
123
  void CancelButton_actionPerformed(ActionEvent e) {
 
124
        notifyOnClose(this);
 
125
  }
 
126
 
 
127
}
 
128
 
 
129
 
 
130
class DummyJoinConnectionStrategy implements JoinConnectionStrategy
 
131
{
 
132
    public DummyJoinConnectionStrategy() throws JoinConnectionException
 
133
    {
 
134
        System.out.println("DummyJoinConnectionStrategy()");
 
135
    }
 
136
 
 
137
    public void join(ChatInfo chatInfo, ChatMember newMember) throws JoinConnectionException
 
138
    {
 
139
        System.out.println("DummyJoinConnectionStrategy.getId(" + chatInfo.get_key() + ", " + newMember.get_name() + ")");
 
140
    }
 
141
}
 
142
 
 
143
class JoinFrame_OKButton_actionAdapter implements java.awt.event.ActionListener {
 
144
  JoinFrame adaptee;
 
145
 
 
146
  JoinFrame_OKButton_actionAdapter(JoinFrame adaptee) {
 
147
    this.adaptee = adaptee;
 
148
  }
 
149
  public void actionPerformed(ActionEvent e) {
 
150
    adaptee.OKButton_actionPerformed(e);
 
151
  }
 
152
}
 
153
 
 
154
class JoinFrame_CancelButton_actionAdapter implements java.awt.event.ActionListener {
 
155
  JoinFrame adaptee;
 
156
 
 
157
  JoinFrame_CancelButton_actionAdapter(JoinFrame adaptee) {
 
158
    this.adaptee = adaptee;
 
159
  }
 
160
  public void actionPerformed(ActionEvent e) {
 
161
    adaptee.CancelButton_actionPerformed(e);
 
162
  }
 
163
}