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