347 * be reimplemented to alter the breaking behavior.
348 * It will either break at word or character boundaries
349 * depending upon the break argument given at
350 * construction.
351 * @param p0 the starting document location
352 * @param p1 the ending document location to use
353 * @return the break position
354 */
355 @SuppressWarnings("deprecation")
356 protected int calculateBreakPosition(int p0, int p1) {
357 int p;
358 Segment segment = SegmentCache.getSharedSegment();
359 loadText(segment, p0, p1);
360 int currentWidth = getWidth();
361 if (wordWrap) {
362 p = p0 + Utilities.getBreakLocation(segment, metrics,
363 tabBase, tabBase + currentWidth,
364 this, p0);
365 } else {
366 p = p0 + Utilities.getTabbedTextOffset(segment, metrics,
367 tabBase, tabBase + currentWidth,
368 this, p0, false);
369 }
370 SegmentCache.releaseSharedSegment(segment);
371 return p;
372 }
373
374 /**
375 * Loads all of the children to initialize the view.
376 * This is called by the <code>setParent</code> method.
377 * Subclasses can reimplement this to initialize their
378 * child views in a different manner. The default
379 * implementation creates a child view for each
380 * child element.
381 *
382 * @param f the view factory
383 */
384 protected void loadChildren(ViewFactory f) {
385 Element e = getElement();
386 int n = e.getElementCount();
387 if (n > 0) {
830 p1 = getEndOffset();
831 } else {
832 int[] lineEnds = getLineEnds();
833 p1 = p0 + lineEnds[line];
834 if (line > 0) {
835 p0 += lineEnds[line - 1];
836 }
837 }
838
839 if (x < alloc.x) {
840 // point is to the left of the line
841 return p0;
842 } else if (x > alloc.x + alloc.width) {
843 // point is to the right of the line
844 return p1 - 1;
845 } else {
846 // Determine the offset into the text
847 Segment segment = SegmentCache.getSharedSegment();
848 loadText(segment, p0, p1);
849 int n = Utilities.getTabbedTextOffset(segment, metrics,
850 alloc.x, x,
851 WrappedPlainView.this, p0);
852 SegmentCache.releaseSharedSegment(segment);
853 return Math.min(p0 + n, p1 - 1);
854 }
855 }
856 }
857 }
858
859 public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
860 update(e, a);
861 }
862
863 public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
864 update(e, a);
865 }
866
867 private void update(DocumentEvent ev, Shape a) {
868 int oldCount = lineCount;
869 breakLines(ev.getOffset());
870 if (oldCount != lineCount) {
871 WrappedPlainView.this.preferenceChanged(this, false, true);
|
347 * be reimplemented to alter the breaking behavior.
348 * It will either break at word or character boundaries
349 * depending upon the break argument given at
350 * construction.
351 * @param p0 the starting document location
352 * @param p1 the ending document location to use
353 * @return the break position
354 */
355 @SuppressWarnings("deprecation")
356 protected int calculateBreakPosition(int p0, int p1) {
357 int p;
358 Segment segment = SegmentCache.getSharedSegment();
359 loadText(segment, p0, p1);
360 int currentWidth = getWidth();
361 if (wordWrap) {
362 p = p0 + Utilities.getBreakLocation(segment, metrics,
363 tabBase, tabBase + currentWidth,
364 this, p0);
365 } else {
366 p = p0 + Utilities.getTabbedTextOffset(segment, metrics,
367 (float)tabBase,
368 (float)(tabBase + currentWidth),
369 this, p0, false);
370 }
371 SegmentCache.releaseSharedSegment(segment);
372 return p;
373 }
374
375 /**
376 * Loads all of the children to initialize the view.
377 * This is called by the <code>setParent</code> method.
378 * Subclasses can reimplement this to initialize their
379 * child views in a different manner. The default
380 * implementation creates a child view for each
381 * child element.
382 *
383 * @param f the view factory
384 */
385 protected void loadChildren(ViewFactory f) {
386 Element e = getElement();
387 int n = e.getElementCount();
388 if (n > 0) {
831 p1 = getEndOffset();
832 } else {
833 int[] lineEnds = getLineEnds();
834 p1 = p0 + lineEnds[line];
835 if (line > 0) {
836 p0 += lineEnds[line - 1];
837 }
838 }
839
840 if (x < alloc.x) {
841 // point is to the left of the line
842 return p0;
843 } else if (x > alloc.x + alloc.width) {
844 // point is to the right of the line
845 return p1 - 1;
846 } else {
847 // Determine the offset into the text
848 Segment segment = SegmentCache.getSharedSegment();
849 loadText(segment, p0, p1);
850 int n = Utilities.getTabbedTextOffset(segment, metrics,
851 (float)alloc.x, (float)x,
852 WrappedPlainView.this, p0, true);
853 SegmentCache.releaseSharedSegment(segment);
854 return Math.min(p0 + n, p1 - 1);
855 }
856 }
857 }
858 }
859
860 public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
861 update(e, a);
862 }
863
864 public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
865 update(e, a);
866 }
867
868 private void update(DocumentEvent ev, Shape a) {
869 int oldCount = lineCount;
870 breakLines(ev.getOffset());
871 if (oldCount != lineCount) {
872 WrappedPlainView.this.preferenceChanged(this, false, true);
|