Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: demo/tucson/chat/GUI.java


1   /*
2    * Chat TuCSoN Demo - Copyright (C) 2001 deis.unibo.it
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   */
18  package demo.tucson.chat;
19  
20  /**
21   * GUI Component used by Chat Agent to get input
22   * from user and to display new messages from the room
23   *
24   * @author  Alessandro Ricci
25   * 
26   */
27  public class GUI extends javax.swing.JFrame {
28  
29      /** Creates new form GUI */
30      public GUI() {
31          initComponents ();
32          pack ();
33      }
34  
35      /** This method is called from within the constructor to
36       * initialize the form.
37       * WARNING: Do NOT modify this code. The content of this method is
38       * always regenerated by the FormEditor.
39       */
40      private void initComponents() {//GEN-BEGIN:initComponents
41          jPanel1 = new javax.swing.JPanel();
42          jScrollPane1 = new javax.swing.JScrollPane();
43          output = new javax.swing.JTextArea();
44          jPanel2 = new javax.swing.JPanel();
45          input = new javax.swing.JTextField();
46          getContentPane().setLayout(new java.awt.GridBagLayout());
47          java.awt.GridBagConstraints gridBagConstraints1;
48          addWindowListener(new java.awt.event.WindowAdapter() {
49              public void windowClosing(java.awt.event.WindowEvent evt) {
50                  exitForm(evt);
51              }
52          }
53          );
54          
55          jPanel1.setLayout(new java.awt.GridBagLayout());
56          java.awt.GridBagConstraints gridBagConstraints2;
57          jPanel1.setBorder(new javax.swing.border.TitledBorder("output"));
58          
59          
60            output.setEditable(false);
61              output.setFont(new java.awt.Font ("Verdana", 0, 12));
62              jScrollPane1.setViewportView(output);
63              
64              gridBagConstraints2 = new java.awt.GridBagConstraints();
65            gridBagConstraints2.gridx = 0;
66            gridBagConstraints2.gridy = 0;
67            gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
68            gridBagConstraints2.weightx = 1.0;
69            gridBagConstraints2.weighty = 1.0;
70            jPanel1.add(jScrollPane1, gridBagConstraints2);
71            
72            
73          gridBagConstraints1 = new java.awt.GridBagConstraints();
74          gridBagConstraints1.gridx = 0;
75          gridBagConstraints1.gridy = 0;
76          gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
77          gridBagConstraints1.weightx = 1.0;
78          gridBagConstraints1.weighty = 1.0;
79          getContentPane().add(jPanel1, gridBagConstraints1);
80          
81          
82          jPanel2.setLayout(new java.awt.GridBagLayout());
83          java.awt.GridBagConstraints gridBagConstraints3;
84          jPanel2.setPreferredSize(new java.awt.Dimension(55, 60));
85          jPanel2.setBorder(new javax.swing.border.TitledBorder("input"));
86          
87          input.setPreferredSize(new java.awt.Dimension(2, 22));
88            input.setBorder(new javax.swing.border.LineBorder(java.awt.Color.black));
89            input.setFont(new java.awt.Font ("Verdana", 0, 12));
90            input.addActionListener(new java.awt.event.ActionListener() {
91                public void actionPerformed(java.awt.event.ActionEvent evt) {
92                    inputActionPerformed(evt);
93                }
94            }
95            );
96            gridBagConstraints3 = new java.awt.GridBagConstraints();
97            gridBagConstraints3.gridx = 0;
98            gridBagConstraints3.gridy = 0;
99            gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
100           gridBagConstraints3.weightx = 1.0;
101           jPanel2.add(input, gridBagConstraints3);
102           
103           
104         gridBagConstraints1 = new java.awt.GridBagConstraints();
105         gridBagConstraints1.gridx = 0;
106         gridBagConstraints1.gridy = 1;
107         gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
108         gridBagConstraints1.weightx = 1.0;
109         getContentPane().add(jPanel2, gridBagConstraints1);
110         
111     }//GEN-END:initComponents
112 
113   private void inputActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputActionPerformed
114     if (agent!=null){
115         agent.notifyNewMsg(input.getText());
116     }
117     input.setText("");
118   }//GEN-LAST:event_inputActionPerformed
119 
120     /** Exit the Application */
121     private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
122         if (agent!=null){
123             agent.notifyLeave();
124         }
125     }//GEN-LAST:event_exitForm
126 
127     public void notifyNewMsg(String who,String content){
128         output.append(who+">  "+content+"\n");
129         output.setCaretPosition(output.getText().length());
130 
131     }
132 
133 
134     public void setAgent(ChatAgent ag){
135         agent=ag;
136     }
137 
138     ChatAgent agent;
139     // Variables declaration - do not modify//GEN-BEGIN:variables
140     private javax.swing.JPanel jPanel1;
141     private javax.swing.JScrollPane jScrollPane1;
142     private javax.swing.JTextArea output;
143     private javax.swing.JPanel jPanel2;
144     private javax.swing.JTextField input;
145     // End of variables declaration//GEN-END:variables
146 
147 }