Package jay.yydebug

Class yyJInputStream

  • All Implemented Interfaces:
    java.awt.event.KeyListener, java.io.Closeable, java.lang.AutoCloseable, java.util.EventListener

    public class yyJInputStream
    extends java.io.InputStream
    implements java.awt.event.KeyListener
    used to reroute standard input from a JTextArea. Feeds all read methods from listening to typed keys. Should not deadlock because one should generally not read from within the event thread.

    While this implementation avoids Java generics, code for a generic version has simply been commented out.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.StringBuffer line
      line edit buffer.
      protected java.util.ArrayList queue
      completed lines, ready to be read.
    • Constructor Summary

      Constructors 
      Constructor Description
      yyJInputStream()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      protected void doKey​(javax.swing.JTextArea ta, char ch, boolean paste)
      process one typed or pasted character.
      void keyPressed​(java.awt.event.KeyEvent ke)
      this one ensures that you can only type at the end and implements control-C as copy and control-V as paste key if AWTPermission(accessClipboard) is granted.
      void keyReleased​(java.awt.event.KeyEvent ke)  
      void keyTyped​(java.awt.event.KeyEvent ke)  
      int read()  
      int read​(byte[] b, int off, int len)  
      long skip​(long len)
      returns 0: cannot skip on a terminal.
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • line

        protected final java.lang.StringBuffer line
        line edit buffer.
      • queue

        protected java.util.ArrayList queue
        completed lines, ready to be read. Invariant: null after close().
    • Constructor Detail

      • yyJInputStream

        public yyJInputStream()
    • Method Detail

      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long len)
        returns 0: cannot skip on a terminal.
        Overrides:
        skip in class java.io.InputStream
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent ke)
        this one ensures that you can only type at the end and implements control-C as copy and control-V as paste key if AWTPermission(accessClipboard) is granted. This is executed within the event thread.

        BUG: paste should be based on the platform paste key; however, Safari does not send that one to an applet.

        Specified by:
        keyPressed in interface java.awt.event.KeyListener
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent ke)
        Specified by:
        keyTyped in interface java.awt.event.KeyListener
      • doKey

        protected void doKey​(javax.swing.JTextArea ta,
                             char ch,
                             boolean paste)
        process one typed or pasted character. The caret position is not updated for pasting.
      • keyReleased

        public void keyReleased​(java.awt.event.KeyEvent ke)
        Specified by:
        keyReleased in interface java.awt.event.KeyListener