1. /*
  2. * @(#)WrappedPlainView.java 1.20 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.text;
  8. import java.util.Vector;
  9. import java.util.Properties;
  10. import java.awt.*;
  11. import javax.swing.event.*;
  12. /**
  13. * View of plain text (text with only one font and color)
  14. * that does line-wrapping. This view expects that its
  15. * associated element has child elements that represent
  16. * the lines it should be wrapping. It is implemented
  17. * as a vertical box that contains logical line views.
  18. * The logical line views are nested classes that render
  19. * the logical line as multiple physical line if the logical
  20. * line is too wide to fit within the allocation. The
  21. * line views draw upon the outer class for its state
  22. * to reduce their memory requirements.
  23. * <p>
  24. * The line views do all of their rendering through the
  25. * <code>drawLine</code> method which in turn does all of
  26. * its rendering through the <code>drawSelectedText</code>
  27. * and <code>drawUnselectedText</code> methods. This
  28. * enables subclasses to easily specialize the rendering
  29. * without concern for the layout aspects.
  30. *
  31. * @author Timothy Prinzing
  32. * @version 1.20 11/29/01
  33. * @see View
  34. */
  35. public class WrappedPlainView extends BoxView implements TabExpander {
  36. /**
  37. * Creates a new WrappedPlainView. Lines will be wrapped
  38. * on character boundries.
  39. *
  40. * @param elem the element underlying the view
  41. */
  42. public WrappedPlainView(Element elem) {
  43. this(elem, false);
  44. }
  45. /**
  46. * Creates a new WrappedPlainView. Lines can be wrapped on
  47. * either character or word boundries depending upon the
  48. * setting of the wordWrap parameter.
  49. *
  50. * @param elem the element underlying the view
  51. * @param wordWrap should lines be wrapped on word boundries?
  52. */
  53. public WrappedPlainView(Element elem, boolean wordWrap) {
  54. super(elem, Y_AXIS);
  55. lineBuffer = new Segment();
  56. this.wordWrap = wordWrap;
  57. }
  58. /**
  59. * Returns the tab size set for the document, defaulting to 8.
  60. *
  61. * @return the tab size
  62. */
  63. protected int getTabSize() {
  64. Integer i = (Integer) getDocument().getProperty(PlainDocument.tabSizeAttribute);
  65. int size = (i != null) ? i.intValue() : 8;
  66. return size;
  67. }
  68. /**
  69. * Renders a line of text, suppressing whitespace at the end
  70. * and expanding any tabs. This is implemented to make calls
  71. * to the methods <code>drawUnselectedText</code> and
  72. * <code>drawSelectedText</code> so that the way selected and
  73. * unselected text are rendered can be customized.
  74. *
  75. * @param p0 the starting document location to use >= 0
  76. * @param p1 the ending document location to use >= p1
  77. * @param g the graphics context
  78. * @param x the starting X position >= 0
  79. * @param y the starting Y position >= 0
  80. * @see #drawUnselectedText
  81. * @see #drawSelectedText
  82. */
  83. protected void drawLine(int p0, int p1, Graphics g, int x, int y) {
  84. Element lineMap = getElement();
  85. Element line = lineMap.getElement(lineMap.getElementIndex(p0));
  86. Element elem;
  87. try {
  88. if (line.isLeaf()) {
  89. drawText(line, p0, p1, g, x, y);
  90. } else {
  91. // this line contains the composed text.
  92. int idx = line.getElementIndex(p0);
  93. int lastIdx = line.getElementIndex(p1);
  94. for(; idx <= lastIdx; idx++) {
  95. elem = line.getElement(idx);
  96. int start = Math.max(elem.getStartOffset(), p0);
  97. int end = Math.min(elem.getEndOffset(), p1);
  98. x = drawText(elem, start, end, g, x, y);
  99. }
  100. }
  101. } catch (BadLocationException e) {
  102. throw new StateInvariantError("Can't render: " + p0 + "," + p1);
  103. }
  104. }
  105. private int drawText(Element elem, int p0, int p1, Graphics g, int x, int y) throws BadLocationException {
  106. p1 = Math.min(getDocument().getLength(), p1);
  107. AttributeSet attr = elem.getAttributes();
  108. if (Utilities.isComposedTextAttributeDefined(attr)) {
  109. g.setColor(unselected);
  110. x = Utilities.drawComposedText(attr, g, x, y,
  111. p0-elem.getStartOffset(),
  112. p1-elem.getStartOffset());
  113. } else {
  114. if (sel0 == sel1) {
  115. // no selection
  116. x = drawUnselectedText(g, x, y, p0, p1);
  117. } else if ((p0 >= sel0 && p0 <= sel1) && (p1 >= sel0 && p1 <= sel1)) {
  118. x = drawSelectedText(g, x, y, p0, p1);
  119. } else if (sel0 >= p0 && sel0 <= p1) {
  120. if (sel1 >= p0 && sel1 <= p1) {
  121. x = drawUnselectedText(g, x, y, p0, sel0);
  122. x = drawSelectedText(g, x, y, sel0, sel1);
  123. x = drawUnselectedText(g, x, y, sel1, p1);
  124. } else {
  125. x = drawUnselectedText(g, x, y, p0, sel0);
  126. x = drawSelectedText(g, x, y, sel0, p1);
  127. }
  128. } else if (sel1 >= p0 && sel1 <= p1) {
  129. x = drawSelectedText(g, x, y, p0, sel1);
  130. x = drawUnselectedText(g, x, y, sel1, p1);
  131. } else {
  132. x = drawUnselectedText(g, x, y, p0, p1);
  133. }
  134. }
  135. return x;
  136. }
  137. /**
  138. * Renders the given range in the model as normal unselected
  139. * text.
  140. *
  141. * @param g the graphics context
  142. * @param x the starting X coordinate >= 0
  143. * @param y the starting Y coordinate >= 0
  144. * @param p0 the beginning position in the model >= 0
  145. * @param p1 the ending position in the model >= p0
  146. * @returns the X location of the end of the range >= 0
  147. * @exception BadLocationException if the range is invalid
  148. */
  149. protected int drawUnselectedText(Graphics g, int x, int y,
  150. int p0, int p1) throws BadLocationException {
  151. g.setColor(unselected);
  152. Document doc = getDocument();
  153. doc.getText(p0, p1 - p0, lineBuffer);
  154. return Utilities.drawTabbedText(lineBuffer, x, y, g, this, p0);
  155. }
  156. /**
  157. * Renders the given range in the model as selected text. This
  158. * is implemented to render the text in the color specified in
  159. * the hosting component. It assumes the highlighter will render
  160. * the selected background.
  161. *
  162. * @param g the graphics context
  163. * @param x the starting X coordinate >= 0
  164. * @param y the starting Y coordinate >= 0
  165. * @param p0 the beginning position in the model >= 0
  166. * @param p1 the ending position in the model >= p0
  167. * @returns the location of the end of the range.
  168. * @exception BadLocationException if the range is invalid
  169. */
  170. protected int drawSelectedText(Graphics g, int x,
  171. int y, int p0, int p1) throws BadLocationException {
  172. g.setColor(selected);
  173. Document doc = getDocument();
  174. doc.getText(p0, p1 - p0, lineBuffer);
  175. return Utilities.drawTabbedText(lineBuffer, x, y, g, this, p0);
  176. }
  177. /**
  178. * Gives access to a buffer that can be used to fetch
  179. * text from the associated document.
  180. *
  181. * @returns the buffer
  182. */
  183. protected final Segment getLineBuffer() {
  184. return lineBuffer;
  185. }
  186. /**
  187. * This is called by the nested wrapped line
  188. * views to determine the break location. This can
  189. * be reimplemented to alter the breaking behavior.
  190. * It will either break at word or character boundries
  191. * depending upon the break argument given at
  192. * construction.
  193. */
  194. protected int calculateBreakPosition(int p0, int p1) {
  195. int p;
  196. loadText(p0, p1);
  197. if (wordWrap) {
  198. p = p0 + Utilities.getBreakLocation(lineBuffer, metrics,
  199. tabBase, tabBase + getWidth(),
  200. this, p0);
  201. } else {
  202. p = p0 + Utilities.getTabbedTextOffset(lineBuffer, metrics,
  203. tabBase, tabBase + getWidth(),
  204. this, p0);
  205. }
  206. return p;
  207. }
  208. /**
  209. * Loads all of the children to initialize the view.
  210. * This is called by the <code>setParent</code> method.
  211. * Subclasses can reimplement this to initialize their
  212. * child views in a different manner. The default
  213. * implementation creates a child view for each
  214. * child element.
  215. *
  216. * @param f the view factory
  217. */
  218. protected void loadChildren(ViewFactory f) {
  219. Element e = getElement();
  220. int n = e.getElementCount();
  221. if (n > 0) {
  222. View[] added = new View[n];
  223. for (int i = 0; i < n; i++) {
  224. added[i] = new WrappedLine(e.getElement(i));
  225. }
  226. replace(0, 0, added);
  227. }
  228. }
  229. /**
  230. * Update the child views in response to a
  231. * document event.
  232. */
  233. void updateChildren(DocumentEvent e, Shape a) {
  234. Element elem = getElement();
  235. DocumentEvent.ElementChange ec = e.getChange(elem);
  236. if (ec != null) {
  237. // the structure of this element changed.
  238. Element[] removedElems = ec.getChildrenRemoved();
  239. Element[] addedElems = ec.getChildrenAdded();
  240. View[] added = new View[addedElems.length];
  241. for (int i = 0; i < addedElems.length; i++) {
  242. added[i] = new WrappedLine(addedElems[i]);
  243. }
  244. replace(ec.getIndex(), removedElems.length, added);
  245. // should damge a little more intelligently.
  246. if (a != null) {
  247. preferenceChanged(null, true, true);
  248. getContainer().repaint();
  249. }
  250. }
  251. // update font metrics which may be used by the child views
  252. updateMetrics();
  253. }
  254. /**
  255. * Load the text buffer with the given range
  256. * of text. This is used by the fragments
  257. * broken off of this view as well as this
  258. * view itself.
  259. */
  260. final void loadText(int p0, int p1) {
  261. try {
  262. Document doc = getDocument();
  263. doc.getText(p0, p1 - p0, lineBuffer);
  264. } catch (BadLocationException bl) {
  265. throw new StateInvariantError("Can't get line text");
  266. }
  267. }
  268. final void updateMetrics() {
  269. Component host = getContainer();
  270. Font f = host.getFont();
  271. metrics = host.getFontMetrics(f);
  272. tabSize = getTabSize() * metrics.charWidth('m');
  273. }
  274. // --- TabExpander methods ------------------------------------------
  275. /**
  276. * Returns the next tab stop position after a given reference position.
  277. * This implementation does not support things like centering so it
  278. * ignores the tabOffset argument.
  279. *
  280. * @param x the current position >= 0
  281. * @param tabOffset the position within the text stream
  282. * that the tab occurred at >= 0.
  283. * @return the tab stop, measured in points >= 0
  284. */
  285. public float nextTabStop(float x, int tabOffset) {
  286. int ntabs = ((int) x - tabBase) / tabSize;
  287. return tabBase + ((ntabs + 1) * tabSize);
  288. }
  289. // --- View methods -------------------------------------
  290. /**
  291. * Renders using the given rendering surface and area
  292. * on that surface. This is implemented to stash the
  293. * selection positions, selection colors, and font
  294. * metrics for the nested lines to use.
  295. *
  296. * @param g the rendering surface to use
  297. * @param a the allocated region to render into
  298. *
  299. * @see View#paint
  300. */
  301. public void paint(Graphics g, Shape a) {
  302. Rectangle alloc = (Rectangle) a;
  303. tabBase = alloc.x;
  304. JTextComponent host = (JTextComponent) getContainer();
  305. sel0 = host.getSelectionStart();
  306. sel1 = host.getSelectionEnd();
  307. unselected = (host.isEnabled()) ?
  308. host.getForeground() : host.getDisabledTextColor();
  309. Caret c = host.getCaret();
  310. selected = c.isSelectionVisible() ? host.getSelectedTextColor() : unselected;
  311. g.setFont(host.getFont());
  312. // superclass paints the children
  313. super.paint(g, a);
  314. }
  315. /**
  316. * Sets the size of the view. If the size has changed, layout
  317. * is redone. The size is the full size of the view including
  318. * the inset areas.
  319. *
  320. * @param width the width >= 0
  321. * @param height the height >= 0
  322. */
  323. public void setSize(float width, float height) {
  324. updateMetrics();
  325. if ((int) width != getWidth()) {
  326. // invalidate the view itself since the childrens
  327. // desired widths will be based upon this views width.
  328. preferenceChanged(null, true, true);
  329. widthChanging = true;
  330. }
  331. super.setSize(width, height);
  332. widthChanging = false;
  333. }
  334. /**
  335. * Determines the preferred span for this view along an
  336. * axis. This is implemented to provide the superclass
  337. * behavior after first making sure that the current font
  338. * metrics are cached (for the nested lines which use
  339. * the metrics to determine the height of the potentially
  340. * wrapped lines).
  341. *
  342. * @param axis may be either View.X_AXIS or View.Y_AXIS
  343. * @returns the span the view would like to be rendered into.
  344. * Typically the view is told to render into the span
  345. * that is returned, although there is no guarantee.
  346. * The parent may choose to resize or break the view.
  347. * @see View#getPreferredSpan
  348. */
  349. public float getPreferredSpan(int axis) {
  350. updateMetrics();
  351. return super.getPreferredSpan(axis);
  352. }
  353. /**
  354. * Determines the minimum span for this view along an
  355. * axis. This is implemented to provide the superclass
  356. * behavior after first making sure that the current font
  357. * metrics are cached (for the nested lines which use
  358. * the metrics to determine the height of the potentially
  359. * wrapped lines).
  360. *
  361. * @param axis may be either View.X_AXIS or View.Y_AXIS
  362. * @returns the span the view would like to be rendered into.
  363. * Typically the view is told to render into the span
  364. * that is returned, although there is no guarantee.
  365. * The parent may choose to resize or break the view.
  366. * @see View#getMinimumSpan
  367. */
  368. public float getMinimumSpan(int axis) {
  369. updateMetrics();
  370. return super.getMinimumSpan(axis);
  371. }
  372. /**
  373. * Determines the maximum span for this view along an
  374. * axis. This is implemented to provide the superclass
  375. * behavior after first making sure that the current font
  376. * metrics are cached (for the nested lines which use
  377. * the metrics to determine the height of the potentially
  378. * wrapped lines).
  379. *
  380. * @param axis may be either View.X_AXIS or View.Y_AXIS
  381. * @returns the span the view would like to be rendered into.
  382. * Typically the view is told to render into the span
  383. * that is returned, although there is no guarantee.
  384. * The parent may choose to resize or break the view.
  385. * @see View#getMaximumSpan
  386. */
  387. public float getMaximumSpan(int axis) {
  388. updateMetrics();
  389. return super.getMaximumSpan(axis);
  390. }
  391. /**
  392. * Gives notification that something was inserted into the
  393. * document in a location that this view is responsible for.
  394. * This is implemented to simply update the children.
  395. *
  396. * @param e the change information from the associated document
  397. * @param a the current allocation of the view
  398. * @param f the factory to use to rebuild if the view has children
  399. * @see View#insertUpdate
  400. */
  401. public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
  402. updateChildren(e, a);
  403. Rectangle alloc = ((a != null) && isAllocationValid()) ?
  404. getInsideAllocation(a) : null;
  405. int pos = e.getOffset();
  406. View v = getViewAtPosition(pos, alloc);
  407. if (v != null) {
  408. v.insertUpdate(e, alloc, f);
  409. }
  410. }
  411. /**
  412. * Gives notification that something was removed from the
  413. * document in a location that this view is responsible for.
  414. * This is implemented to simply update the children.
  415. *
  416. * @param e the change information from the associated document
  417. * @param a the current allocation of the view
  418. * @param f the factory to use to rebuild if the view has children
  419. * @see View#removeUpdate
  420. */
  421. public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
  422. updateChildren(e, a);
  423. Rectangle alloc = ((a != null) && isAllocationValid()) ?
  424. getInsideAllocation(a) : null;
  425. int pos = e.getOffset();
  426. View v = getViewAtPosition(pos, alloc);
  427. if (v != null) {
  428. v.removeUpdate(e, alloc, f);
  429. }
  430. }
  431. /**
  432. * Gives notification from the document that attributes were changed
  433. * in a location that this view is responsible for.
  434. *
  435. * @param e the change information from the associated document
  436. * @param a the current allocation of the view
  437. * @param f the factory to use to rebuild if the view has children
  438. * @see View#changedUpdate
  439. */
  440. public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
  441. updateChildren(e, a);
  442. }
  443. // --- variables -------------------------------------------
  444. FontMetrics metrics;
  445. Segment lineBuffer;
  446. boolean widthChanging;
  447. int tabBase;
  448. int tabSize;
  449. boolean wordWrap;
  450. int sel0;
  451. int sel1;
  452. Color unselected;
  453. Color selected;
  454. /**
  455. * Simple view of a line that wraps if it doesn't
  456. * fit withing the horizontal space allocated.
  457. * This class tries to be lightweight by carrying little
  458. * state of it's own and sharing the state of the outer class
  459. * with it's sibblings.
  460. */
  461. class WrappedLine extends View {
  462. WrappedLine(Element elem) {
  463. super(elem);
  464. }
  465. /**
  466. * Calculate the number of lines that will be rendered
  467. * by logical line when it is wrapped.
  468. */
  469. final int calculateLineCount() {
  470. int nlines = 0;
  471. int p1 = getEndOffset();
  472. for (int p0 = getStartOffset(); p0 < p1; ) {
  473. nlines += 1;
  474. int p = calculateBreakPosition(p0, p1);
  475. p0 = (p == p0) ? p1 : p;
  476. }
  477. return nlines;
  478. }
  479. /**
  480. * Determines the preferred span for this view along an
  481. * axis.
  482. *
  483. * @param axis may be either X_AXIS or Y_AXIS
  484. * @returns the span the view would like to be rendered into.
  485. * Typically the view is told to render into the span
  486. * that is returned, although there is no guarantee.
  487. * The parent may choose to resize or break the view.
  488. * @see View#getPreferredSpan
  489. */
  490. public float getPreferredSpan(int axis) {
  491. switch (axis) {
  492. case View.X_AXIS:
  493. return getWidth();
  494. case View.Y_AXIS:
  495. if (nlines == 0 || widthChanging) {
  496. nlines = calculateLineCount();
  497. }
  498. int h = nlines * metrics.getHeight();
  499. return h;
  500. default:
  501. throw new IllegalArgumentException("Invalid axis: " + axis);
  502. }
  503. }
  504. /**
  505. * Renders using the given rendering surface and area on that
  506. * surface. The view may need to do layout and create child
  507. * views to enable itself to render into the given allocation.
  508. *
  509. * @param g the rendering surface to use
  510. * @param a the allocated region to render into
  511. * @see View#paint
  512. */
  513. public void paint(Graphics g, Shape a) {
  514. Rectangle alloc = (Rectangle) a;
  515. int y = alloc.y + metrics.getAscent();
  516. int x = alloc.x;
  517. JTextComponent host = (JTextComponent)getContainer();
  518. Highlighter h = host.getHighlighter();
  519. LayeredHighlighter dh = (h instanceof LayeredHighlighter) ?
  520. (LayeredHighlighter)h : null;
  521. int p1 = getEndOffset();
  522. for (int p0 = getStartOffset(); p0 < p1; ) {
  523. int p = calculateBreakPosition(p0, p1);
  524. if (dh != null) {
  525. if (p == p1) {
  526. dh.paintLayeredHighlights(g, p0, p - 1, a, host, this);
  527. }
  528. else {
  529. dh.paintLayeredHighlights(g, p0, p, a, host, this);
  530. }
  531. }
  532. drawLine(p0, p, g, x, y);
  533. p0 = (p == p0) ? p1 : p;
  534. y += metrics.getHeight();
  535. }
  536. }
  537. /**
  538. * Provides a mapping from the document model coordinate space
  539. * to the coordinate space of the view mapped to it.
  540. *
  541. * @param pos the position to convert
  542. * @param a the allocated region to render into
  543. * @return the bounding box of the given position is returned
  544. * @exception BadLocationException if the given position does not represent a
  545. * valid location in the associated document
  546. * @see View#modelToView
  547. */
  548. public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
  549. Rectangle alloc = a.getBounds();
  550. alloc.height = metrics.getHeight();
  551. alloc.width = 1;
  552. int p1 = getEndOffset();
  553. int p0 = getStartOffset();
  554. int testP = (b == Position.Bias.Forward) ? pos :
  555. Math.max(p0, pos - 1);
  556. while (p0 < p1) {
  557. int p = calculateBreakPosition(p0, p1);
  558. if ((pos >= p0) && (testP < p)) {
  559. // it's in this line
  560. loadText(p0, pos);
  561. alloc.x += Utilities.getTabbedTextWidth(lineBuffer, metrics,
  562. alloc.x,
  563. WrappedPlainView.this, p0);
  564. return alloc;
  565. }
  566. if (p == p1 && pos == p1) {
  567. // Wants end.
  568. if (pos > p0) {
  569. loadText(p0, pos);
  570. alloc.x += Utilities.getTabbedTextWidth(lineBuffer,
  571. metrics, alloc.x,
  572. WrappedPlainView.this, p0);
  573. }
  574. return alloc;
  575. }
  576. p0 = (p == p0) ? p1 : p;
  577. alloc.y += alloc.height;
  578. }
  579. throw new BadLocationException(null, pos);
  580. }
  581. /**
  582. * Provides a mapping from the view coordinate space to the logical
  583. * coordinate space of the model.
  584. *
  585. * @param x the X coordinate
  586. * @param y the Y coordinate
  587. * @param a the allocated region to render into
  588. * @return the location within the model that best represents the
  589. * given point in the view
  590. * @see View#viewToModel
  591. */
  592. public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
  593. // PENDING(prinz) implement bias properly
  594. bias[0] = Position.Bias.Forward;
  595. Rectangle alloc = (Rectangle) a;
  596. Document doc = getDocument();
  597. int x = (int) fx;
  598. int y = (int) fy;
  599. if (y < alloc.y) {
  600. // above the area covered by this icon, so the the position
  601. // is assumed to be the start of the coverage for this view.
  602. return getStartOffset();
  603. } else if (y > alloc.y + alloc.height) {
  604. // below the area covered by this icon, so the the position
  605. // is assumed to be the end of the coverage for this view.
  606. return getEndOffset() - 1;
  607. } else {
  608. // positioned within the coverage of this view vertically,
  609. // so we figure out which line the point corresponds to.
  610. // if the line is greater than the number of lines contained, then
  611. // simply use the last line as it represents the last possible place
  612. // we can position to.
  613. alloc.height = metrics.getHeight();
  614. int p1 = getEndOffset();
  615. for (int p0 = getStartOffset(); p0 < p1; ) {
  616. int p = calculateBreakPosition(p0, p1);
  617. if ((y >= alloc.y) && (y < (alloc.y + alloc.height))) {
  618. // it's in this line
  619. if (x < alloc.x) {
  620. // point is to the left of the line
  621. return p0;
  622. } else if (x > alloc.x + alloc.width) {
  623. // point is to the right of the line
  624. return p;
  625. } else {
  626. // Determine the offset into the text
  627. int n = Utilities.getTabbedTextOffset(lineBuffer, metrics,
  628. alloc.x, x,
  629. WrappedPlainView.this, p0);
  630. return Math.min(p0 + n, p1 - 1);
  631. }
  632. }
  633. p0 = (p == p0) ? p1 : p;
  634. alloc.y += alloc.height;
  635. }
  636. return getEndOffset() - 1;
  637. }
  638. }
  639. public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
  640. int n = calculateLineCount();
  641. if (this.nlines != n) {
  642. this.nlines = n;
  643. WrappedPlainView.this.preferenceChanged(this, false, true);
  644. // have to repaint any views after the receiver.
  645. getContainer().repaint();
  646. }
  647. else if (a != null) {
  648. Component c = getContainer();
  649. Rectangle alloc = (Rectangle) a;
  650. c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
  651. }
  652. }
  653. public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
  654. int n = calculateLineCount();
  655. if (this.nlines != n) {
  656. // have to repaint any views after the receiver.
  657. this.nlines = n;
  658. WrappedPlainView.this.preferenceChanged(this, false, true);
  659. getContainer().repaint();
  660. }
  661. else if (a != null) {
  662. Component c = getContainer();
  663. Rectangle alloc = (Rectangle) a;
  664. c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
  665. }
  666. }
  667. // --- variables ---------------------------------------
  668. int nlines;
  669. }
  670. }