001    package stringtransformers;
002    
003    import cs101.lang.Animate;
004    import cs101.io.connection.*;
005    import cs101.io.Console;
006    import cs101.util.AnimateObject;
007    import cs101.util.gamecontrol.Initializable;
008    import java.awt.*;
009    import java.awt.event.*;
010    
011    public class StringInputter extends SimpleFrame
012                                implements OutputAcceptor, 
013                                           Initializable
014    
015    {
016      private OutputConnection out;
017      private TextField textField;
018    
019      private static int instanceNumber;
020      private final int myIndex;
021    
022      public StringInputter ()
023      {
024        super( new TextField( 20 ) );  // 40 = # columns
025    
026        this.myIndex = instanceNumber++;
027    
028        this.textField = (TextField) super.c;
029        this.textField.setEditable( false );
030        this.textField.addActionListener( new ActionListener() {
031          public void actionPerformed( ActionEvent e ) 
032          {
033            //      Console.println ("In:  Something happened!");
034            //      Console.println (StringInputter.this.textField.getText());
035            StringInputter.this.out.writeOutput( StringInputter.this.textField.getText() );
036            StringInputter.this.textField.selectAll();
037          }
038        });
039    
040        MouseListener mouseEars = TVConnectManager.getListener( this );
041        this.addMouseListener( mouseEars );
042        this.textField.addMouseListener ( mouseEars );
043    
044        this.setTitle( this.toString() );
045    
046        Console.println( this + " created");
047    
048      }
049    
050      public String toString()
051      {
052        return this.getClass().getName() + " #"+this.myIndex;
053      }
054    
055    
056      public void addOutputConnection( OutputConnection out ) 
057        throws ConnectionRejectedException
058      {
059        if ( this.out != null )
060        {
061          throw new 
062            ConnectionRejectedException ("Redundant output connection rejected" );
063        } 
064        else
065        {
066          this.out = out;
067          this.textField.setEditable( true );
068          Console.println( "SI:  Added output connection" );
069        }
070      }
071    }
072