Gridarta Editor
Home.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-201 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 Home implements ActionListener {
19 
20  private final boolean select;
21 
22  public Home(final boolean select) {
23  this.select = select;
24  }
25 
26  @Override
27  public void actionPerformed(final ActionEvent e) {
28  final JEditTextArea textArea = InputHandler.getTextArea(e);
29 
30  int caret = textArea.getCaretPosition();
31 
32  final int firstLine = textArea.getFirstLine();
33 
34  final int firstOfLine = textArea.getLineStartOffset(textArea.getCaretLine());
35  final int firstVisibleLine = firstLine == 0 ? 0 : firstLine + textArea.getElectricScroll();
36  final int firstVisible = textArea.getLineStartOffset(firstVisibleLine);
37 
38  if (caret == 0) {
39  textArea.getToolkit().beep();
40  return;
41  } else if (!Boolean.TRUE.equals(textArea.getClientProperty(InputActions.SMART_HOME_END_PROPERTY))) {
42  caret = firstOfLine;
43  } else if (caret == firstVisible) {
44  caret = 0;
45  } else if (caret == firstOfLine) {
46  caret = firstVisible;
47  } else {
48  caret = firstOfLine;
49  }
50 
51  if (select) {
52  textArea.select(textArea.getMarkPosition(), caret);
53  } else {
54  textArea.setCaretPosition(caret);
55  }
56  }
57 
58 }
int getMarkPosition()
Returns the mark position.
An input handler converts the user's key strokes into concrete actions.
Base package of all Gridarta classes.
int getLineStartOffset(final int line)
Returns the start offset of the specified line.
void select(final int start, final int end)
Selects from the start offset to the end offset.
This package contains the other part of the script editor.
int getCaretPosition()
Returns the caret position.
int getElectricScroll()
Returns the number of lines from the top and button of the text area that are always visible...
int getFirstLine()
Returns the line displayed at the text area's origin.
static JEditTextArea getTextArea(final EventObject evt)
Returns the text area that fired the specified event.
void setCaretPosition(final int caret)
Sets the caret position.
void actionPerformed(final ActionEvent e)
Definition: Home.java:27
static final String SMART_HOME_END_PROPERTY
If this client property is set to Boolean.TRUE on the text area, the home/end keys will support 'smar...