PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/textarea/ScreenLineManager.java

#
Java | 139 lines | 80 code | 18 blank | 41 comment | 12 complexity | ca3009370ae00b302b7500d55ec71f34 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. * ScreenLineManager.java - Manage screen line counts
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2004 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. //{{{ Imports
  24. import org.gjt.sp.jedit.buffer.*;
  25. import org.gjt.sp.jedit.Debug;
  26. import org.gjt.sp.util.Log;
  27. //}}}
  28. /**
  29. * Performs the Mapping between physical lines and screen lines.
  30. *
  31. * @since jEdit 4.3pre1
  32. * @author Slava Pestov
  33. * @version $Id: ScreenLineManager.java 5459 2006-06-20 21:53:46Z kpouer $
  34. */
  35. class ScreenLineManager
  36. {
  37. //{{{ ScreenLineManager constructor
  38. ScreenLineManager(DisplayManager displayManager, JEditBuffer buffer)
  39. {
  40. this.displayManager = displayManager;
  41. this.buffer = buffer;
  42. if(!buffer.isLoading())
  43. reset();
  44. } //}}}
  45. //{{{ isScreenLineCountValid() method
  46. boolean isScreenLineCountValid(int line)
  47. {
  48. return (screenLines[line] & SCREEN_LINES_VALID_MASK) != 0;
  49. } //}}}
  50. //{{{ getScreenLineCount() method
  51. int getScreenLineCount(int line)
  52. {
  53. return screenLines[line] >> SCREEN_LINES_SHIFT;
  54. } //}}}
  55. //{{{ setScreenLineCount() method
  56. void setScreenLineCount(int line, int count)
  57. {
  58. if(count > Short.MAX_VALUE)
  59. {
  60. // limitations...
  61. count = Short.MAX_VALUE;
  62. }
  63. if(Debug.SCREEN_LINES_DEBUG)
  64. Log.log(Log.DEBUG,this,new Exception("setScreenLineCount(" + line + "," + count + ")"));
  65. screenLines[line] = (short)(count << SCREEN_LINES_SHIFT
  66. | SCREEN_LINES_VALID_MASK);
  67. } //}}}
  68. //{{{ invalidateScreenLineCounts() method
  69. void invalidateScreenLineCounts()
  70. {
  71. int lineCount = buffer.getLineCount();
  72. for(int i = 0; i < lineCount; i++)
  73. screenLines[i] &= ~SCREEN_LINES_VALID_MASK;
  74. } //}}}
  75. //{{{ reset() method
  76. void reset()
  77. {
  78. screenLines = new short[buffer.getLineCount()];
  79. for(int i = 0; i < screenLines.length; i++)
  80. screenLines[i] = 0;
  81. } //}}}
  82. //{{{ contentInserted() method
  83. public void contentInserted(int startLine, int numLines)
  84. {
  85. int endLine = startLine + numLines;
  86. screenLines[startLine] &= ~SCREEN_LINES_VALID_MASK;
  87. int lineCount = buffer.getLineCount();
  88. if(numLines > 0)
  89. {
  90. if(screenLines.length <= lineCount)
  91. {
  92. short[] screenLinesN = new short[(lineCount + 1) * 2];
  93. System.arraycopy(screenLines,0,screenLinesN,0,
  94. screenLines.length);
  95. screenLines = screenLinesN;
  96. }
  97. System.arraycopy(screenLines,startLine,screenLines,
  98. endLine,lineCount - endLine);
  99. for(int i = 0; i < numLines; i++)
  100. screenLines[startLine + i] = 0;
  101. }
  102. } //}}}
  103. //{{{ contentRemoved() method
  104. public void contentRemoved(int startLine, int numLines)
  105. {
  106. int endLine = startLine + numLines;
  107. screenLines[startLine] &= ~SCREEN_LINES_VALID_MASK;
  108. if(numLines > 0 && endLine != screenLines.length)
  109. {
  110. System.arraycopy(screenLines,endLine + 1,screenLines,
  111. startLine + 1,screenLines.length - endLine - 1);
  112. }
  113. } //}}}
  114. //{{{ Private members
  115. private static final int SCREEN_LINES_SHIFT = 1;
  116. private static final int SCREEN_LINES_VALID_MASK = 1;
  117. private DisplayManager displayManager;
  118. private JEditBuffer buffer;
  119. private short[] screenLines;
  120. //}}}
  121. }