001: /*
002: * Marker.java - Named location in a buffer
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 1998, 1999, 2000, 2001 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit;
024:
025: import javax.swing.text.Position;
026:
027: /**
028: * Buffers may contain one or more <i>markers</i> which serve
029: * as textual bookmarks.<p>
030: *
031: * A <code>Marker</code> has three key attributes: the
032: * <code>Buffer</code> to which it relates, the line number to which
033: * the marker refers, and an optional shortcut character. The shortcut
034: * identifies the the key that can be pressed with the
035: * <b>Markers</b>><b>Go To Marker</b> command.
036: *
037: * @author Slava Pestov
038: * @author John Gellene (API documentation)
039: * @version $Id: Marker.java 4469 2003-02-08 18:53:03Z spestov $
040: */
041: public class Marker {
042: //{{{ getShortcut() method
043: /**
044: * Returns the marker's shortcut character.
045: * @since jEdit 3.2pre1
046: */
047: public char getShortcut() {
048: return shortcut;
049: } //}}}
050:
051: //{{{ getPosition() method
052: /**
053: * Returns the position of this marker.
054: * @since jEdit 3.2pre1
055: */
056: public int getPosition() {
057: return (position == null ? pos : position.getOffset());
058: } //}}}
059:
060: //{{{ Package-private members
061:
062: //{{{ Marker constructor
063: Marker(Buffer buffer, char shortcut, int position) {
064: this .buffer = buffer;
065: this .shortcut = shortcut;
066: this .pos = position;
067: } //}}}
068:
069: //{{{ setShortcut() method
070: /**
071: * Sets the marker's shortcut.
072: * @param shortcut The new shortcut
073: * @since jEdit 3.2pre1
074: */
075: void setShortcut(char shortcut) {
076: this .shortcut = shortcut;
077: } //}}}
078:
079: //{{{ createPosition() method
080: void createPosition() {
081: position = buffer.createPosition(pos);
082: } //}}}
083:
084: //{{{ removePosition() method
085: void removePosition() {
086: // forget the cached Position instance
087: if (position != null) {
088: pos = position.getOffset();
089: position = null;
090: }
091: } //}}}
092:
093: //{{{ setPosition() method
094: /**
095: * Sets the position of this marker.
096: * @since jEdit 4.0pre5
097: */
098: void setPosition(int pos) {
099: this .pos = pos;
100: } //}}}
101:
102: //}}}
103:
104: //{{{ Private members
105: private Buffer buffer;
106: private char shortcut;
107: private int pos;
108: private Position position;
109: //}}}
110: }
|