Class KeyFilter

  • All Implemented Interfaces:
    java.awt.event.KeyListener, java.util.EventListener

    public class KeyFilter
    extends java.lang.Object
    implements java.awt.event.KeyListener
    A KeyListener that, when added to a component, filters out certain keys to prevent them from being processed by that component.
    Author:
    Chris Jennings
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyFilter()
      Create a filter that allows all key codes.
      KeyFilter​(int... keyCodes)
      Create a filter that filters out key codes from an array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean filter​(int keyCode)
      Returns true if keyCode is filtered out by this filter.
      void keyPressed​(java.awt.event.KeyEvent e)  
      void keyReleased​(java.awt.event.KeyEvent e)  
      void keyTyped​(java.awt.event.KeyEvent e)  
      protected void onFiltration​(int keyCode)
      Called whenever a key code has been filtered.
      • Methods inherited from class java.lang.Object

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

      • KeyFilter

        public KeyFilter()
        Create a filter that allows all key codes. This constructor is meant primarily for use by subclasses that override the filter(int) method.
      • KeyFilter

        public KeyFilter​(int... keyCodes)
        Create a filter that filters out key codes from an array. Key codes are supplied as VK_ constants (see java.awt.event.KeyEvent).
        Parameters:
        keyCodes -
    • Method Detail

      • filter

        public boolean filter​(int keyCode)
        Returns true if keyCode is filtered out by this filter. Subclasses may override this to implement custom filtering mechanisms.
        Parameters:
        keyCode - the code to check
        Returns:
        true if the key code should be filtered out
      • onFiltration

        protected void onFiltration​(int keyCode)
        Called whenever a key code has been filtered. This method allows subclasses to perform some action whenever a key is filtered out. The default implementation emits an error beep.
        Parameters:
        keyCode - the code being filtered
      • keyTyped

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

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

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