Gridarta Editor
Delete.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;
15 import javax.swing.text.BadLocationException;
18 
19 public class Delete implements ActionListener {
20 
21  @Override
22  public void actionPerformed(final ActionEvent e) {
23  final JEditTextArea textArea = InputHandler.getTextArea(e);
24 
25  if (!textArea.isEditable()) {
26  textArea.getToolkit().beep();
27  return;
28  }
29 
30  if (textArea.getSelectionStart() == textArea.getSelectionEnd()) {
31  final int caret = textArea.getCaretPosition();
32  if (caret == textArea.getDocumentLength()) {
33  textArea.getToolkit().beep();
34  return;
35  }
36 
37  try {
38  textArea.getDocument().remove(caret, 1);
39  } catch (final BadLocationException bl) {
40  bl.printStackTrace();
41  }
42  } else {
43  textArea.setSelectedText("");
44  }
45  }
46 
47 }
void setSelectedText(@NotNull final String selectedText)
Replaces the selection with the specified text.
int getSelectionStart()
Returns the selection start offset.
int getSelectionEnd()
Returns the selection end offset.
int getDocumentLength()
Returns the length of the document.
An input handler converts the user's key strokes into concrete actions.
Base package of all Gridarta classes.
boolean isEditable()
Returns true if this text area is editable, false otherwise.
This package contains the other part of the script editor.
int getCaretPosition()
Returns the caret position.
Document getDocument()
Returns the document this text area is editing.
static JEditTextArea getTextArea(final EventObject evt)
Returns the text area that fired the specified event.
void actionPerformed(final ActionEvent e)
Definition: Delete.java:22