KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > editor > bookmarks > api > Bookmark


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.editor.bookmarks.api;
21
22 import javax.swing.text.Document JavaDoc;
23 import org.netbeans.lib.editor.bookmarks.spi.BookmarkImplementation;
24
25 /**
26  * Interface to a bookmark.
27  *
28  * @author Miloslav Metelka
29  */

30
31 public final class Bookmark {
32
33     /**
34      * Bookmark list to which this bookmark belongs.
35      */

36     private BookmarkList bookmarkList;
37
38     /**
39      * Implementation to which this bookmark delegates.
40      */

41     private BookmarkImplementation impl;
42
43     /**
44      * Whether this mark was released or not.
45      */

46     private boolean released;
47     
48     /**
49      * Construct new instance of bookmark.
50      *
51      * <p>
52      * The constructor is not public intentionally.
53      * Please see <code>BookmarksApiPackageAccessor</code> for details.
54      */

55     Bookmark(BookmarkList bookmarkList, BookmarkImplementation impl) {
56         this.bookmarkList = bookmarkList;
57         this.impl = impl;
58     }
59
60     /**
61      * Get offset of this bookmark.
62      * <br>
63      * Offsets behave like {@link javax.swing.text.Position}s (they track
64      * inserts/removals).
65      */

66     public int getOffset() {
67         return impl.getOffset();
68     }
69
70     /**
71      * Get the index of the line at which this bookmark resides.
72      */

73     public int getLineIndex() {
74         return getDocument().getDefaultRootElement().getElementIndex(impl.getOffset());
75     }
76     
77     /**
78      * Get the bookmark list for which this bookmark was created.
79      */

80     public BookmarkList getList() {
81         return bookmarkList;
82     }
83     
84     /**
85      * Return true if this mark was released (removed from its bookmark list)
86      * and is no longer actively used.
87      */

88     public boolean isReleased() {
89         return released;
90     }
91     
92     /**
93      * Mark the current bookmark as invalid.
94      */

95     void release() {
96         assert (!released);
97         released = true;
98         impl.release();
99     }
100
101     /**
102      * Get bookmark's implementation. For API accessor only.
103      */

104     BookmarkImplementation getImplementation() {
105         return impl;
106     }
107
108     /**
109      * Get document to which this bookmark belongs.
110      */

111     private Document JavaDoc getDocument() {
112         return bookmarkList.getDocument();
113     }
114     
115 }
116
117
Popular Tags