2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.gui;
8 * A pointer to a character in a text using row and column.
10 * It can be used to represent a cursor position in a text.
11 * Also, it can be used to represent beginning and end of a selection.
13 public class TextPointer implements Comparable<TextPointer> {
16 * The row of the character. Starts from 0.
21 * The column of the character. Starts from 0.
25 public TextPointer() {
29 public TextPointer(final int row, final int column) {
34 public TextPointer(final TextPointer parent) {
35 this(parent.row, parent.column);
39 public boolean equals(final Object o) {
40 if (o == null) return false;
42 return o instanceof TextPointer && compareTo((TextPointer) o) == 0;
46 public int hashCode() {
48 result = 31 * result + column;
53 public int compareTo(final TextPointer textPointer) {
55 if (textPointer.row > row)
57 if (textPointer.row < row)
60 return Integer.compare(column, textPointer.column);
65 * Checks if this pointer is between the specified pointers.
67 * @param start The start pointer.
68 * @param end The end pointer.
69 * @return True if this pointer is between the specified pointers.
71 public boolean isBetween(final TextPointer start, final TextPointer end) {
79 // Make sure that start is smaller than end.
83 if (end.compareTo(start) >= 0) {
91 // Check if this pointer is between the specified pointers.
92 return (compareTo(smaller) >= 0) && (bigger.compareTo(this) > 0);