/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/Marker.java
Java | 112 lines | 44 code | 12 blank | 56 comment | 3 complexity | 0e151d257fd5a48eaa84c91e8cccc453 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
1/*
2 * Marker.java - Named location in a buffer
3 * :tabSize=8:indentSize=8:noTabs=false:
4 * :folding=explicit:collapseFolds=1:
5 *
6 * Copyright (C) 1998, 1999, 2000, 2001 Slava Pestov
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23package org.gjt.sp.jedit;
24
25import javax.swing.text.Position;
26import org.gjt.sp.util.Log;
27
28/**
29 * A named location in a buffer.
30 *
31 * @author Slava Pestov
32 * @version $Id: Marker.java 4022 2002-02-11 03:15:30Z spestov $
33 */
34public class Marker
35{
36 //{{{ getShortcut() method
37 /**
38 * Returns the marker's shortcut.
39 * @since jEdit 3.2pre1
40 */
41 public char getShortcut()
42 {
43 return shortcut;
44 } //}}}
45
46 //{{{ getPosition() method
47 /**
48 * Returns the position of this marker.
49 * @since jEdit 3.2pre1
50 */
51 public int getPosition()
52 {
53 return (position == null ? pos : position.getOffset());
54 } //}}}
55
56 //{{{ Package-private members
57
58 //{{{ Marker constructor
59 Marker(Buffer buffer, char shortcut, int position)
60 {
61 this.buffer = buffer;
62 this.shortcut = shortcut;
63 this.pos = position;
64 } //}}}
65
66 //{{{ setShortcut() method
67 /**
68 * Sets the marker's shortcut.
69 * @param shortcut The new shortcut
70 * @since jEdit 3.2pre1
71 */
72 void setShortcut(char shortcut)
73 {
74 this.shortcut = shortcut;
75 } //}}}
76
77 //{{{ createPosition() method
78 void createPosition()
79 {
80 position = buffer.createPosition(pos);
81 } //}}}
82
83 //{{{ removePosition() method
84 void removePosition()
85 {
86 // forget the cached Position instance
87 if(position != null)
88 {
89 pos = position.getOffset();
90 position = null;
91 }
92 } //}}}
93
94 //{{{ setPosition() method
95 /**
96 * Sets the position of this marker.
97 * @since jEdit 4.0pre5
98 */
99 void setPosition(int pos)
100 {
101 this.pos = pos;
102 } //}}}
103
104 //}}}
105
106 //{{{ Private members
107 private Buffer buffer;
108 private char shortcut;
109 private int pos;
110 private Position position;
111 //}}}
112}