Gridarta Editor
InsertChar.java
Go to the documentation of this file.
1 /*
2  * InputHandler.java - Manages key bindings and executes actions
3  * Copyright (C) 1999 Slava Pestov
4  * Copyright (C) 2000-2015 The Gridarta Developers.
5  *
6  * You may use and modify this package for any purpose. Redistribution is
7  * permitted, in both source and binary form, provided that this notice
8  * remains intact in all source distributions of this package.
9  */
10 
11 package net.sf.gridarta.textedit.textarea.actions;
12 
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
17 
18 public class InsertChar implements ActionListener, InputHandler.NonRepeatable {
19 
20  @Override
21  public void actionPerformed(final ActionEvent e) {
22  final JEditTextArea textArea = InputHandler.getTextArea(e);
23  final String str = e.getActionCommand();
24  final int repeatCount = textArea.getInputHandler().getRepeatCount();
25 
26  if (textArea.isEditable()) {
27  final StringBuilder buf = new StringBuilder();
28  for (int i = 0; i < repeatCount; i++) {
29  buf.append(str);
30  }
31  textArea.overwriteSetSelectedText(buf.toString());
32  } else {
33  textArea.getToolkit().beep();
34  }
35  }
36 
37 }
An input handler converts the user&#39;s key strokes into concrete actions.
Base package of all Gridarta classes.
InputHandler getInputHandler()
Returns the input handler.
boolean isEditable()
Returns true if this text area is editable, false otherwise.
This package contains the other part of the script editor.
static JEditTextArea getTextArea(final EventObject evt)
Returns the text area that fired the specified event.
int getRepeatCount()
Returns the number of times the next action will be repeated.
void overwriteSetSelectedText(@NotNull final String str)
Similar to.