KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > Marker


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
23 package org.gjt.sp.jedit;
24
25 import javax.swing.text.Position JavaDoc;
26
27 /**
28  * Buffers may contain one or more <i>markers</i> which serve
29  * as textual bookmarks.<p>
30  *
31  * A <code>Marker</code> has three key attributes: the
32  * <code>Buffer</code> to which it relates, the line number to which
33  * the marker refers, and an optional shortcut character. The shortcut
34  * identifies the the key that can be pressed with the
35  * <b>Markers</b>&gt;<b>Go To Marker</b> command.
36  *
37  * @author Slava Pestov
38  * @author John Gellene (API documentation)
39  * @version $Id: Marker.java 4469 2003-02-08 18:53:03Z spestov $
40  */

41 public class Marker
42 {
43     //{{{ getShortcut() method
44
/**
45      * Returns the marker's shortcut character.
46      * @since jEdit 3.2pre1
47      */

48     public char getShortcut()
49     {
50         return shortcut;
51     } //}}}
52

53     //{{{ getPosition() method
54
/**
55      * Returns the position of this marker.
56      * @since jEdit 3.2pre1
57      */

58     public int getPosition()
59     {
60         return (position == null ? pos : position.getOffset());
61     } //}}}
62

63     //{{{ Package-private members
64

65     //{{{ Marker constructor
66
Marker(Buffer buffer, char shortcut, int position)
67     {
68         this.buffer = buffer;
69         this.shortcut = shortcut;
70         this.pos = position;
71     } //}}}
72

73     //{{{ setShortcut() method
74
/**
75      * Sets the marker's shortcut.
76      * @param shortcut The new shortcut
77      * @since jEdit 3.2pre1
78      */

79     void setShortcut(char shortcut)
80     {
81         this.shortcut = shortcut;
82     } //}}}
83

84     //{{{ createPosition() method
85
void createPosition()
86     {
87         position = buffer.createPosition(pos);
88     } //}}}
89

90     //{{{ removePosition() method
91
void removePosition()
92     {
93         // forget the cached Position instance
94
if(position != null)
95         {
96             pos = position.getOffset();
97             position = null;
98         }
99     } //}}}
100

101     //{{{ setPosition() method
102
/**
103      * Sets the position of this marker.
104      * @since jEdit 4.0pre5
105      */

106     void setPosition(int pos)
107     {
108         this.pos = pos;
109     } //}}}
110

111     //}}}
112

113     //{{{ Private members
114
private Buffer buffer;
115     private char shortcut;
116     private int pos;
117     private Position JavaDoc position;
118     //}}}
119
}
120
Popular Tags