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

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

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

revision 1.6.2.7 by gnu_andrew, Sun Aug 7 18:34:12 2005 UTC revision 1.6.2.8 by gnu_andrew, Sat Sep 10 15:31:55 2005 UTC
# Line 62  public abstract class View implements Sw Line 62  public abstract class View implements Sw
62    private View parent;    private View parent;
63    
64    /**    /**
    * The child views.  
    */  
   View[] children;  
   
   /**  
65     * Creates a new <code>View</code> instance.     * Creates a new <code>View</code> instance.
66     *     *
67     * @param elem an <code>Element</code> value     * @param elem an <code>Element</code> value
# Line 74  public abstract class View implements Sw Line 69  public abstract class View implements Sw
69    public View(Element elem)    public View(Element elem)
70    {    {
71      elt = elem;      elt = elem;
     children = new View[0];  
72    }    }
73    
74    public abstract void paint(Graphics g, Shape s);    public abstract void paint(Graphics g, Shape s);
# Line 92  public abstract class View implements Sw Line 86  public abstract class View implements Sw
86    public Container getContainer()    public Container getContainer()
87    {    {
88      View parent = getParent();      View parent = getParent();
89      return parent != null ? parent.getContainer() : null;      if (parent == null)
90          throw new AssertionError("The parent of a View must not be null.");
91    
92        return parent.getContainer();
93    }    }
94        
95    public Document getDocument()    public Document getDocument()
# Line 178  public abstract class View implements Sw Line 175  public abstract class View implements Sw
175    public void append(View view)    public void append(View view)
176    {    {
177      View[] array = { view };      View[] array = { view };
178      replace(getViewCount(), 1, array);      int offset = getViewCount();
179        replace(offset, 0, array);
180    }    }
181    
182    public void removeAll()    public void removeAll()
183    {    {
184      replace(0, getViewCount(), null);      replace(0, getViewCount(), new View[0]);
185    }    }
186    
187    public void remove(int index)    public void remove(int index)
# Line 250  public abstract class View implements Sw Line 248  public abstract class View implements Sw
248    {    {
249      if (parent != null)      if (parent != null)
250        parent.preferenceChanged(this, width, height);        parent.preferenceChanged(this, width, height);
     else  
       ((JComponent) getContainer()).revalidate();  
251    }    }
252    
253    public int getBreakWeight(int axis, float pos, float len)    public int getBreakWeight(int axis, float pos, float len)
# Line 351  public abstract class View implements Sw Line 347  public abstract class View implements Sw
347      Element el = getElement();      Element el = getElement();
348      DocumentEvent.ElementChange ec = ev.getChange(el);      DocumentEvent.ElementChange ec = ev.getChange(el);
349      if (ec != null)      if (ec != null)
350          updateChildren(ec, ev, vf);        updateChildren(ec, ev, vf);
351      forwardUpdate(ec, ev, shape, vf);      forwardUpdate(ec, ev, shape, vf);
352      updateLayout(ec, ev, shape);      updateLayout(ec, ev, shape);
353    }    }
# Line 382  public abstract class View implements Sw Line 378  public abstract class View implements Sw
378    {    {
379      Element[] added = ec.getChildrenAdded();      Element[] added = ec.getChildrenAdded();
380      Element[] removed = ec.getChildrenRemoved();      Element[] removed = ec.getChildrenRemoved();
     View[] newChildren = new View[children.length + added.length  
                                   - removed.length];  
381      int index = ec.getIndex();      int index = ec.getIndex();
382      System.arraycopy(children, 0, newChildren, 0, index);  
383      System.arraycopy(children, index, added, 0, added.length);      View[] newChildren = new View[added.length];
384      int index2 = index + removed.length;      for (int i = 0; i < added.length; ++i)
385      int len2 = children.length - index2;        newChildren[i] = vf.create(added[i]);
386      System.arraycopy(children, index2, newChildren, index + added.length,      replace(index, removed.length, newChildren);
                      len2);  
     children = newChildren;  
387    
388      return true;      return true;
389    }    }
# Line 412  public abstract class View implements Sw Line 404  public abstract class View implements Sw
404    protected void forwardUpdate(DocumentEvent.ElementChange ec,    protected void forwardUpdate(DocumentEvent.ElementChange ec,
405                                 DocumentEvent ev, Shape shape, ViewFactory vf)                                 DocumentEvent ev, Shape shape, ViewFactory vf)
406    {    {
407      for (int i = 0; i < children.length; i++)      int count = getViewCount();
408        for (int i = 0; i < count; i++)
409        {        {
410          View child = children[i];          View child = getView(i);
411          forwardUpdateToView(child, ev, shape, vf);          forwardUpdateToView(child, ev, shape, vf);
412        }        }
413    }    }
# Line 467  public abstract class View implements Sw Line 460  public abstract class View implements Sw
460     *     *
461     * @param pos the position of the character in the model     * @param pos the position of the character in the model
462     * @param a the area that is occupied by the view     * @param a the area that is occupied by the view
463     * @param bias either {@link Position.Bias.Forward} or     * @param b either {@link Position.Bias#Forward} or
464     *        {@link Position.Bias.Backward} depending on the preferred     *        {@link Position.Bias#Backward} depending on the preferred
465     *        direction bias. If <code>null</code> this defaults to     *        direction bias. If <code>null</code> this defaults to
466     *        <code>Position.Bias.Forward</code>     *        <code>Position.Bias.Forward</code>
467     *     *
# Line 526  public abstract class View implements Sw Line 519  public abstract class View implements Sw
519     * @return the position in the document that corresponds to the screen     * @return the position in the document that corresponds to the screen
520     *         coordinates <code>x, y</code>     *         coordinates <code>x, y</code>
521     */     */
522    public abstract int viewToModel(float x, float y, Shape a, Position.Bias b);    public abstract int viewToModel(float x, float y, Shape a, Position.Bias[] b);
523    
524    
525      /**
526       * Dumps the complete View hierarchy. This method can be used for debugging
527       * purposes.
528       */
529      void dump()
530      {
531        // Climb up the hierarchy to the parent.
532        View parent = getParent();
533        if (parent != null)
534          parent.dump();
535        else
536          dump(0);
537      }
538    
539      /**
540       * Dumps the view hierarchy below this View with the specified indentation
541       * level.
542       *
543       * @param indent the indentation level to be used for this view
544       */
545      void dump(int indent)
546      {
547        for (int i = 0; i < indent; ++i)
548          System.out.print('.');
549        System.out.println(this);
550    
551        int count = getViewCount();
552        for (int i = 0; i < count; ++i)
553          getView(i).dump(indent + 1);
554      }
555  }  }

Legend:
Removed from v.1.6.2.7  
changed lines
  Added in v.1.6.2.8

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