home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / TextPositionInfo.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  4.9 KB  |  167 lines  |  [TEXT/CWIE]

  1. // TextPositionInfo.java
  2. // By Ned Etcode
  3. // Copyright 1995, 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9. /** Object subclass that contains information about a single character position
  10.   * within the TextView (position, line number, height of the line,
  11.   * etc.).<br><br>
  12.   * @note 1.0 changes
  13.   */
  14. class TextPositionInfo {
  15.     public TextStyleRun _textRun;
  16.     public int          _x, _y, _lineNumber, _lineHeight, _absPosition,
  17.                         _positionInRun, _updateLine;
  18.     public boolean      _redrawCurrentLineOnly, _redrawCurrentParagraphOnly,
  19.                         _nextLine, _endOfLine, _endOfParagraph;
  20.  
  21.  
  22.  
  23. /* constructors */
  24.  
  25.      TextPositionInfo() {
  26.         super();
  27.     }
  28.  
  29.      TextPositionInfo(TextStyleRun theRun, int x, int y, int lineNumber,
  30.                             int lineHeight, int runPosition, int absPosition) {
  31.         this();
  32.  
  33.         init(theRun, x, y, lineNumber, lineHeight, runPosition, absPosition);
  34.     }
  35.  
  36.      TextPositionInfo(TextPositionInfo aPosition) {
  37.         this();
  38.  
  39.         init(aPosition._textRun, aPosition._x, aPosition._y,
  40.              aPosition._lineNumber, aPosition._lineHeight,
  41.              aPosition._positionInRun, aPosition._absPosition);
  42.     }
  43.  
  44.  
  45.     public String toString() {
  46.         return "run is " + _textRun + " x is " + _x + " y is " + _y + " lineNumber is " + _lineNumber +
  47.             "line height is: " + _lineHeight + "positionInRun is " + _positionInRun + "position is:" +
  48.              _absPosition + "endOfLine is " + _endOfLine + "_endOfParagraph is " + _endOfParagraph;
  49.     }
  50.  
  51. /* initializers */
  52.  
  53.  
  54.      void init(TextStyleRun theRun, int x, int y, int lineNumber,
  55.                      int lineHeight, int runPosition, int absPosition) {
  56.  
  57.         _textRun = theRun;
  58.         _x = x;
  59.         _y = y;
  60.         _lineNumber = lineNumber;
  61.         _lineHeight = lineHeight;
  62.         _positionInRun = runPosition;
  63.         _absPosition = absPosition;
  64.  
  65.         _updateLine = _lineNumber;
  66.     }
  67.  
  68.      void init(TextPositionInfo aPosition) {
  69.         init(aPosition._textRun, aPosition._x, aPosition._y,
  70.              aPosition._lineNumber, aPosition._lineHeight,
  71.              aPosition._positionInRun, aPosition._absPosition);
  72.     }
  73.  
  74.     /** ALERT!, it would be better to make sure that the rest of the code is never accessing _x,_y and
  75.      * line number directly so we can perform the following conversion on the fly
  76.       */
  77.      void representCharacterAfterEndOfLine() {
  78.         if( _endOfLine ) {
  79.             TextParagraphFormat f = _textRun.paragraph().currentParagraphFormat();
  80.             _x = f._leftMargin + f._leftIndent;
  81.             if( f.wrapsUnderFirstCharacter() ) {
  82.                 _x = f._leftMargin +
  83.                     (_textRun.paragraph().addWidthOfInitialTabs(
  84.                                                             f._leftMargin+f._leftIndent)
  85.                      - f._leftIndent);
  86.             }
  87.             _y += _lineHeight;
  88.             _lineNumber++;
  89.             _lineHeight = _textRun.paragraph()._lineHeights[_lineNumber];
  90.             _endOfLine = false;
  91.  
  92.         }
  93.     }
  94.  
  95.      void representCharacterBeforeEndOfLine() {
  96.          TextPositionInfo info = _textRun._paragraph._owner.positionInfoForIndex(_absPosition);
  97.          if( info._endOfLine ) {
  98.              _textRun = info._textRun;
  99.              _x = info._x;
  100.              _y = info._y;
  101.              _absPosition = info._absPosition;
  102.              _lineNumber = info._lineNumber;
  103.              _lineHeight = info._lineHeight;
  104.              _positionInRun = info._positionInRun;
  105.              _updateLine = info._updateLine;
  106.              _redrawCurrentLineOnly = info._redrawCurrentLineOnly;
  107.              _redrawCurrentParagraphOnly = info._redrawCurrentParagraphOnly;
  108.              _nextLine = info._nextLine;
  109.              _endOfLine = info._endOfLine;
  110.              _endOfParagraph = info._endOfParagraph;
  111.          }
  112.      }
  113.  
  114.      void setUpdateLine(int lineNumber) {
  115.         _updateLine = lineNumber;
  116.     }
  117.  
  118.      void setRedrawCurrentLineOnly(boolean flag) {
  119.         _redrawCurrentLineOnly = flag;
  120.     }
  121.  
  122.      void setRedrawCurrentParagraphOnly(boolean flag) {
  123.         _redrawCurrentParagraphOnly = flag;
  124.     }
  125.  
  126.      void setX(int anInt) {
  127.         _x = anInt;
  128.     }
  129.  
  130.      void setAbsPosition(int absPosition) {
  131.         _absPosition = absPosition;
  132.     }
  133.  
  134.      void setPositionInRun(int anInt) {
  135.         _positionInRun = anInt;
  136.     }
  137.  
  138.      void moveBy(int deltaX, int deltaY) {
  139.         _x += deltaX;
  140.         _y += deltaY;
  141.     }
  142.  
  143.      int maxY() {
  144.         return _y + _lineHeight;
  145.     }
  146.  
  147.      Rect lineBounds() {
  148.         return _textRun._paragraph.rectForLine(_lineNumber);
  149.     }
  150.  
  151.      Range lineRange() {
  152.         return _textRun._paragraph.rangeForLine(_lineNumber);
  153.     }
  154.      void setNextLine(boolean flag) {
  155.         _nextLine = flag;
  156.     }
  157.  
  158.      void setAtEndOfLine(boolean flag) {
  159.         _endOfLine = flag;
  160.     }
  161.  
  162.      void setAtEndOfParagraph(boolean flag) {
  163.         _endOfParagraph = flag;
  164.     }
  165.  }
  166.  
  167.