Class InputDecoder


  • public class InputDecoder
    extends java.lang.Object
    Used to read the input stream character by character and generate Key objects to be put in the input queue.
    • Constructor Summary

      Constructors 
      Constructor Description
      InputDecoder​(java.io.Reader source)
      Creates a new input decoder using a specified Reader as the source to read characters from
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addProfile​(KeyDecodingProfile profile)
      Adds another key decoding profile to this InputDecoder, which means all patterns from the profile will be used when decoding input.
      private CharacterPattern.Matching getBestMatch​(java.util.List<java.lang.Character> characterSequence)  
      KeyStroke getNextCharacter​(boolean blockingIO)
      Reads and decodes the next key stroke from the input stream
      java.util.Collection<CharacterPattern> getPatterns()
      Returns a collection of all patterns registered in this InputDecoder.
      int getTimeoutUnits()
      queries the current timeoutUnits value.
      boolean removePattern​(CharacterPattern pattern)
      Removes one pattern from the list of patterns in this InputDecoder
      void setTimeoutUnits​(int units)
      Sets the number of 1/4-second units for how long to try to get further input to complete an escape-sequence for a special Key.
      • Methods inherited from class java.lang.Object

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

      • source

        private final java.io.Reader source
      • currentMatching

        private final java.util.List<java.lang.Character> currentMatching
      • seenEOF

        private boolean seenEOF
      • timeoutUnits

        private int timeoutUnits
    • Constructor Detail

      • InputDecoder

        public InputDecoder​(java.io.Reader source)
        Creates a new input decoder using a specified Reader as the source to read characters from
        Parameters:
        source - Reader to read characters from, will be wrapped by a BufferedReader
    • Method Detail

      • addProfile

        public void addProfile​(KeyDecodingProfile profile)
        Adds another key decoding profile to this InputDecoder, which means all patterns from the profile will be used when decoding input.
        Parameters:
        profile - Profile to add
      • getPatterns

        public java.util.Collection<CharacterPattern> getPatterns()
        Returns a collection of all patterns registered in this InputDecoder.
        Returns:
        Collection of patterns in the InputDecoder
      • removePattern

        public boolean removePattern​(CharacterPattern pattern)
        Removes one pattern from the list of patterns in this InputDecoder
        Parameters:
        pattern - Pattern to remove
        Returns:
        true if the supplied pattern was found and was removed, otherwise false
      • setTimeoutUnits

        public void setTimeoutUnits​(int units)
        Sets the number of 1/4-second units for how long to try to get further input to complete an escape-sequence for a special Key. Negative numbers are mapped to 0 (no wait at all), and unreasonably high values are mapped to a maximum of 240 (1 minute).
        Parameters:
        units - New timeout to use, in 250ms units
      • getTimeoutUnits

        public int getTimeoutUnits()
        queries the current timeoutUnits value. One unit is 1/4 second.
        Returns:
        The timeout this InputDecoder will use when waiting for additional input, in units of 1/4 seconds
      • getNextCharacter

        public KeyStroke getNextCharacter​(boolean blockingIO)
                                   throws java.io.IOException
        Reads and decodes the next key stroke from the input stream
        Parameters:
        blockingIO - If set to true, the call will not return until it has read at least one KeyStroke
        Returns:
        Key stroke read from the input stream, or null if none
        Throws:
        java.io.IOException - If there was an I/O error when reading from the input stream