01: package net.sourceforge.squirrel_sql.plugins.syntax.oster;
02:
03: /*
04: * This is based on the text editor demonstration class that comes with
05: * the Ostermiller Syntax Highlighter Copyright (C) 2001 Stephen Ostermiller
06: * http://ostermiller.org/contact.pl?regarding=Syntax+Highlighting
07:
08: * Modifications copyright (C) 2003 Colin Bell
09: * colbell@users.sourceforge.net
10: *
11: *
12: * This program is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU General Public License
14: * as published by the Free Software Foundation; either version 2
15: * of the License, or any later version.
16: *
17: * This program is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: * GNU General Public License for more details.
21: *
22: * You should have received a copy of the GNU General Public License
23: * along with this program; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25: */
26:
27: /**
28: * A wrapper for a position in a document appropriate for storing
29: * in a collection.
30: */
31: class DocPosition {
32: /**
33: * The actual position
34: */
35: private int position;
36:
37: /**
38: * Get the position represented by this DocPosition
39: *
40: * @return the position
41: */
42: int getPosition() {
43: return position;
44: }
45:
46: /**
47: * Construct a DocPosition from the given offset into the document.
48: *
49: * @param position The position this DocObject will represent
50: */
51: public DocPosition(int position) {
52: this .position = position;
53: }
54:
55: /**
56: * Adjust this position.
57: * This is useful in cases that an amount of text is inserted
58: * or removed before this position.
59: *
60: * @param adjustment amount (either positive or negative) to adjust this position.
61: * @return the DocPosition, adjusted properly.
62: */
63: public DocPosition adjustPosition(int adjustment) {
64: position += adjustment;
65: return this ;
66: }
67:
68: /**
69: * Two DocPositions are equal iff they have the same internal position.
70: *
71: * @return if this DocPosition represents the same position as another.
72: */
73: public boolean equals(Object obj) {
74: if (obj instanceof DocPosition) {
75: DocPosition d = (DocPosition) (obj);
76: if (this .position == d.position) {
77: return true;
78: } else {
79: return false;
80: }
81: } else {
82: return false;
83: }
84: }
85:
86: /**
87: * A string representation useful for debugging.
88: *
89: * @return A string representing the position.
90: */
91: public String toString() {
92: return "" + position;
93: }
94: }
|