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

Quick Search    Search Deep

Source code: com/synaptics/elvis/ElvisTest.java


1   /*
2    * The contents of this file are subject to the Mozilla Public License Version 
3    * 1.1 (the "License"); you may not use this file except in compliance with the 
4    * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
5    *
6    * Software distributed under the License is distributed on an "AS IS" basis, 
7    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
8    * the specific language governing rights and limitations under the License.
9    *
10   * The Original Code is com.synaptics.elvis code.
11   *
12   * The Initial Developers of the Original Code are Synaptics, Inc. and Christopher Heiny.
13   * Portions created by Synaptics, Inc. and Christopher Heiny are
14   * Copyright (C) 2002 Synaptics, Inc. and Christopher Heiny. All Rights Reserved.
15   *
16   * Contributor(s):
17   *    Christopher Heiny <cheiny@synaptics.com>
18   */
19  
20  package com.synaptics.elvis;
21  
22  /** This is a handy dandy test program to verify the basic functionality of Elvis.
23   * Start it once, and it becomes the One True Elvis.  Start it agin while the first
24   * instance is still running, and it will discover that first instance and send it
25   * some test requests.
26   * <P>
27   * This program was created using Forte for Java CE 3.0.  I highly recommend you
28   * use the same tool if you modify this program.
29   *
30   * @author  cheiny
31   * @version $Id: ElvisTest.java,v 1.1 2002/05/09 07:17:17 clheiny Exp $
32   */
33  public class ElvisTest extends javax.swing.JFrame {
34  
35      /** Creates new form ElvisTest */
36      public ElvisTest() {
37          initComponents();
38      }
39  
40      /** This method is called from within the constructor to
41       * initialize the form.
42       * WARNING: Do NOT modify this code. The content of this method is
43       * always regenerated by the Form Editor.
44       */
45      private void initComponents() {//GEN-BEGIN:initComponents
46          scrollPane = new javax.swing.JScrollPane();
47          log = new javax.swing.JTextArea();
48          exitButton = new javax.swing.JButton();
49          msg = new javax.swing.JLabel();
50          
51          getContentPane().setLayout(new java.awt.GridBagLayout());
52          java.awt.GridBagConstraints gridBagConstraints1;
53          
54          setTitle("Elvis Test 0.1");
55          addWindowListener(new java.awt.event.WindowAdapter() {
56              public void windowClosing(java.awt.event.WindowEvent evt) {
57                  exitForm(evt);
58              }
59          });
60          
61          log.setEditable(false);
62          log.setFont(new java.awt.Font("Monospaced", 0, 12));
63          scrollPane.setViewportView(log);
64          
65          gridBagConstraints1 = new java.awt.GridBagConstraints();
66          gridBagConstraints1.gridx = 0;
67          gridBagConstraints1.gridy = 0;
68          gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
69          gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST;
70          gridBagConstraints1.weightx = 1.0;
71          gridBagConstraints1.weighty = 1.0;
72          getContentPane().add(scrollPane, gridBagConstraints1);
73          
74          exitButton.setText("Exit");
75          exitButton.setToolTipText("Quit the Elvis tester...");
76          exitButton.addActionListener(new java.awt.event.ActionListener() {
77              public void actionPerformed(java.awt.event.ActionEvent evt) {
78                  exitButtonActionPerformed(evt);
79              }
80          });
81          
82          gridBagConstraints1 = new java.awt.GridBagConstraints();
83          gridBagConstraints1.gridx = 0;
84          gridBagConstraints1.gridy = 1;
85          getContentPane().add(exitButton, gridBagConstraints1);
86          
87          msg.setFont(new java.awt.Font("Dialog", 0, 10));
88          msg.setText(" ");
89          gridBagConstraints1 = new java.awt.GridBagConstraints();
90          gridBagConstraints1.gridx = 0;
91          gridBagConstraints1.gridy = 2;
92          gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
93          getContentPane().add(msg, gridBagConstraints1);
94          
95          pack();
96      }//GEN-END:initComponents
97  
98      private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
99          System.exit(0);
100     }//GEN-LAST:event_exitButtonActionPerformed
101 
102     /** Exit the Application */
103     private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
104         System.exit(0);
105     }//GEN-LAST:event_exitForm
106 
107     /**
108     * @param args the command line arguments
109     */
110     public static void main(String args[]) {
111         ElvisTest me = new ElvisTest();
112         
113         me.setSize ( 400, 400 );
114         me.show();
115         
116         Elvis myElvis = null;
117         try {
118             myElvis = Elvis.get ( "ElvisTest", 14568, me.handler, me.feedbackListener );
119         } catch ( Exception e ) {
120             javax.swing.JOptionPane.showMessageDialog ( me, "Unable to get Elvis: " + e.getMessage(), "Elvis Test Error",
121                 javax.swing.JOptionPane.ERROR_MESSAGE );
122             me.log.append ( "Unable to get Elvis: " + e.getMessage() + "\n" );
123         }
124         if ( myElvis == null ) {
125             me.log.append ( "We failed to get ahold of Elvis.  You might as well quit now.\n" );
126         }
127         else {
128             me.log.append ( "We have contacted Elvis!\n" );
129             if ( myElvis.isTheOneTrueElvis() ) {
130                 me.log.append ( "And he is the one true Elvis!\n" );
131             }
132             else {
133                 me.log.append ( "However, he appears to be an impersonator.\n" );
134             }
135             myElvis.perform ( "Blue Suede Shoes" );
136             myElvis.perform ( "Jailhouse Rock" );
137         }
138     }
139     
140     /** This is used to monitor and report feedback from Elvis.
141      */
142     private class FeedbackListener implements java.beans.PropertyChangeListener {        
143         public void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent) {
144             Elvis e = (Elvis) propertyChangeEvent.getSource();
145             msg.setText ( e.getFeedback() );
146         }
147         
148     }
149 
150     public class TestHandler implements ElvisHandler {
151         
152         private ElvisTest parent = null;
153         
154         public TestHandler(ElvisTest parent) {
155             this.parent = parent;
156         }
157         
158         public ElvisResult perform(String data) {
159             parent.log.append( "Internal Elvis handler called with data " + data + "\n" );
160             return ElvisResult.succeed( "Thankyouverrrmuch" );
161         }
162         
163     }
164     
165     private TestHandler handler = new TestHandler( this );
166     
167     private FeedbackListener feedbackListener = new FeedbackListener();
168     
169     // Variables declaration - do not modify//GEN-BEGIN:variables
170     private javax.swing.JScrollPane scrollPane;
171     private javax.swing.JTextArea log;
172     private javax.swing.JButton exitButton;
173     private javax.swing.JLabel msg;
174     // End of variables declaration//GEN-END:variables
175 
176 }