Lines 43-48
Link Here
|
43 |
*/ |
43 |
*/ |
44 |
package org.netbeans.api.editor.guards; |
44 |
package org.netbeans.api.editor.guards; |
45 |
|
45 |
|
|
|
46 |
import org.netbeans.modules.editor.guards.OffsetPosition; |
46 |
import java.beans.PropertyVetoException; |
47 |
import java.beans.PropertyVetoException; |
47 |
import javax.swing.text.Position; |
48 |
import javax.swing.text.Position; |
48 |
import org.netbeans.modules.editor.guards.GuardedSectionImpl; |
49 |
import org.netbeans.modules.editor.guards.GuardedSectionImpl; |
Lines 50-58
Link Here
|
50 |
/** |
51 |
/** |
51 |
* Represents one guarded section. |
52 |
* Represents one guarded section. |
52 |
*/ |
53 |
*/ |
53 |
public class GuardedSection { |
54 |
public abstract class GuardedSection { |
54 |
|
55 |
|
55 |
private final GuardedSectionImpl impl; |
56 |
private final GuardedSectionImpl impl; |
|
|
57 |
private final GuardedSection delegate; |
58 |
final int offset; |
56 |
|
59 |
|
57 |
/** |
60 |
/** |
58 |
* Creates new section. |
61 |
* Creates new section. |
Lines 62-67
Link Here
|
62 |
assert impl != null; |
65 |
assert impl != null; |
63 |
this.impl = impl; |
66 |
this.impl = impl; |
64 |
impl.attach(this); |
67 |
impl.attach(this); |
|
|
68 |
this.delegate = null; |
69 |
this.offset = 0; |
70 |
} |
71 |
|
72 |
GuardedSection(GuardedSection delegate, int offset) { |
73 |
this.impl = null; |
74 |
this.delegate = delegate; |
75 |
this.offset = offset; |
65 |
} |
76 |
} |
66 |
|
77 |
|
67 |
/** |
78 |
/** |
Lines 69-75
Link Here
|
69 |
* @return the name |
80 |
* @return the name |
70 |
*/ |
81 |
*/ |
71 |
public String getName() { |
82 |
public String getName() { |
72 |
return impl.getName(); |
83 |
return impl != null ? impl.getName() : delegate.getName(); |
73 |
} |
84 |
} |
74 |
|
85 |
|
75 |
/** |
86 |
/** |
Lines 78-83
Link Here
|
78 |
* @exception PropertyVetoException if the new name is already in use |
89 |
* @exception PropertyVetoException if the new name is already in use |
79 |
*/ |
90 |
*/ |
80 |
public void setName(String name) throws PropertyVetoException { |
91 |
public void setName(String name) throws PropertyVetoException { |
|
|
92 |
if (impl == null) throw new IllegalStateException(); |
81 |
impl.setName(name); |
93 |
impl.setName(name); |
82 |
} |
94 |
} |
83 |
|
95 |
|
Lines 87-92
Link Here
|
87 |
* and it will be impossible to use its methods. |
99 |
* and it will be impossible to use its methods. |
88 |
*/ |
100 |
*/ |
89 |
public void deleteSection() { |
101 |
public void deleteSection() { |
|
|
102 |
if (impl == null) throw new IllegalStateException(); |
90 |
impl.deleteSection(); |
103 |
impl.deleteSection(); |
91 |
} |
104 |
} |
92 |
|
105 |
|
Lines 95-101
Link Here
|
95 |
* source. |
108 |
* source. |
96 |
*/ |
109 |
*/ |
97 |
public boolean isValid() { |
110 |
public boolean isValid() { |
98 |
return impl.isValid(); |
111 |
return impl != null ? impl.isValid() : delegate.isValid(); |
99 |
} |
112 |
} |
100 |
|
113 |
|
101 |
/** |
114 |
/** |
Lines 104-109
Link Here
|
104 |
* instead of calling NbDocument. |
117 |
* instead of calling NbDocument. |
105 |
*/ |
118 |
*/ |
106 |
public void removeSection() { |
119 |
public void removeSection() { |
|
|
120 |
if (impl == null) throw new IllegalStateException(); |
107 |
impl.removeSection(); |
121 |
impl.removeSection(); |
108 |
} |
122 |
} |
109 |
|
123 |
|
Lines 113-119
Link Here
|
113 |
* @return the position to place the caret. |
127 |
* @return the position to place the caret. |
114 |
*/ |
128 |
*/ |
115 |
public Position getCaretPosition() { |
129 |
public Position getCaretPosition() { |
116 |
return impl.getCaretPosition(); |
130 |
return impl != null ? impl.getCaretPosition() : new OffsetPosition(delegate.getCaretPosition(), offset); |
117 |
} |
131 |
} |
118 |
|
132 |
|
119 |
/** |
133 |
/** |
Lines 121-127
Link Here
|
121 |
* @return The text contained in the section. |
135 |
* @return The text contained in the section. |
122 |
*/ |
136 |
*/ |
123 |
public String getText() { |
137 |
public String getText() { |
124 |
return impl.getText(); |
138 |
return impl != null ? impl.getText() : delegate.getText(); |
125 |
} |
139 |
} |
126 |
|
140 |
|
127 |
/** |
141 |
/** |
Lines 134-140
Link Here
|
134 |
* @return <code>true</code> if the position is inside section. |
148 |
* @return <code>true</code> if the position is inside section. |
135 |
*/ |
149 |
*/ |
136 |
public boolean contains(Position pos, boolean permitHoles) { |
150 |
public boolean contains(Position pos, boolean permitHoles) { |
137 |
return impl.contains(pos, permitHoles); |
151 |
return impl != null ? impl.contains(pos, permitHoles) : delegate.contains(new OffsetPosition(pos, -offset), permitHoles); |
138 |
} |
152 |
} |
139 |
|
153 |
|
140 |
/** |
154 |
/** |
Lines 142-148
Link Here
|
142 |
* @return the end position of the guarded section. |
156 |
* @return the end position of the guarded section. |
143 |
*/ |
157 |
*/ |
144 |
public Position getEndPosition() { |
158 |
public Position getEndPosition() { |
145 |
return impl.getEndPosition(); |
159 |
return impl != null ? impl.getEndPosition() : new OffsetPosition(delegate.getEndPosition(), offset); |
146 |
} |
160 |
} |
147 |
|
161 |
|
148 |
/** |
162 |
/** |
Lines 150-160
Link Here
|
150 |
* @return the start position of the guarded section. |
164 |
* @return the start position of the guarded section. |
151 |
*/ |
165 |
*/ |
152 |
public Position getStartPosition() { |
166 |
public Position getStartPosition() { |
153 |
return impl.getStartPosition(); |
167 |
return impl != null ? impl.getStartPosition() : new OffsetPosition(delegate.getStartPosition(), offset); |
154 |
} |
168 |
} |
155 |
|
169 |
|
156 |
GuardedSectionImpl getImpl() { |
170 |
GuardedSectionImpl getImpl() { |
157 |
return impl; |
171 |
return impl; |
158 |
} |
172 |
} |
159 |
|
173 |
|
|
|
174 |
GuardedSection getDelegate() { |
175 |
return delegate; |
176 |
} |
177 |
|
178 |
abstract GuardedSection clone(int offset); |
160 |
} |
179 |
} |