I added the missing methods in ParagraphView. Most of these methods are
not used and/or leftovers from pre JDK1.2 times. Obviously they have
been obsoleted and forgotten but never removed from the specs. It is
quite interesting to read the 1st edition of the OReilly Swing book on
that class, it seems that this view has been a standalone subclass of
View in the beginning and now is a subclass of FlowView ( and therefore
BoxView ) which takes over quite some functionality of these methods.

2006-02-10  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/ParagraphView.java
        (findOffsetToCharactersInString): New method.
        (getClosestPositionTo): New method.
        (getPartialSize): New method.
        (getTabBase): New method.
        (adjustRow): New method.
        (breakView): New method.
        (getBreakWeight): New method.

/Roman
Index: javax/swing/text/ParagraphView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/ParagraphView.java,v
retrieving revision 1.5
diff -u -r1.5 ParagraphView.java
--- javax/swing/text/ParagraphView.java	9 Feb 2006 14:28:49 -0000	1.5
+++ javax/swing/text/ParagraphView.java	10 Feb 2006 14:47:43 -0000
@@ -234,4 +234,185 @@
   {
     return tabSet;
   }
+
+  /**
+   * Finds the next offset in the document that has one of the characters
+   * specified in <code>string</code>. If there is no such character found,
+   * this returns -1.
+   *
+   * @param string the characters to search for
+   * @param start the start offset
+   *
+   * @return the next offset in the document that has one of the characters
+   *         specified in <code>string</code>
+   */
+  protected int findOffsetToCharactersInString(char[] string, int start)
+  {
+    int offset = -1;
+    Document doc = getDocument();
+    Segment text = new Segment();
+    try
+      {
+        doc.getText(start, doc.getLength() - start, text);
+        int index = start;
+
+        searchLoop:
+        while (true)
+          {
+            char ch = text.next();
+            if (ch == Segment.DONE)
+              break;
+
+            for (int j = 0; j < string.length; ++j)
+              {
+                if (string[j] == ch)
+                  {
+                    offset = index;
+                    break searchLoop;
+                  }
+              }
+            index++;
+          }
+      }
+    catch (BadLocationException ex)
+      {
+        // Ignore this and return -1.
+      }
+    return offset;
+  }
+
+  protected int getClosestPositionTo(int pos, Position.Bias bias, Shape a,
+                                     int direction, Position.Bias[] biasRet,
+                                     int rowIndex, int x)
+    throws BadLocationException
+  {
+    // FIXME: Implement this properly. However, this looks like it might
+    // have been replaced by viewToModel.
+    return pos;
+  }
+
+  /**
+   * Returns the size that is used by this view (or it's child views) between
+   * <code>startOffset</code> and <code>endOffset</code>. If the child views
+   * implement the [EMAIL PROTECTED] TabableView} interface, then this is used to
+   * determine the span, otherwise we use the preferred span of the child
+   * views.
+   *
+   * @param startOffset the start offset
+   * @param endOffset the end offset
+   *
+   * @return the span used by the view between <code>startOffset</code> and
+   *         <code>endOffset</cod>
+   */
+  protected float getPartialSize(int startOffset, int endOffset)
+  {
+    int startIndex = getViewIndex(startOffset, Position.Bias.Backward);
+    int endIndex = getViewIndex(endOffset, Position.Bias.Forward);
+    float span;
+    if (startIndex == endIndex)
+      {
+        View child = getView(startIndex);
+        if (child instanceof TabableView)
+          {
+            TabableView tabable = (TabableView) child;
+            span = tabable.getPartialSpan(startOffset, endOffset);
+          }
+        else
+          span = child.getPreferredSpan(X_AXIS);
+      }
+    else if (endIndex - startIndex == 1)
+      {
+        View child1 = getView(startIndex);
+        if (child1 instanceof TabableView)
+          {
+            TabableView tabable = (TabableView) child1;
+            span = tabable.getPartialSpan(startOffset, child1.getEndOffset());
+          }
+        else
+          span = child1.getPreferredSpan(X_AXIS);
+        View child2 = getView(endIndex);
+        if (child2 instanceof TabableView)
+          {
+            TabableView tabable = (TabableView) child2;
+            span += tabable.getPartialSpan(child2.getStartOffset(), endOffset);
+          }
+        else
+          span += child2.getPreferredSpan(X_AXIS);
+      }
+    else
+      {
+        // Start with the first view.
+        View child1 = getView(startIndex);
+        if (child1 instanceof TabableView)
+          {
+            TabableView tabable = (TabableView) child1;
+            span = tabable.getPartialSpan(startOffset, child1.getEndOffset());
+          }
+        else
+          span = child1.getPreferredSpan(X_AXIS);
+
+        // Add up the view spans between the start and the end view.
+        for (int i = startIndex + 1; i < endIndex; i++)
+          {
+            View child = getView(i);
+            span += child.getPreferredSpan(X_AXIS);
+          }
+
+        // Add the span of the last view.
+        View child2 = getView(endIndex);
+        if (child2 instanceof TabableView)
+          {
+            TabableView tabable = (TabableView) child2;
+            span += tabable.getPartialSpan(child2.getStartOffset(), endOffset);
+          }
+        else
+          span += child2.getPreferredSpan(X_AXIS);
+      }
+    return span;
+  }
+
+  /**
+   * Returns the location where the tabs are calculated from. This returns
+   * <code>0.0F</code> by default.
+   *
+   * @return the location where the tabs are calculated from
+   */
+  protected float getTabBase()
+  {
+    return 0.0F;
+  }
+
+  /**
+   * @specnote This method is specified to take a Row parameter, which is a
+   *           private inner class of that class, which makes it unusable from
+   *           application code. Also, this method seems to be replaced by
+   *           [EMAIL PROTECTED] FlowStrategy#adjustRow(FlowView, int, int, int)}.
+   *
+   */
+  protected void adjustRow(Row r, int desiredSpan, int x)
+  {
+  }
+
+  /**
+   * @specnote This method's signature differs from the one defined in
+   *           [EMAIL PROTECTED] View} and is therefore never called. It is probably there
+   *           for historical reasons.
+   */
+  public View breakView(int axis, float len, Shape a)
+  {
+    // This method is not used.
+    return null;
+  }
+
+  /**
+   * @specnote This method's signature differs from the one defined in
+   *           [EMAIL PROTECTED] View} and is therefore never called. It is probably there
+   *           for historical reasons.
+   */
+  public int getBreakWeight(int axis, float len)
+  {
+    // This method is not used.
+    return 0;
+  }
+
 }

Reply via email to