98 |
{ |
{ |
99 |
Element el = getElement(); |
Element el = getElement(); |
100 |
int count = el.getElementCount(); |
int count = el.getElementCount(); |
101 |
children = new View[count]; |
View[] newChildren = new View[count]; |
102 |
for (int i = 0; i < count; ++i) |
for (int i = 0; i < count; ++i) |
103 |
{ |
{ |
104 |
Element child = el.getElement(i); |
Element child = el.getElement(i); |
105 |
View view = f.create(child); |
View view = f.create(child); |
106 |
children[i] = view; |
newChildren[i] = view; |
107 |
} |
} |
108 |
|
replace(0, getViewCount(), newChildren); |
109 |
} |
} |
110 |
|
|
111 |
/** |
/** |
118 |
public void setParent(View parent) |
public void setParent(View parent) |
119 |
{ |
{ |
120 |
super.setParent(parent); |
super.setParent(parent); |
121 |
if ((children == null) || children.length == 0) |
if (parent != null && ((children == null) || children.length == 0)) |
122 |
loadChildren(getViewFactory()); |
loadChildren(getViewFactory()); |
123 |
} |
} |
124 |
|
|
156 |
*/ |
*/ |
157 |
public void replace(int offset, int length, View[] views) |
public void replace(int offset, int length, View[] views) |
158 |
{ |
{ |
159 |
|
// Check for null views to add. |
160 |
|
for (int i = 0; i < views.length; ++i) |
161 |
|
if (views[i] == null) |
162 |
|
throw new NullPointerException("Added views must not be null"); |
163 |
|
|
164 |
|
int endOffset = offset + length; |
165 |
|
|
166 |
|
// First we set the parent of the removed children to null. |
167 |
|
for (int i = offset; i < endOffset; ++i) |
168 |
|
children[i].setParent(null); |
169 |
|
|
170 |
View[] newChildren = new View[children.length - length + views.length]; |
View[] newChildren = new View[children.length - length + views.length]; |
171 |
System.arraycopy(children, 0, newChildren, 0, offset); |
System.arraycopy(children, 0, newChildren, 0, offset); |
172 |
System.arraycopy(views, 0, newChildren, offset, views.length); |
System.arraycopy(views, 0, newChildren, offset, views.length); |
174 |
offset + views.length, |
offset + views.length, |
175 |
children.length - (offset + length)); |
children.length - (offset + length)); |
176 |
children = newChildren; |
children = newChildren; |
177 |
|
|
178 |
|
// Finally we set the parent of the added children to this. |
179 |
|
for (int i = 0; i < views.length; ++i) |
180 |
|
views[i].setParent(this); |
181 |
} |
} |
182 |
|
|
183 |
/** |
/** |
218 |
throws BadLocationException |
throws BadLocationException |
219 |
{ |
{ |
220 |
int childIndex = getViewIndex(pos, bias); |
int childIndex = getViewIndex(pos, bias); |
221 |
View child = children[childIndex]; |
if (childIndex != -1) |
222 |
return child.modelToView(pos, a, bias); |
{ |
223 |
|
View child = getView(childIndex); |
224 |
|
Shape result = child.modelToView(pos, a, bias); |
225 |
|
if (result == null) |
226 |
|
throw new AssertionError("" + child.getClass().getName() |
227 |
|
+ ".modelToView() must not return null"); |
228 |
|
return result; |
229 |
|
} |
230 |
|
else |
231 |
|
{ |
232 |
|
// FIXME: Handle the case when we have no child view for the given |
233 |
|
// position. |
234 |
|
throw new AssertionError("No child views found where child views are " |
235 |
|
+ "expected. pos = " + pos + ", bias = " |
236 |
|
+ bias); |
237 |
|
} |
238 |
} |
} |
239 |
|
|
240 |
/** |
/** |
385 |
* |
* |
386 |
* @param x the X coordinate |
* @param x the X coordinate |
387 |
* @param y the Y coordinate |
* @param y the Y coordinate |
388 |
* @param r the allocation of this <code>CompositeView</code> |
* @param r the inner allocation of this <code>BoxView</code> on entry, |
389 |
|
* the allocation of the found child on exit |
390 |
* |
* |
391 |
* @return the child <code>View</code> at the specified location |
* @return the child <code>View</code> at the specified location |
392 |
*/ |
*/ |