Package ca.cgjennings.ui
Class KeyFilter
- java.lang.Object
-
- ca.cgjennings.ui.KeyFilter
-
- All Implemented Interfaces:
java.awt.event.KeyListener
,java.util.EventListener
public class KeyFilter extends java.lang.Object implements java.awt.event.KeyListener
AKeyListener
that, when added to a component, filters out certain keys to prevent them from being processed by that component.- Author:
- Chris Jennings
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
filter(int keyCode)
Returnstrue
ifkeyCode
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.
-
-
-
Constructor Detail
-
KeyFilter
public KeyFilter()
Create a filter that allows all key codes. This constructor is meant primarily for use by subclasses that override thefilter(int)
method.
-
KeyFilter
public KeyFilter(int... keyCodes)
Create a filter that filters out key codes from an array. Key codes are supplied asVK_
constants (seejava.awt.event.KeyEvent
).- Parameters:
keyCodes
-
-
-
Method Detail
-
filter
public boolean filter(int keyCode)
Returnstrue
ifkeyCode
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 interfacejava.awt.event.KeyListener
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent e)
- Specified by:
keyPressed
in interfacejava.awt.event.KeyListener
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent e)
- Specified by:
keyReleased
in interfacejava.awt.event.KeyListener
-
-