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

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/samples/chat/client/CreateFrame.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.Dimension;
 
4
import java.awt.GridBagConstraints;
 
5
import java.awt.GridBagLayout;
 
6
import java.awt.Insets;
 
7
import java.awt.event.ActionEvent;
 
8
 
 
9
import javax.swing.JButton;
 
10
import javax.swing.JFrame;
 
11
import javax.swing.JLabel;
 
12
import javax.swing.JTextField;
 
13
 
 
14
import org.jboss.remoting.samples.chat.exceptions.CreateConnectionException;
 
15
 
 
16
/**
 
17
 * <p>Title: Chat</p>
 
18
 * <p>Description: </p>
 
19
 * <p>Copyright: Copyright (c) 2003</p>
 
20
 * <p>Company: </p>
 
21
 * @author not attributable 
 
22
 * @version 1.0
 
23
 */
 
24
 
 
25
interface CreateConnectionStrategy
 
26
{
 
27
    void createChat(String description, ChatMember owner)
 
28
        throws CreateConnectionException;
 
29
}
 
30
 
 
31
public class CreateFrame extends CloseableFrame {
 
32
  JLabel jDescriptionLabel = new JLabel();
 
33
  JLabel IDLabel = new JLabel();
 
34
  JTextField descriptionField = new JTextField();
 
35
  JTextField idField = new JTextField();
 
36
  JButton OKButton = new JButton();
 
37
  JButton CancelButton = new JButton();
 
38
  GridBagLayout gridBagLayout1 = new GridBagLayout();
 
39
 
 
40
  private CreateConnectionStrategy ccs;
 
41
 
 
42
  public CreateFrame(
 
43
      CreateConnectionStrategy ccs,
 
44
      Closeable parent)
 
45
  {
 
46
    super(parent);
 
47
    this.ccs = ccs;
 
48
 
 
49
    try {
 
50
      jbInit();
 
51
    }
 
52
    catch(Exception e) {
 
53
      e.printStackTrace();
 
54
    }
 
55
  }
 
56
 
 
57
  private void jbInit() throws Exception {
 
58
    jDescriptionLabel.setFont(new java.awt.Font("SansSerif", 1, 12));
 
59
    jDescriptionLabel.setText("Description:");
 
60
    this.getContentPane().setLayout(gridBagLayout1);
 
61
    IDLabel.setFont(new java.awt.Font("SansSerif", 1, 12));
 
62
    IDLabel.setText("Your ID:");
 
63
    descriptionField.setText("");
 
64
    idField.setText("");
 
65
    OKButton.setFont(new java.awt.Font("SansSerif", 1, 14));
 
66
    OKButton.setText("OK");
 
67
    OKButton.addActionListener(new CreateFrame_OKButton_actionAdapter(this));
 
68
    CancelButton.setFont(new java.awt.Font("SansSerif", 1, 14));
 
69
    CancelButton.setText("Cancel");
 
70
    CancelButton.addActionListener(new CreateFrame_CancelButton_actionAdapter(this));
 
71
    this.setLocale(java.util.Locale.getDefault());
 
72
    this.setResizable(false);
 
73
    this.setTitle("Create a chat room");
 
74
    this.setSize(new Dimension(00, 300));
 
75
    this.getContentPane().add(jDescriptionLabel,  new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
 
76
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(25, 21, 0, 0), 11, 4));
 
77
    this.getContentPane().add(IDLabel,  new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
 
78
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(11, 21, 0, 0), 27, 0));
 
79
    this.getContentPane().add(descriptionField,  new GridBagConstraints(2, 0, 2, 1, 1.0, 0.0
 
80
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(25, 0, 0, 16), 270, 1));
 
81
    this.getContentPane().add(OKButton,  new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0
 
82
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(81, 0, 115, 0), 30, -5));
 
83
    this.getContentPane().add(CancelButton,  new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
 
84
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(81, 27, 115, 103), 11, -2));
 
85
    this.getContentPane().add(idField, new GridBagConstraints(2, 1, 2, 1, 1.0, 0.0
 
86
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(9, 0, 0, 22), 272, 2));
 
87
 
 
88
    center();
 
89
    pack();
 
90
  }
 
91
 
 
92
  void OKButton_actionPerformed(ActionEvent e) {
 
93
    try
 
94
    {
 
95
      notifyOnClose(this);
 
96
      ChatMember chatMember = new ChatMember();
 
97
      chatMember.set_name(idField.getText());
 
98
      ccs.createChat(descriptionField.getText(),chatMember);
 
99
    }
 
100
    catch (CreateConnectionException cce)
 
101
    {
 
102
      System.out.println("OK button catches exception:");
 
103
      System.out.println(cce);
 
104
    }
 
105
  }
 
106
 
 
107
  void CancelButton_actionPerformed(ActionEvent e) {
 
108
    notifyOnClose(this);
 
109
  }
 
110
 
 
111
  public static void main(String[] args) {
 
112
     CreateFrame createFrame;
 
113
     try
 
114
     {
 
115
       createFrame = new CreateFrame(
 
116
                     new DummyCreateConnectionStrategy(),
 
117
                     null);
 
118
 
 
119
       createFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
120
       createFrame.show();
 
121
     }
 
122
     catch (CreateConnectionException ce)
 
123
     {
 
124
       System.out.println("unable to create create frame");
 
125
     }
 
126
   }
 
127
}
 
128
 
 
129
 
 
130
class CreateFrame_OKButton_actionAdapter implements java.awt.event.ActionListener {
 
131
  CreateFrame adaptee;
 
132
 
 
133
  CreateFrame_OKButton_actionAdapter(CreateFrame adaptee) {
 
134
    this.adaptee = adaptee;
 
135
  }
 
136
  public void actionPerformed(ActionEvent e) {
 
137
    adaptee.OKButton_actionPerformed(e);
 
138
  }
 
139
}
 
140
 
 
141
class CreateFrame_CancelButton_actionAdapter implements java.awt.event.ActionListener {
 
142
  CreateFrame adaptee;
 
143
 
 
144
  CreateFrame_CancelButton_actionAdapter(CreateFrame adaptee) {
 
145
    this.adaptee = adaptee;
 
146
  }
 
147
  public void actionPerformed(ActionEvent e) {
 
148
    adaptee.CancelButton_actionPerformed(e);
 
149
  }
 
150
}
 
151
 
 
152
class DummyCreateConnectionStrategy implements CreateConnectionStrategy
 
153
{
 
154
    public DummyCreateConnectionStrategy() throws CreateConnectionException
 
155
    {
 
156
        System.out.println("DummyCreateConnectionStrategy()");
 
157
    }
 
158
 
 
159
    public void createChat(String description, ChatMember owner)
 
160
        throws CreateConnectionException
 
161
    {
 
162
        System.out.println("description: " + description);
 
163
        System.out.println("nickName:    " + owner.get_name());
 
164
    }
 
165
}