KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > editor > guards > GuardedSection


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 package org.netbeans.api.editor.guards;
20
21 import java.beans.PropertyVetoException JavaDoc;
22 import javax.swing.text.Position JavaDoc;
23 import org.netbeans.modules.editor.guards.GuardedSectionImpl;
24
25 /**
26  * Represents one guarded section.
27  */

28 public class GuardedSection {
29     
30     private final GuardedSectionImpl impl;
31
32     /**
33      * Creates new section.
34      * @param name Name of the new section.
35      */

36     GuardedSection(GuardedSectionImpl impl) {
37         assert impl != null;
38         this.impl = impl;
39         impl.attach(this);
40     }
41     
42     /**
43      * Get the name of the section.
44      * @return the name
45      */

46     public String JavaDoc getName() {
47         return impl.getName();
48     }
49
50     /**
51      * Set the name of the section.
52      * @param name the new name
53      * @exception PropertyVetoException if the new name is already in use
54      */

55     public void setName(String JavaDoc name) throws PropertyVetoException JavaDoc {
56         impl.setName(name);
57     }
58
59     /**
60      * Removes the section and the text of the section from the Document.
61      * The section will then be invalid
62      * and it will be impossible to use its methods.
63      */

64     public void deleteSection() {
65         impl.deleteSection();
66     }
67
68     /**
69      * Tests if the section is still valid - it is not removed from the
70      * source.
71      */

72     public boolean isValid() {
73         return impl.isValid();
74     }
75
76     /**
77      * Removes the section from the Document, but retains the text contained
78      * within. The method should be used to unprotect a region of code
79      * instead of calling NbDocument.
80      */

81     public void removeSection() {
82         impl.removeSection();
83     }
84     
85     /**
86      * Gets the begin of section. To this position is set the caret
87      * when section is open in the editor.
88      * @return the position to place the caret.
89      */

90     public Position JavaDoc getCaretPosition() {
91         return impl.getCaretPosition();
92     }
93     
94     /**
95      * Gets the text contained in the section.
96      * @return The text contained in the section.
97      */

98     public String JavaDoc getText() {
99         return impl.getText();
100     }
101
102     /**
103      * Assures that a position is not inside the guarded section. Complex guarded sections
104      * that contain portions of editable text can return true if the tested position is
105      * inside one of such portions provided that permitHoles is true.
106      * @param pos position in question
107      * @param permitHoles if false, guarded section is taken as a monolithic block
108      * without any holes in it regardless of its complexity.
109      * @return <code>true</code> if the position is inside section.
110      */

111     public boolean contains(Position JavaDoc pos, boolean permitHoles) {
112         return impl.contains(pos, permitHoles);
113     }
114     
115     /**
116      * Returns the end position of the whole guarded section.
117      * @return the end position of the guarded section.
118      */

119     public Position JavaDoc getEndPosition() {
120         return impl.getEndPosition();
121     }
122     
123     /**
124      * Returns the start position of the whole guarded section.
125      * @return the start position of the guarded section.
126      */

127     public Position JavaDoc getStartPosition() {
128         return impl.getStartPosition();
129     }
130     
131     GuardedSectionImpl getImpl() {
132         return impl;
133     }
134
135 }
136
Popular Tags