Class InputHandler
- java.lang.Object
-
- net.sf.gridarta.textedit.textarea.InputHandler
-
- All Implemented Interfaces:
java.awt.event.KeyListener,java.util.EventListener
- Direct Known Subclasses:
DefaultInputHandler
public abstract class InputHandler extends java.lang.Object implements java.awt.event.KeyListenerAn input handler converts the user's key strokes into concrete actions. It also takes care of macro recording and action repetition.This class provides all the necessary support code for an input handler, but doesn't actually do any key binding logic. It is up to the implementations of this class to do so.
- See Also:
DefaultInputHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceInputHandler.NonRepeatableIf an action implements this interface, it should not be repeated.
-
Field Summary
Fields Modifier and Type Field Description protected intrepeatCount
-
Constructor Summary
Constructors Constructor Description InputHandler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddDefaultKeyBindings()Adds the default key bindings to this input handler.abstract InputHandlercopy()Returns a copy of this input handler that shares the same key bindings.protected voidexecuteAction(java.awt.event.ActionListener listener, java.lang.Object source, @Nullable java.lang.String actionCommand)Executes the specified action, repeating and recording it as necessary.intgetRepeatCount()Returns the number of times the next action will be repeated.static @NotNull JEditTextAreagetTextArea(java.util.EventObject evt)Returns the text area that fired the specified event.protected booleanhandleGrabAction(java.awt.event.KeyEvent evt)If a key is being grabbed, this method should be called with the appropriate key event.protected booleanisRepeatEnabled()Returns if repetition is enabled.voidsetRepeatCount(int repeatCount)Sets the number of times the next action will be repeated.voidsetRepeatEnabled(boolean repeat)Sets the enabled state of repetition.
-
-
-
Method Detail
-
addDefaultKeyBindings
public abstract void addDefaultKeyBindings()
Adds the default key bindings to this input handler. This should not be called in the constructor of this input handler, because applications might load the key bindings from a file, etc.
-
isRepeatEnabled
protected boolean isRepeatEnabled()
Returns if repetition is enabled. When repetition is enabled, actions will be executed multiple times. This is usually invoked with a special key stroke in the input handler.- Returns:
trueif repeating is enabled, otherwisefalse
-
setRepeatEnabled
public void setRepeatEnabled(boolean repeat)
Sets the enabled state of repetition. When repetition is enabled, actions will be executed multiple times. Once repeating is enabled, the input handler should read a number from the keyboard.- Parameters:
repeat-truefor enabling repetition,falsefor disabling it
-
getRepeatCount
public int getRepeatCount()
Returns the number of times the next action will be repeated.- Returns:
- number of times the next action will be repeated (1 or the set repeat count)
-
setRepeatCount
public void setRepeatCount(int repeatCount)
Sets the number of times the next action will be repeated.- Parameters:
repeatCount- the repeat count
-
copy
public abstract InputHandler copy()
Returns a copy of this input handler that shares the same key bindings. Setting key bindings in the copy will also set them in the original.- Returns:
- copy of this InputHandler
-
executeAction
protected void executeAction(java.awt.event.ActionListener listener, java.lang.Object source, @Nullable @Nullable java.lang.String actionCommand)Executes the specified action, repeating and recording it as necessary.- Parameters:
listener- the action listenersource- the event sourceactionCommand- the action command
-
getTextArea
@NotNull public static @NotNull JEditTextArea getTextArea(java.util.EventObject evt)
Returns the text area that fired the specified event. This method will throw anErrorifevtdoes not have a JEditTextArea in it's source component hierarchy.- Parameters:
evt- the event- Returns:
- the JEditTextArea found as the source of
evt
-
handleGrabAction
protected boolean handleGrabAction(java.awt.event.KeyEvent evt)
If a key is being grabbed, this method should be called with the appropriate key event. It executes the grab action with the typed character as the parameter.- Parameters:
evt- the key event the key should be grabbed of- Returns:
- whether a grab action was active
-
-