|                                                                                                              1
 19
 20  package org.netbeans.lib.editor.view;
 21
 22  import java.awt.Component
  ; 23  import java.awt.Graphics
  ; 24  import java.awt.Rectangle
  ; 25  import java.awt.Shape
  ; 26  import javax.swing.text.AbstractDocument
  ; 27  import javax.swing.text.View
  ; 28  import org.netbeans.editor.view.spi.EstimatedSpanView;
 29  import org.netbeans.editor.view.spi.LockView;
 30  import org.netbeans.editor.view.spi.ViewInsets;
 31  import org.netbeans.editor.view.spi.ViewLayoutQueue;
 32  import org.netbeans.editor.view.spi.ViewLayoutState;
 33
 34
 36
 55
 56  class GapBoxViewChildren extends GapObjectArray implements GapObjectArray.RemoveUpdater {
 57
 58      GapBoxViewChildren(GapBoxView view) {
 59          this.view = view;
 60
 61          indexGapLength = INITIAL_INDEX_GAP_LENGTH;
 62          majorAxisOffsetGapLength = INITIAL_MAJOR_AXIS_OFFSET_GAP_LENGTH;
 63      }
 64
 65
 75      private static final int INITIAL_INDEX_GAP_LENGTH
 76          = Integer.MAX_VALUE >> 1;
 77
 78
 104     private static final double INITIAL_MAJOR_AXIS_OFFSET_GAP_LENGTH
 105         = 0d;
 106
 107
 111     protected final GapBoxView view;
 113
 129     private double majorAxisOffsetGapLength;
 131
 135     private int majorAxisOffsetGapIndex;
 137
 147     private int indexGapLength;
 149
 159     private int firstUpdateLayoutChildIndex;
 161
 167     private int updateLayoutChildCount;
 169
 172     private float minorAxisPreferredSpan;
 174
 180     private int maxMinorAxisPreferredSpanChildIndex = -1;
 182
 186     private int firstRepaintChildIndex = -1;
 188
 190     public int getChildCount() {
 191         return getItemCount();
 192     }
 193
 194     public ViewLayoutState getChild(int index) {
 195         return (ViewLayoutState)getItem(index);
 196     }
 197
 198     public int getChildIndex(ViewLayoutState child) {
 199         int childIndex = getChildIndexNoCheck(child);
 200         if (childIndex >= getChildCount() || getChild(childIndex) != child) {
 201             childIndex = -1;
 202         }
 203         return childIndex;
 204     }
 205
 206     public int getChildIndexNoCheck(ViewLayoutState child) {
 207         return getTranslatedChildIndex(child.getViewRawIndex());
 208     }
 209
 210     private int getTranslatedChildIndex(int rawIndex) {
 211         if (rawIndex >= indexGapLength) {
 212             rawIndex -= indexGapLength;
 213         }
 214         return rawIndex;
 215     }
 216
 217     public void replace(int index, int length, View
  [] views) { 218
 221         checkConsistency();
 222
 223         int insertLength = (views != null) ? views.length : 0;
 224
 225
 227                         if (isReplaceRemovingIndexes(index, length)) {
 234             int neighborIndex;
 235             int neighborIndexAfterReplace;
 236             ViewLayoutState neighbor;
 237             int endRemoveIndex = index + length;
 238             if (index > 0) {
 239                 neighborIndex = index - 1;
 240                 neighborIndexAfterReplace = neighborIndex;
 241                 neighbor = getChild(neighborIndex);
 242
 243             } else if (endRemoveIndex < getChildCount()) {
 244                 neighborIndex = endRemoveIndex;
 245                 neighborIndexAfterReplace = index + insertLength;
 246                 neighbor = getChild(neighborIndex);
 247             } else {                 neighborIndex = -1;
 249                 neighborIndexAfterReplace = -1;
 250                 neighbor = null;
 251             }
 252
 253             replaceUpdateIndexes(index, length, insertLength,
 254                 neighborIndex, neighborIndexAfterReplace, neighbor);
 255
 256         } else {             replaceUpdateIndexes(index, length, insertLength);
 258         }
 259
 260         double childMajorAxisOffset = 0;
 261         if (length == 0) {             if (getChildCount() == 0) {                 ensureCapacity(insertLength);             }
 265
 266         } else {             int endIndex = index + length;
 268
 269             removeInvalidChildIndexesArea(index, length);
 270
 271             moveMajorAxisOffsetGap(endIndex);             moveIndexGap(endIndex);
 273
 274                         childMajorAxisOffset = getMajorAxisOffset(index);             double majorAxisRemovedSpan = getMajorAxisOffset(endIndex)
 277                 - childMajorAxisOffset;
 278             majorAxisOffsetGapIndex = index;
 279             majorAxisOffsetGapLength += majorAxisRemovedSpan;
 281                         indexGapLength += length;
 283
 284                         remove(index, length, this);
 287         }
 288
 289                 if (insertLength > 0) {
 291             if (length == 0) {                 moveIndexGap(index);
 293                 moveMajorAxisOffsetGap(index);
 294                 childMajorAxisOffset = getMajorAxisOffset(index) - majorAxisOffsetGapLength;
 295             }
 296
 297
 299             int majorAxis = view.getMajorAxis();
 300             boolean estimatedSpan = view.isEstimatedSpan();
 301             boolean childEstimatedSpan;
 302             boolean insertLengthAboveThreshold;
 303             if (estimatedSpan) {
 304                 childEstimatedSpan = true;
 305                 insertLengthAboveThreshold = false;
 307             } else {                 insertLengthAboveThreshold = (insertLength >= view.getReplaceEstimatedThreshold());
 309                 childEstimatedSpan = insertLengthAboveThreshold;
 310             }
 311
 312             for (int i = 0; i < insertLength; i++) {
 313                 ViewLayoutState child = view.createChild(views[i]);
 314                 View
  childView = child.getView(); 315                 int childIndex = index + i;
 316
 317                 if (childEstimatedSpan && (childView instanceof EstimatedSpanView)) {
 318                     ((EstimatedSpanView)childView).setEstimatedSpan(childEstimatedSpan);
 319                 }
 320
 321                 child.selectLayoutMajorAxis(majorAxis);
 322
 323                 insertItem(childIndex, child);
 324                 indexGapLength--;
 325                 majorAxisOffsetGapIndex++;
 326
 327                 if (!child.isFlyweight()) {
 328                     child.setViewRawIndex(childIndex);                     child.setLayoutMajorAxisRawOffset(childMajorAxisOffset);
 330
 331                                                             childView.setParent(view);
 334
 335                                         child.viewPreferenceChanged(true, true);
 337
 338                                                                                 moveMajorAxisOffsetGap(childIndex + 1);
 342
 343                                                             childMajorAxisOffset = child.getLayoutMajorAxisRawOffset() + child.getLayoutMajorAxisPreferredSpan();
 346
 347                 } else {                     childMajorAxisOffset += child.getLayoutMajorAxisPreferredSpan();
 349                 }
 350
 351             }
 352
 353             if (childEstimatedSpan && !estimatedSpan) {
 354                 view.resetEstimatedSpan(index, insertLength);
 355             }
 356         }
 357
 358                 view.markMajorAxisPreferenceChanged();
 360                         markLayoutInvalid(index, insertLength);
 363                 view.markRepaint(index, true);
 365
 366
 369         checkConsistency();
 370     }
 371
 372         public void removeUpdate(Object
  removedItem) { 374         releaseChild((ViewLayoutState)removedItem);
 375     }
 376
 377     protected void releaseChild(ViewLayoutState child) {
 378         if (!child.isFlyweight()) {
 379             child.getView().setParent(null);
 380         }
 381
 382     }
 383
 384
 391     protected boolean isReplaceRemovingIndexes(int index, int removeLength) {
 392         int ind = getMaxMinorAxisPreferredSpanChildIndex();
 393         return (!view.isChildrenLayoutNecessary()
 394             && ind >= index && ind < index + removeLength);
 395     }
 396
 397
 398
 409     protected void replaceUpdateIndexes(int index, int removeLength, int insertLength) {
 410                         if (!view.isChildrenLayoutNecessary()) {
 413             int endRemoveIndex = index + removeLength;
 414                                                 int ind = getMaxMinorAxisPreferredSpanChildIndex();
 418             if (ind >= endRemoveIndex) {                 setMaxMinorAxisPreferredSpanChildIndex(ind + insertLength - removeLength);
 420             }
 421         }
 422     }
 423
 424
 443     protected void replaceUpdateIndexes(int index, int removeLength, int insertLength,
 444     int neighborIndex, int neighborIndexAfterReplace, ViewLayoutState neighbor) {
 445
 446                         if (!view.isChildrenLayoutNecessary()) {
 449             int endRemoveIndex = index + removeLength;
 450
 460             int ind = getMaxMinorAxisPreferredSpanChildIndex();
 461             if (ind >= endRemoveIndex) {                 setMaxMinorAxisPreferredSpanChildIndex(ind + insertLength - removeLength);
 463
 464             } else if (ind >= index) {                 if (neighbor == null || neighbor.getLayoutMinorAxisPreferredSpan()
 466                     < view.getMinorAxisPreferredSpan()
 467                 ) {
 468                                                                                 view.markChildrenLayoutNecessary();
 472                 }
 473                 setMaxMinorAxisPreferredSpanChildIndex(neighborIndexAfterReplace);
 474             }
 475         }
 476     }
 477
 478
 481     public double getMajorAxisOffset(int childIndex) {
 482         if (childIndex < getChildCount()) {             ViewLayoutState child = getChild(childIndex);
 484             if (!child.isFlyweight()) {
 485                 double offset = child.getLayoutMajorAxisRawOffset();
 486                 if (childIndex >= majorAxisOffsetGapIndex) {
 487                     offset -= majorAxisOffsetGapLength;
 488                 }
 489                 return offset;
 490             }
 491         }
 492
 493         double majorAxisOffset = 0;
 494         while (--childIndex >= 0) {
 495             ViewLayoutState child = getChild(childIndex);
 496             majorAxisOffset += child.getLayoutMajorAxisPreferredSpan();
 497             if (!child.isFlyweight()) {
 498                 double offset = child.getLayoutMajorAxisRawOffset();
 499                 if (childIndex >= majorAxisOffsetGapIndex) {
 500                     offset -= majorAxisOffsetGapLength;
 501                 }
 502                 majorAxisOffset += offset;
 503                 break;
 504             }
 505         }
 506
 507         return majorAxisOffset;
 508     }
 509
 510
 514     protected double getMajorAxisPreferredSpan() {
 515         return INITIAL_MAJOR_AXIS_OFFSET_GAP_LENGTH - majorAxisOffsetGapLength;
 516     }
 517
 518     protected final float getMinorAxisPreferredSpan() {
 519         return minorAxisPreferredSpan;
 520     }
 521
 522     protected void setMinorAxisPreferredSpan(float minorAxisPreferredSpan) {
 523         this.minorAxisPreferredSpan = minorAxisPreferredSpan;
 524     }
 525
 526
 529     protected float getMinorAxisOffset(ViewLayoutState child) {
 530         float minorAxisAssignedSpan = view.getMinorAxisAssignedSpan();
 531         float childPreferredSpan = child.getLayoutMinorAxisPreferredSpan();
 532         if (childPreferredSpan < minorAxisAssignedSpan) {
 533                         float align = child.getLayoutMinorAxisAlignment();
 535             return ((minorAxisAssignedSpan - childPreferredSpan) * align);
 536         }
 537
 538         return 0f;
 539     }
 540
 541     protected float getMinorAxisSpan(ViewLayoutState child) {
 542         float minorAxisAssignedSpan = view.getMinorAxisAssignedSpan();
 543         float childPreferredSpan = child.getLayoutMinorAxisPreferredSpan();
 544         return (childPreferredSpan < minorAxisAssignedSpan)             ? childPreferredSpan
 546             : minorAxisAssignedSpan;
 547     }
 548
 549
 557     protected void majorAxisPreferenceChanged(ViewLayoutState child,
 558     int childIndex, double majorAxisSpanDelta) {
 559
 560         moveMajorAxisOffsetGap(childIndex + 1);
 561         majorAxisOffsetGapLength -= majorAxisSpanDelta;
 562         view.markMajorAxisPreferenceChanged();
 563     }
 564
 565
 573     protected void minorAxisPreferenceChanged(ViewLayoutState child, int childIndex) {
 574                         if (!view.isChildrenLayoutNecessary()) {
 577             float preferredSpan = child.getLayoutMinorAxisPreferredSpan();
 578             float minorAxisPreferredSpan = getMinorAxisPreferredSpan();
 579             int maxPreferredSpanIndex= getMaxMinorAxisPreferredSpanChildIndex();
 580
 581             if (maxPreferredSpanIndex == -1                 || preferredSpan > minorAxisPreferredSpan
 583             ) {
 584                 setMinorAxisPreferredSpan(preferredSpan);
 585                 view.markMinorAxisPreferenceChanged();                 setMaxMinorAxisPreferredSpanChildIndex(childIndex);
 587
 588             } else if (childIndex == maxPreferredSpanIndex
 589                 && preferredSpan < minorAxisPreferredSpan
 590             ) {                                                 view.markChildrenLayoutNecessary();
 594             }
 595         }
 596     }
 597
 598     public int getChildStartOffset(int childIndex) {
 599         ViewLayoutState child = getChild(childIndex);
 600         if (!child.isFlyweight()) {
 601             return child.getView().getStartOffset();
 602         }
 603
 604         int startOffset = 0;
 605         while (--childIndex >= 0) {
 606             child = getChild(childIndex);
 607
 610             startOffset += child.getView().getEndOffset();
 611             if (!child.isFlyweight()) {
 612                 break;
 613             }
 614         }
 615
 616         return startOffset;
 617     }
 618
 619     public int getChildEndOffset(int childIndex) {
 620         int endOffset = 0;
 621         while (childIndex >= 0) {
 622             ViewLayoutState child = getChild(childIndex--);
 623             endOffset += child.getView().getEndOffset();
 624             if (!child.isFlyweight()) {                 break;
 626             }
 627         }
 628
 629         return endOffset;
 630     }
 631
 632
 641     public Rectangle
  getChildCoreAllocation(int childIndex, Rectangle  targetRect) { 642         childrenUpdateLayout(childIndex);
 644         if (targetRect == null) {
 645             targetRect = new Rectangle
  (); 646         }
 647
 648         ViewLayoutState child = getChild(childIndex);
 649         int majorAxisOffsetInt = (int)getMajorAxisOffset(childIndex);
 650         int minorAxisOffsetInt = (int)getMinorAxisOffset(child);
 651         int majorAxisSpanInt = (int)child.getLayoutMajorAxisPreferredSpan();
 652         int minorAxisSpanInt = (int)getMinorAxisSpan(child);
 653
 654         if (view.isXMajorAxis()) {
 655             targetRect.x = majorAxisOffsetInt;
 656             targetRect.y = minorAxisOffsetInt;
 657             targetRect.width = majorAxisSpanInt;
 658             targetRect.height = minorAxisSpanInt;
 659
 660         } else {
 661             targetRect.x = minorAxisOffsetInt;
 662             targetRect.y = majorAxisOffsetInt;
 663             targetRect.width = minorAxisSpanInt;
 664             targetRect.height = majorAxisSpanInt;
 665         }
 666
 667         ViewInsets insets = view.getInsets();
 668         if (insets != null) {
 669             targetRect.x += (int)insets.getLeft();
 670             targetRect.y += (int)insets.getTop();
 671         }
 672
 673         return targetRect;
 674     }
 675
 676
 688     public int getChildIndexAtCorePoint(float x, float y) {
 689         int childCount = getChildCount();
 690         int low = 0;
 691         int high = childCount - 1;
 692
 693         if (high == -1) {             return -1;
 695         }
 696
 697         double majorAxisOffset = view.isXMajorAxis() ? x : y;
 698
 699         int luChildCount = getUpdateLayoutChildCount();
 700         if (luChildCount > 0) {             int firstLUChildIndex = getFirstUpdateLayoutChildIndex();
 702             if (getMajorAxisOffset(firstLUChildIndex) <= majorAxisOffset) {                 childrenUpdateLayout(high);                 low = firstLUChildIndex;
 705
 706             } else {                 high = firstLUChildIndex - 1;
 708             }
 709         }
 710
 711         while (low <= high) {
 712             int mid = (low + high) / 2;
 713             ViewLayoutState child = getChild(mid);
 714             double midMajorAxisOffset = getMajorAxisOffset(mid);
 715
 716             if (midMajorAxisOffset < majorAxisOffset) {
 717                 low = mid + 1;
 718             } else if (midMajorAxisOffset > majorAxisOffset) {
 719                 high = mid - 1;
 720             } else {
 721                                 return mid;
 723             }
 724         }
 725
 726
 729                 if (high < 0) {
 731             high = 0;
 732         }
 733
 734         return high;
 735     }
 736
 737
 744     protected void paintChildren(Graphics
  g, Rectangle  alloc) { 745         int viewAllocX = alloc.x;
 746         int viewAllocY = alloc.y;
 747
 750         alloc = g.getClipBounds(alloc);         if (alloc == null) {             return;
 753         }
 754         int clipX = alloc.x;
 755         int clipY = alloc.y;
 756         boolean isXMajorAxis = view.isXMajorAxis();
 757         int clipEnd = isXMajorAxis
 758             ? (clipX + alloc.width)
 759             : (clipY + alloc.height);
 760
 761
 762         int childIndex = getChildIndexAtCorePoint(clipX, clipY);
 763         int childCount = getChildCount();
 764
 765         for (int i = Math.max(childIndex, 0); i < childCount; i++) {
 766             ViewLayoutState child = getChild(i);
 767                         alloc = getChildCoreAllocation(i, alloc);
 769             alloc.x += viewAllocX;
 770             alloc.y += viewAllocY;
 771
 778             int allocStart = isXMajorAxis ? alloc.x : alloc.y;
 779
 780             if (allocStart < clipEnd) {
 782                 View
  v = child.getView(); 783                 v.paint(g, alloc);
 784             } else {
 785                 break;             }
 787         }
 788     }
 789
 790     protected final int getFirstRepaintChildIndex() {
 791         return firstRepaintChildIndex;
 792     }
 793
 794     final void setFirstRepaintChildIndex(int firstRepaintChildIndex) {
 795         this.firstRepaintChildIndex = firstRepaintChildIndex;
 796     }
 797
 798     final int getMaxMinorAxisPreferredSpanChildIndex() {
 799         return maxMinorAxisPreferredSpanChildIndex;
 800     }
 801
 802     void setMaxMinorAxisPreferredSpanChildIndex(int maxMinorAxisPreferredSpanChildIndex) {
 803         this.maxMinorAxisPreferredSpanChildIndex = maxMinorAxisPreferredSpanChildIndex;
 804     }
 805
 806
 809     final int getFirstUpdateLayoutChildIndex() {
 810         return firstUpdateLayoutChildIndex;
 811     }
 812
 813
 819     final int getUpdateLayoutChildCount() {
 820         return updateLayoutChildCount;
 821     }
 822
 823     void markLayoutInvalid(int firstChildIndex, int count) {
 824         if (count > 0) {
 825             if (updateLayoutChildCount > 0) {
 826                 int endInvalid = firstUpdateLayoutChildIndex + updateLayoutChildCount;                 firstUpdateLayoutChildIndex = Math.min(firstUpdateLayoutChildIndex, firstChildIndex);
 828                 updateLayoutChildCount = Math.max(endInvalid, firstChildIndex + count)
 829                     - firstUpdateLayoutChildIndex;
 830
 831             } else {                 firstUpdateLayoutChildIndex = firstChildIndex;
 833                 updateLayoutChildCount = count;
 834                                                                 view.markLayoutInvalid();
 838             }
 839         }
 840     }
 841
 842
 846     void removeInvalidChildIndexesArea(int firstChildIndex, int count) {
 847         int endChildIndex = firstChildIndex + count;
 848         if (updateLayoutChildCount > 0) {             int endInvalid = firstUpdateLayoutChildIndex + updateLayoutChildCount;
 850             if (endInvalid > firstChildIndex) {                 if (firstUpdateLayoutChildIndex >= endChildIndex) {                     firstUpdateLayoutChildIndex -= count;
 853                 } else if (firstUpdateLayoutChildIndex < firstChildIndex) {                     updateLayoutChildCount -= Math.min(endInvalid, endChildIndex) - firstChildIndex;
 855                 } else {                     updateLayoutChildCount -= Math.min(endInvalid, endChildIndex) - firstUpdateLayoutChildIndex;
 857                     firstUpdateLayoutChildIndex = endChildIndex;
 858                     while (updateLayoutChildCount > 0 && getChild(firstUpdateLayoutChildIndex).isFlyweight()) {
 859                         firstUpdateLayoutChildIndex++;
 860                         updateLayoutChildCount--;
 861                     }
 862                 }
 863             }
 864         }
 865     }
 866
 867
 874     protected final void childrenUpdateLayout(int tillChildIndex) {
 875         while (updateLayoutChildCount > 0 && firstUpdateLayoutChildIndex <= tillChildIndex) {
 876             updateLayoutChildCount--;
 877             ViewLayoutState child = getChild(firstUpdateLayoutChildIndex++);
 878             child.updateLayout();
 879         }
 880     }
 881
 882     protected final void childrenUpdateLayout() {
 883         childrenUpdateLayout(Integer.MAX_VALUE);
 884     }
 885
 886
 900     protected void childrenLayout() {
 901
 904         int childCount = getChildCount();
 905         int maxPreferredSpanChildIndex = -1;
 906         float maxPreferredSpan = 0f;
 907
 908         for (int i = 0; i < childCount; i++) {
 909             ViewLayoutState child = getChild(i);
 910             float span = child.getLayoutMinorAxisPreferredSpan();
 911             if (span > maxPreferredSpan) {
 912                 maxPreferredSpanChildIndex = i;
 913                 maxPreferredSpan = span;
 914             }
 915
 916         }
 917                 setMaxMinorAxisPreferredSpanChildIndex(maxPreferredSpanChildIndex);
 919
 920                 if (maxPreferredSpan != getMinorAxisPreferredSpan()) {
 922             setMinorAxisPreferredSpan(maxPreferredSpan);
 923             view.markMinorAxisPreferenceChanged();
 924         }
 925     }
 926
 927     protected void unload() {
 928         int childCount = getChildCount();
 929         for (int i = 0; i < childCount; i++) {
 930             releaseChild(getChild(i));
 931         }
 932     }
 933
 934     private void moveIndexGap(int index) {
 935         checkConsistency();
 936
 937         int gapLen = indexGapLength;         int belowIndex = index;
 939         boolean updated = false;
 940         while (--belowIndex >= 0) {
 941             ViewLayoutState child = getChild(belowIndex);
 942             if (!child.isFlyweight()) {
 943                 int rawIndex = child.getViewRawIndex();
 944                 if (rawIndex >= gapLen) {
 945                     child.setViewRawIndex(rawIndex - gapLen);
 946                     updated = true;
 947                 } else {                     break;                 }
 950             }
 951         }
 952
 953         if (!updated) {             int childCount = getChildCount();
 955             while (index < childCount) {
 956                 ViewLayoutState child = getChild(index++);
 957                 if (!child.isFlyweight()) {
 958                     int rawIndex = child.getViewRawIndex();
 959                     if (rawIndex < gapLen) {                         child.setViewRawIndex(rawIndex + gapLen);
 961                     } else {
 962                         break;                     }
 964                 }
 965             }
 966         }
 967
 968         checkConsistency();
 969     }
 970
 971     private void moveMajorAxisOffsetGap(int index) {
 972         if (index == majorAxisOffsetGapIndex) {
 973             return;         }
 975
 976         checkConsistency();
 977
 978         if (index < majorAxisOffsetGapIndex) {             while (--majorAxisOffsetGapIndex >= index) {
 980                 ViewLayoutState child = getChild(majorAxisOffsetGapIndex);
 981                 if (!child.isFlyweight()) {
 982                     child.setLayoutMajorAxisRawOffset(child.getLayoutMajorAxisRawOffset()
 983                         + majorAxisOffsetGapLength);
 984                 }
 985             }
 986             majorAxisOffsetGapIndex++;
 987
 988         } else {             while (majorAxisOffsetGapIndex < index) {                 ViewLayoutState child = getChild(majorAxisOffsetGapIndex);
 991                 if (!child.isFlyweight()) {
 992                     child.setLayoutMajorAxisRawOffset(child.getLayoutMajorAxisRawOffset()
 993                         - majorAxisOffsetGapLength);
 994                 }
 995                 majorAxisOffsetGapIndex++;
 996             }
 997         }
 998
 999         checkConsistency();
 1000    }
 1001
 1002    private void checkConsistency() {
 1003        if (true) {
 1004            return;         }
 1006
 1008        int childCount = getChildCount();
 1009        if (majorAxisOffsetGapIndex > childCount) {
 1010            throw new IllegalStateException
  ( 1011                "majorAxisOffsetGapIndex=" + majorAxisOffsetGapIndex                 + " > childCount=" + childCount             );
 1014        }
 1015
 1016        int indexGapStart = computeIndexGapStart();
 1017        int lastRawIndex = -1;
 1018        double lastMajorAxisOffset = 0;
 1019        for (int i = 0; i < childCount; i++) {
 1020            ViewLayoutState child = getChild(i);
 1021
 1022            int rawIndex = child.getViewRawIndex();
 1023            if (rawIndex <= lastRawIndex) {
 1024                throw new IllegalStateException
  ("rawIndex=" + rawIndex                     + " at index=" + i                     + " <= lastRawIndex=" + lastRawIndex);             } 1028
 1029            if (rawIndex >= indexGapLength && rawIndex < indexGapStart) {
 1030                throw new IllegalStateException
  ("Above gap rawIndex=" + rawIndex                     + " at index=" + i                     + " but gap seems to start at index " + indexGapStart);             } 1034
 1035            if (rawIndex < indexGapLength && rawIndex >= indexGapStart) {
 1036                throw new IllegalStateException
  ("Below gap rawIndex=" + rawIndex                     + " at index=" + i                     + " but gap seems to start at index " + indexGapStart);             } 1040
 1041            if (getChildIndexNoCheck(child) != i) {
 1042                throw new IllegalStateException
  ("Child at index=" + i                     + " has internal index=" + getChildIndexNoCheck(child));             } 1045
 1046
 1047            double childMajorAxisOffset = child.getLayoutMajorAxisRawOffset();
 1048            if (i >= majorAxisOffsetGapIndex) {
 1049                childMajorAxisOffset -= majorAxisOffsetGapLength;
 1050            }
 1051
 1052            if (childMajorAxisOffset < lastMajorAxisOffset) {
 1053                throw new IllegalStateException
  ( 1054                    "childMajorAxisOffset=" + childMajorAxisOffset                     + " at index=" + i                     + " < lastMajorAxisOffset=" + lastMajorAxisOffset);             }
 1058
 1059            if (childMajorAxisOffset < 0) {
 1060                throw new IllegalStateException
  ("Major axis offset at index=" + i                     + " is " + childMajorAxisOffset + " < 0");             } 1063        }
 1064    }
 1065
 1066    private int computeIndexGapStart() {
 1067        int childCount = getChildCount();
 1068        for (int i = 0; i < childCount; i++) {
 1069            if (getChild(i).getViewRawIndex() >= indexGapLength) {
 1070                return  i;
 1071            }
 1072        }
 1073        return childCount;
 1074    }
 1075
 1076    public String
  toStringDetail() { 1077        StringBuffer
  sb = new StringBuffer  (); 1078        sb.append(view.toString());
 1079        sb.append(", indexGapStart=");         sb.append(computeIndexGapStart());
 1081        sb.append(", majorAxisOffsetGapIndex=");         sb.append(majorAxisOffsetGapIndex);
 1083        sb.append(", majorAxisOffsetGapLength=");         sb.append(majorAxisOffsetGapLength);
 1085
 1086
 1087        sb.append(view.childrenToString());
 1088
 1089        return sb.toString();
 1090    }
 1091
 1092}
 1093
                                                                                                                                                                                                             |                                                                       
 
 
 
 
 
                                                                                   Popular Tags                                                                                                                                                                                              |