コード例 #1
0
    /**
     * Adjusts the given row if possible to fit within the layout span. By default this will try to
     * find the highest break weight possible nearest the end of the row. If a forced break is
     * encountered, the break will be positioned there.
     *
     * @param rowIndex the row to adjust to the current layout span.
     * @param desiredSpan the current layout span >= 0
     * @param x the location r starts at.
     */
    protected void adjustRow(FlowView fv, int rowIndex, int desiredSpan, int x) {
      final int flowAxis = fv.getFlowAxis();
      View r = fv.getView(rowIndex);
      int n = r.getViewCount();
      int span = 0;
      int bestWeight = BadBreakWeight;
      int bestSpan = 0;
      int bestIndex = -1;
      int bestOffset = 0;
      View v;
      for (int i = 0; i < n; i++) {
        v = r.getView(i);
        int spanLeft = desiredSpan - span;

        int w = v.getBreakWeight(flowAxis, x + span, spanLeft);
        if ((w >= bestWeight) && (w > BadBreakWeight)) {
          bestWeight = w;
          bestIndex = i;
          bestSpan = span;
          if (w >= ForcedBreakWeight) {
            // it's a forced break, so there is
            // no point in searching further.
            break;
          }
        }
        span += v.getPreferredSpan(flowAxis);
      }
      if (bestIndex < 0) {
        // there is nothing that can be broken, leave
        // it in it's current state.
        return;
      }

      // Break the best candidate view, and patch up the row.
      int spanLeft = desiredSpan - bestSpan;
      v = r.getView(bestIndex);
      v = v.breakView(flowAxis, v.getStartOffset(), x + bestSpan, spanLeft);
      View[] va = new View[1];
      va[0] = v;
      View lv = getLogicalView(fv);
      for (int i = bestIndex; i < n; i++) {
        View tmpView = r.getView(i);
        if (contains(lv, tmpView)) {
          tmpView.setParent(lv);
        } else if (tmpView.getViewCount() > 0) {
          recursiveReparent(tmpView, lv);
        }
      }
      r.replace(bestIndex, n - bestIndex, va);
    }
コード例 #2
0
ファイル: View.java プロジェクト: subxiang/jdk-source-code
 /**
  * Updates the child views in response to receiving notification that the model changed, and there
  * is change record for the element this view is responsible for. This is implemented to assume
  * the child views are directly responsible for the child elements of the element this view
  * represents. The <code>ViewFactory</code> is used to create child views for each element
  * specified as added in the <code>ElementChange</code>, starting at the index specified in the
  * given <code>ElementChange</code>. The number of child views representing the removed elements
  * specified are removed.
  *
  * @param ec the change information for the element this view is responsible for. This should not
  *     be <code>null</code> if this method gets called
  * @param e the change information from the associated document
  * @param f the factory to use to build child views
  * @return whether or not the child views represent the child elements of the element this view is
  *     responsible for. Some views create children that represent a portion of the element they
  *     are responsible for, and should return false. This information is used to determine if
  *     views in the range of the added elements should be forwarded to or not
  * @see #insertUpdate
  * @see #removeUpdate
  * @see #changedUpdate
  * @since 1.3
  */
 protected boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent e, ViewFactory f) {
   Element[] removedElems = ec.getChildrenRemoved();
   Element[] addedElems = ec.getChildrenAdded();
   View[] added = null;
   if (addedElems != null) {
     added = new View[addedElems.length];
     for (int i = 0; i < addedElems.length; i++) {
       added[i] = f.create(addedElems[i]);
     }
   }
   int nremoved = 0;
   int index = ec.getIndex();
   if (removedElems != null) {
     nremoved = removedElems.length;
   }
   replace(index, nremoved, added);
   return true;
 }
コード例 #3
0
ファイル: View.java プロジェクト: subxiang/jdk-source-code
 /**
  * Appends a single child view. This is a convenience call to <code>replace</code>.
  *
  * @param v the view
  * @see #replace
  * @since 1.3
  */
 public void append(View v) {
   View[] one = new View[1];
   one[0] = v;
   replace(getViewCount(), 0, one);
 }
コード例 #4
0
ファイル: View.java プロジェクト: subxiang/jdk-source-code
 /**
  * Inserts a single child view. This is a convenience call to <code>replace</code>.
  *
  * @param offs the offset of the view to insert before >= 0
  * @param v the view
  * @see #replace
  * @since 1.3
  */
 public void insert(int offs, View v) {
   View[] one = new View[1];
   one[0] = v;
   replace(offs, 0, one);
 }
コード例 #5
0
ファイル: View.java プロジェクト: subxiang/jdk-source-code
 /**
  * Removes one of the children at the given position. This is a convenience call to <code>replace
  * </code>.
  *
  * @since 1.3
  */
 public void remove(int i) {
   replace(i, 1, null);
 }
コード例 #6
0
ファイル: View.java プロジェクト: subxiang/jdk-source-code
 /**
  * Removes all of the children. This is a convenience call to <code>replace</code>.
  *
  * @since 1.3
  */
 public void removeAll() {
   replace(0, getViewCount(), null);
 }