/[classpath]/classpath/javax/swing/text/CompositeView.java
ViewVC logotype

Diff of /classpath/javax/swing/text/CompositeView.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2.2.2 by gnu_andrew, Sun Aug 7 18:34:12 2005 UTC revision 1.2.2.3 by gnu_andrew, Sat Sep 10 15:31:54 2005 UTC
# Line 92  public abstract class CompositeView Line 92  public abstract class CompositeView
92     *     *
93     * @param f the view factory to use for creating new child views     * @param f the view factory to use for creating new child views
94     *     *
95     * @see {@link #setParent}     * @see #setParent
96     */     */
97    protected void loadChildren(ViewFactory f)    protected void loadChildren(ViewFactory f)
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    /**    /**
# Line 112  public abstract class CompositeView Line 113  public abstract class CompositeView
113     * In addition to setting the parent, this calls {@link #loadChildren}, if     * In addition to setting the parent, this calls {@link #loadChildren}, if
114     * this <code>View</code> does not already have its children initialized.     * this <code>View</code> does not already have its children initialized.
115     *     *
116     * @param p the parent to set     * @param parent the parent to set
117     */     */
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    
# Line 155  public abstract class CompositeView Line 156  public abstract class CompositeView
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);
# Line 162  public abstract class CompositeView Line 174  public abstract class CompositeView
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    /**    /**
# Line 186  public abstract class CompositeView Line 202  public abstract class CompositeView
202     *     *
203     * @param pos the position of the character in the model     * @param pos the position of the character in the model
204     * @param a the area that is occupied by the view     * @param a the area that is occupied by the view
205     * @param bias either {@link Position.Bias.Forward} or     * @param bias either {@link Position.Bias#Forward} or
206     *        {@link Position.Bias.Backward} depending on the preferred     *        {@link Position.Bias#Backward} depending on the preferred
207     *        direction bias. If <code>null</code> this defaults to     *        direction bias. If <code>null</code> this defaults to
208     *        <code>Position.Bias.Forward</code>     *        <code>Position.Bias.Forward</code>
209     *     *
# Line 202  public abstract class CompositeView Line 218  public abstract class CompositeView
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    /**    /**
# Line 244  public abstract class CompositeView Line 275  public abstract class CompositeView
275     * @return the position in the document that corresponds to the screen     * @return the position in the document that corresponds to the screen
276     *         coordinates <code>x, y</code>     *         coordinates <code>x, y</code>
277     */     */
278    public int viewToModel(float x, float y, Shape a, Position.Bias b)    public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
279    {    {
280      Rectangle r = getInsideAllocation(a);      Rectangle r = getInsideAllocation(a);
281      View view = getViewAtPoint((int) x, (int) y, r);      View view = getViewAtPoint((int) x, (int) y, r);
# Line 262  public abstract class CompositeView Line 293  public abstract class CompositeView
293     * {@link #getNextEastWestVisualPositionFrom}.     * {@link #getNextEastWestVisualPositionFrom}.
294     *     *
295     * @param pos the model position to start search from     * @param pos the model position to start search from
296     * @param the bias for <code>pos</code>     * @param b the bias for <code>pos</code>
297     * @param a the allocated region for this view     * @param a the allocated region for this view
298     * @param direction the direction from the current position, can be one of     * @param direction the direction from the current position, can be one of
299     *        the following:     *        the following:
# Line 354  public abstract class CompositeView Line 385  public abstract class CompositeView
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     */     */
# Line 414  public abstract class CompositeView Line 446  public abstract class CompositeView
446     *     *
447     * Also this translates from an immutable allocation to a mutable allocation     * Also this translates from an immutable allocation to a mutable allocation
448     * that is typically reused and further narrowed, like in     * that is typically reused and further narrowed, like in
449     * {@link childAllocation}.     * {@link #childAllocation}.
450     *     *
451     * @param a the allocation given to this <code>CompositeView</code>     * @param a the allocation given to this <code>CompositeView</code>
452     *     *
# Line 450  public abstract class CompositeView Line 482  public abstract class CompositeView
482    
483    /**    /**
484     * Sets the insets defined by attributes in <code>attributes</code>. This     * Sets the insets defined by attributes in <code>attributes</code>. This
485     * queries the attribute keys {@link StyleConstants#SpaveAbove},     * queries the attribute keys {@link StyleConstants#SpaceAbove},
486     * {@link StyleConstants#SpaveBelow}, {@link StyleConstants#LeftIndent} and     * {@link StyleConstants#SpaceBelow}, {@link StyleConstants#LeftIndent} and
487     * {@link StyleConstants#RightIndent} and calls {@link #setInsets} to     * {@link StyleConstants#RightIndent} and calls {@link #setInsets} to
488     * actually set the insets on this <code>CompositeView</code>.     * actually set the insets on this <code>CompositeView</code>.
489     *     *
# Line 542  public abstract class CompositeView Line 574  public abstract class CompositeView
574     * the arrow keys.     * the arrow keys.
575     *     *
576     * @param pos the model position to start search from     * @param pos the model position to start search from
577     * @param the bias for <code>pos</code>     * @param b the bias for <code>pos</code>
578     * @param a the allocated region for this view     * @param a the allocated region for this view
579     * @param direction the direction from the current position, can be one of     * @param direction the direction from the current position, can be one of
580     *        the following:     *        the following:
# Line 575  public abstract class CompositeView Line 607  public abstract class CompositeView
607     * the arrow keys.     * the arrow keys.
608     *     *
609     * @param pos the model position to start search from     * @param pos the model position to start search from
610     * @param the bias for <code>pos</code>     * @param b the bias for <code>pos</code>
611     * @param a the allocated region for this view     * @param a the allocated region for this view
612     * @param direction the direction from the current position, can be one of     * @param direction the direction from the current position, can be one of
613     *        the following:     *        the following:

Legend:
Removed from v.1.2.2.2  
changed lines
  Added in v.1.2.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26