PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/textarea/Anchor.java

#
Java | 155 lines | 63 code | 11 blank | 81 comment | 10 complexity | d71510c399543e8a108e1951c64de52a MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * Anchor.java - A base point for physical line <-> screen line conversion
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2005 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.textarea;
  23. import org.gjt.sp.jedit.Debug;
  24. import org.gjt.sp.util.Log;
  25. /**
  26. * A base point for physical line/screen line conversion.
  27. * @author Slava Pestov
  28. * @version $Id: Anchor.java 15570 2009-06-25 00:43:57Z ezust $
  29. */
  30. abstract class Anchor
  31. {
  32. protected final DisplayManager displayManager;
  33. protected final TextArea textArea;
  34. /** The physical line. */
  35. int physicalLine;
  36. /**
  37. * The visible line index. (from the top of the buffer). It can be different from physical line
  38. * when using soft wrap.
  39. */
  40. int scrollLine;
  41. /**
  42. * If this is set to true, the changed() method will be called in
  43. * {@link DisplayManager#notifyScreenLineChanges()}
  44. */
  45. boolean callChanged;
  46. /**
  47. * If this is set to true, the reset() method will be called in
  48. * {@link DisplayManager#notifyScreenLineChanges()}
  49. */
  50. boolean callReset;
  51. //{{{ Anchor constructor
  52. protected Anchor(DisplayManager displayManager,
  53. TextArea textArea)
  54. {
  55. this.displayManager = displayManager;
  56. this.textArea = textArea;
  57. } //}}}
  58. /** This method recalculates the scrollLine from the beginning. */
  59. abstract void reset();
  60. abstract void changed();
  61. //{{{ toString() method
  62. @Override
  63. public String toString()
  64. {
  65. return getClass().getName() + '[' + physicalLine + ','
  66. + scrollLine + ']';
  67. } //}}}
  68. //{{{ contentInserted() method
  69. /**
  70. * Some content is inserted.
  71. *
  72. * @param startLine the start of the insert
  73. * @param numLines the number of insterted lines
  74. */
  75. void contentInserted(int startLine, int numLines)
  76. {
  77. // The Anchor is changed only if the content was inserted before
  78. if(physicalLine >= startLine)
  79. {
  80. if(physicalLine != startLine)
  81. physicalLine += numLines;
  82. callChanged = true;
  83. }
  84. } //}}}
  85. //{{{ preContentRemoved() method
  86. /**
  87. * Method called before a content is removed from a buffer.
  88. *
  89. * @param startLine the first line of the removed content
  90. * @param offset the offset in the start line
  91. * @param numLines the number of removed lines
  92. */
  93. void preContentRemoved(int startLine, int offset, int numLines)
  94. {
  95. if(Debug.SCROLL_DEBUG)
  96. Log.log(Log.DEBUG,this,"preContentRemoved() before:" + this);
  97. // The removed content starts before the Anchor, we need to pull the anchor up
  98. if(physicalLine >= startLine)
  99. {
  100. if(physicalLine == startLine)
  101. callChanged = true;
  102. else
  103. {
  104. int end = Math.min(startLine + numLines, physicalLine);
  105. //Check the lines from the beginning of the removed content to the end (or the physical
  106. //line of the Anchor if it is before the end of the removed content
  107. //int loopStart = startLine + 1;
  108. //{{{ treatment if the beginning of the deleted content is inside a physical line that has several line counts
  109. /*if (displayManager.isLineVisible(startLine))
  110. {
  111. int screenLineCount = displayManager.screenLineMgr.getScreenLineCount(startLine);
  112. if (screenLineCount > 1)
  113. {
  114. int lineStartOffset = textArea.getLineStartOffset(startLine);
  115. int startScreenLine = textArea.getScreenLineOfOffset(lineStartOffset);
  116. int deleteStartScreenLine = textArea.getScreenLineOfOffset(offset);
  117. if (startScreenLine != deleteStartScreenLine)
  118. {
  119. loopStart = startLine + 2;
  120. scrollLine -= screenLineCount - deleteStartScreenLine + startScreenLine;
  121. }
  122. }
  123. }*/
  124. //}}}
  125. for(int i = startLine + 1; i <= end; i++)
  126. {
  127. //XXX
  128. if(displayManager.isLineVisible(i))
  129. {
  130. scrollLine -=
  131. displayManager
  132. .screenLineMgr
  133. .getScreenLineCount(i);
  134. }
  135. }
  136. physicalLine -= end - startLine;
  137. callChanged = true;
  138. }
  139. }
  140. if(Debug.SCROLL_DEBUG)
  141. Log.log(Log.DEBUG,this,"preContentRemoved() after:" + this);
  142. } //}}}
  143. }