PageRenderTime 33ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/textarea/FoldVisibilityManager.java

#
Java | 920 lines | 610 code | 116 blank | 194 comment | 173 complexity | 6825736fc8b9811023beb24a511b1698 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. * FoldVisibilityManager.java - Controls fold visiblity
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2001, 2002 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 java.awt.Toolkit;
  25. import org.gjt.sp.jedit.buffer.OffsetManager;
  26. import org.gjt.sp.jedit.*;
  27. //}}}
  28. /**
  29. * Manages fold visibility.
  30. *
  31. * This class defines methods for translating between physical and virtual
  32. * line numbers, for determining which lines are visible and which aren't,
  33. * and for expanding and collapsing folds.<p>
  34. *
  35. * Note that a "physical" line number is a line index, numbered from the
  36. * start of the buffer. A "virtual" line number is a visible line index;
  37. * lines after a collapsed fold have a virtual line number that is less
  38. * than their physical line number, for example.<p>
  39. *
  40. * You can use the <code>physicalToVirtual()</code> and
  41. * <code>virtualToPhysical()</code> methods to convert one type of line
  42. * number to another.
  43. *
  44. * @author Slava Pestov
  45. * @version $Id: FoldVisibilityManager.java 4093 2002-03-17 03:05:24Z spestov $
  46. * @since jEdit 4.0pre1
  47. */
  48. public class FoldVisibilityManager
  49. {
  50. //{{{ FoldVisibilityManager constructor
  51. public FoldVisibilityManager(Buffer buffer, OffsetManager offsetMgr,
  52. JEditTextArea textArea)
  53. {
  54. this.buffer = buffer;
  55. this.offsetMgr = offsetMgr;
  56. this.textArea = textArea;
  57. } //}}}
  58. //{{{ isNarrowed() method
  59. /**
  60. * Returns if the buffer has been narrowed.
  61. * @since jEdit 4.0pre2
  62. */
  63. public boolean isNarrowed()
  64. {
  65. return narrowed;
  66. } //}}}
  67. //{{{ getVirtualLineCount() method
  68. /**
  69. * Returns the number of virtual lines in the buffer.
  70. * @since jEdit 4.0pre1
  71. */
  72. public int getVirtualLineCount()
  73. {
  74. return offsetMgr.getVirtualLineCount(index);
  75. } //}}}
  76. //{{{ isLineVisible() method
  77. /**
  78. * Returns if the specified line is visible.
  79. * @param line A physical line index
  80. * @since jEdit 4.0pre1
  81. */
  82. public final boolean isLineVisible(int line)
  83. {
  84. if(line < 0 || line >= offsetMgr.getLineCount())
  85. throw new ArrayIndexOutOfBoundsException(line);
  86. try
  87. {
  88. buffer.readLock();
  89. return offsetMgr.isLineVisible(line,index);
  90. }
  91. finally
  92. {
  93. buffer.readUnlock();
  94. }
  95. } //}}}
  96. //{{{ getFirstVisibleLine() method
  97. /**
  98. * Returns the physical line number of the first visible line.
  99. * @since jEdit 4.0pre3
  100. */
  101. public int getFirstVisibleLine()
  102. {
  103. try
  104. {
  105. buffer.readLock();
  106. for(int i = 0; i < buffer.getLineCount(); i++)
  107. {
  108. if(offsetMgr.isLineVisible(i,index))
  109. return i;
  110. }
  111. }
  112. finally
  113. {
  114. buffer.readUnlock();
  115. }
  116. // can't happen?
  117. return -1;
  118. } //}}}
  119. //{{{ getLastVisibleLine() method
  120. /**
  121. * Returns the physical line number of the last visible line.
  122. * @since jEdit 4.0pre3
  123. */
  124. public int getLastVisibleLine()
  125. {
  126. try
  127. {
  128. buffer.readLock();
  129. for(int i = buffer.getLineCount() - 1; i >= 0; i--)
  130. {
  131. if(offsetMgr.isLineVisible(i,index))
  132. return i;
  133. }
  134. }
  135. finally
  136. {
  137. buffer.readUnlock();
  138. }
  139. // can't happen?
  140. return -1;
  141. } //}}}
  142. //{{{ getNextVisibleLine() method
  143. /**
  144. * Returns the next visible line after the specified line index.
  145. * @param line A physical line index
  146. * @since jEdit 4.0pre1
  147. */
  148. public int getNextVisibleLine(int line)
  149. {
  150. if(line < 0 || line >= offsetMgr.getLineCount())
  151. throw new ArrayIndexOutOfBoundsException(line);
  152. try
  153. {
  154. buffer.readLock();
  155. if(line == buffer.getLineCount() - 1)
  156. return -1;
  157. for(int i = line + 1; i < buffer.getLineCount(); i++)
  158. {
  159. if(offsetMgr.isLineVisible(i,index))
  160. return i;
  161. }
  162. return -1;
  163. }
  164. finally
  165. {
  166. buffer.readUnlock();
  167. }
  168. } //}}}
  169. //{{{ getPrevVisibleLine() method
  170. /**
  171. * Returns the previous visible line before the specified line index.
  172. * @param line A physical line index
  173. * @since jEdit 4.0pre1
  174. */
  175. public int getPrevVisibleLine(int line)
  176. {
  177. if(line < 0 || line >= offsetMgr.getLineCount())
  178. throw new ArrayIndexOutOfBoundsException(line);
  179. try
  180. {
  181. buffer.readLock();
  182. if(line == 0)
  183. return -1;
  184. for(int i = line - 1; i >= 0; i--)
  185. {
  186. if(offsetMgr.isLineVisible(i,index))
  187. return i;
  188. }
  189. return -1;
  190. }
  191. finally
  192. {
  193. buffer.readUnlock();
  194. }
  195. } //}}}
  196. //{{{ physicalToVirtual() method
  197. /**
  198. * Converts a physical line number to a virtual line number.
  199. * @param line A physical line index
  200. * @since jEdit 4.0pre1
  201. */
  202. public int physicalToVirtual(int line)
  203. {
  204. try
  205. {
  206. buffer.readLock();
  207. if(line < 0)
  208. throw new ArrayIndexOutOfBoundsException(line + " < 0");
  209. else if(line >= offsetMgr.getLineCount())
  210. {
  211. throw new ArrayIndexOutOfBoundsException(line + " > "
  212. + buffer.getLineCount());
  213. }
  214. // optimization
  215. if(getVirtualLineCount() == buffer.getLineCount())
  216. return line;
  217. while(!offsetMgr.isLineVisible(line,index) && line > 0)
  218. line--;
  219. if(line == 0 && !offsetMgr.isLineVisible(line,index))
  220. {
  221. // inside the top narrow.
  222. return 0;
  223. }
  224. if(lastPhysical == line)
  225. {
  226. if(lastVirtual < 0 || lastVirtual >= offsetMgr.getVirtualLineCount(index))
  227. {
  228. throw new ArrayIndexOutOfBoundsException(
  229. "cached: " + lastVirtual);
  230. }
  231. }
  232. else if(line > lastPhysical && lastPhysical != -1)
  233. {
  234. for(;;)
  235. {
  236. if(lastPhysical == line)
  237. break;
  238. if(offsetMgr.isLineVisible(lastPhysical,index))
  239. lastVirtual++;
  240. if(lastPhysical == buffer.getLineCount() - 1)
  241. break;
  242. else
  243. lastPhysical++;
  244. }
  245. if(lastVirtual < 0 || lastVirtual >= offsetMgr.getVirtualLineCount(index))
  246. {
  247. throw new ArrayIndexOutOfBoundsException(
  248. "fwd scan: " + lastVirtual);
  249. }
  250. }
  251. else if(line < lastPhysical && lastPhysical - line > line)
  252. {
  253. for(;;)
  254. {
  255. if(lastPhysical == line)
  256. break;
  257. if(offsetMgr.isLineVisible(lastPhysical,index))
  258. lastVirtual--;
  259. if(lastPhysical == 0)
  260. break;
  261. else
  262. lastPhysical--;
  263. }
  264. if(lastVirtual < 0 || lastVirtual >= offsetMgr.getVirtualLineCount(index))
  265. {
  266. throw new ArrayIndexOutOfBoundsException(
  267. "back scan: " + lastVirtual);
  268. }
  269. }
  270. else
  271. {
  272. lastPhysical = 0;
  273. // find first visible line
  274. while(!offsetMgr.isLineVisible(lastPhysical,index))
  275. lastPhysical++;
  276. lastVirtual = 0;
  277. for(;;)
  278. {
  279. if(lastPhysical == line)
  280. break;
  281. if(offsetMgr.isLineVisible(lastPhysical,index))
  282. lastVirtual++;
  283. if(lastPhysical == buffer.getLineCount() - 1)
  284. break;
  285. else
  286. lastPhysical++;
  287. }
  288. if(lastVirtual < 0 || lastVirtual >= offsetMgr.getVirtualLineCount(index))
  289. {
  290. throw new ArrayIndexOutOfBoundsException(
  291. "zero scan: " + lastVirtual);
  292. }
  293. }
  294. return lastVirtual;
  295. }
  296. finally
  297. {
  298. buffer.readUnlock();
  299. }
  300. } //}}}
  301. //{{{ virtualToPhysical() method
  302. /**
  303. * Converts a virtual line number to a physical line number.
  304. * @param line A virtual line index
  305. * @since jEdit 4.0pre1
  306. */
  307. public int virtualToPhysical(int line)
  308. {
  309. try
  310. {
  311. buffer.readLock();
  312. if(line < 0)
  313. throw new ArrayIndexOutOfBoundsException(line + " < 0");
  314. else if(line >= offsetMgr.getVirtualLineCount(index))
  315. {
  316. throw new ArrayIndexOutOfBoundsException(line + " > "
  317. + offsetMgr.getVirtualLineCount(index));
  318. }
  319. // optimization
  320. if(getVirtualLineCount() == buffer.getLineCount())
  321. return line;
  322. if(lastVirtual == line)
  323. {
  324. if(lastPhysical < 0 || lastPhysical >= buffer.getLineCount())
  325. {
  326. throw new ArrayIndexOutOfBoundsException(
  327. "cached: " + lastPhysical);
  328. }
  329. }
  330. else if(line > lastVirtual && lastVirtual != -1)
  331. {
  332. for(;;)
  333. {
  334. if(offsetMgr.isLineVisible(lastPhysical,index))
  335. {
  336. if(lastVirtual == line)
  337. break;
  338. else
  339. lastVirtual++;
  340. }
  341. if(lastPhysical == buffer.getLineCount() - 1)
  342. break;
  343. else
  344. lastPhysical++;
  345. }
  346. if(lastPhysical < 0 || lastPhysical >= buffer.getLineCount())
  347. {
  348. throw new ArrayIndexOutOfBoundsException(
  349. "fwd scan: " + lastPhysical);
  350. }
  351. }
  352. else if(line < lastVirtual && lastVirtual - line > line)
  353. {
  354. for(;;)
  355. {
  356. if(offsetMgr.isLineVisible(lastPhysical,index))
  357. {
  358. if(lastVirtual == line)
  359. break;
  360. else
  361. lastVirtual--;
  362. }
  363. if(lastPhysical == 0)
  364. break;
  365. else
  366. lastPhysical--;
  367. }
  368. if(lastPhysical < 0 || lastPhysical >= buffer.getLineCount())
  369. {
  370. throw new ArrayIndexOutOfBoundsException(
  371. "back scan: " + lastPhysical);
  372. }
  373. }
  374. else
  375. {
  376. lastPhysical = 0;
  377. // find first visible line
  378. while(!offsetMgr.isLineVisible(lastPhysical,index))
  379. lastPhysical++;
  380. lastVirtual = 0;
  381. for(;;)
  382. {
  383. if(offsetMgr.isLineVisible(lastPhysical,index))
  384. {
  385. if(lastVirtual == line)
  386. break;
  387. else
  388. lastVirtual++;
  389. }
  390. if(lastPhysical == buffer.getLineCount() - 1)
  391. break;
  392. else
  393. lastPhysical++;
  394. }
  395. if(lastPhysical < 0 || lastPhysical >= buffer.getLineCount())
  396. {
  397. throw new ArrayIndexOutOfBoundsException(
  398. "zero scan: " + lastPhysical);
  399. }
  400. }
  401. return lastPhysical;
  402. }
  403. finally
  404. {
  405. buffer.readUnlock();
  406. }
  407. } //}}}
  408. //{{{ collapseFold() method
  409. /**
  410. * Collapses the fold at the specified physical line index.
  411. * @param line A physical line index
  412. * @since jEdit 4.0pre1
  413. */
  414. public void collapseFold(int line)
  415. {
  416. int lineCount = buffer.getLineCount();
  417. int start = 0;
  418. int end = lineCount - 1;
  419. try
  420. {
  421. buffer.writeLock();
  422. // if the caret is on a collapsed fold, collapse the
  423. // parent fold
  424. if(line != 0
  425. && line != buffer.getLineCount() - 1
  426. && buffer.isFoldStart(line)
  427. && !offsetMgr.isLineVisible(line + 1,index))
  428. {
  429. line--;
  430. }
  431. int initialFoldLevel = buffer.getFoldLevel(line);
  432. //{{{ Find fold start and end...
  433. if(line != lineCount - 1
  434. && buffer.getFoldLevel(line + 1) > initialFoldLevel)
  435. {
  436. // this line is the start of a fold
  437. start = line + 1;
  438. for(int i = line + 1; i < lineCount; i++)
  439. {
  440. if(buffer.getFoldLevel(i) <= initialFoldLevel)
  441. {
  442. end = i - 1;
  443. break;
  444. }
  445. }
  446. }
  447. else
  448. {
  449. boolean ok = false;
  450. // scan backwards looking for the start
  451. for(int i = line - 1; i >= 0; i--)
  452. {
  453. if(buffer.getFoldLevel(i) < initialFoldLevel)
  454. {
  455. start = i + 1;
  456. ok = true;
  457. break;
  458. }
  459. }
  460. if(!ok)
  461. {
  462. // no folds in buffer
  463. return;
  464. }
  465. for(int i = line + 1; i < lineCount; i++)
  466. {
  467. if(buffer.getFoldLevel(i) < initialFoldLevel)
  468. {
  469. end = i - 1;
  470. break;
  471. }
  472. }
  473. } //}}}
  474. //{{{ Collapse the fold...
  475. int delta = (end - start + 1);
  476. for(int i = start; i <= end; i++)
  477. {
  478. if(offsetMgr.isLineVisible(i,index))
  479. offsetMgr.setLineVisible(i,index,false);
  480. else
  481. delta--;
  482. }
  483. if(delta == 0)
  484. {
  485. // user probably pressed A+BACK_SPACE twice
  486. return;
  487. }
  488. offsetMgr.setVirtualLineCount(index,
  489. offsetMgr.getVirtualLineCount(index)
  490. - delta);
  491. //}}}
  492. }
  493. finally
  494. {
  495. buffer.writeUnlock();
  496. }
  497. foldStructureChanged();
  498. int virtualLine = physicalToVirtual(start);
  499. if(textArea.getFirstLine() > virtualLine)
  500. textArea.setFirstLine(virtualLine - textArea.getElectricScroll());
  501. } //}}}
  502. //{{{ expandFold() method
  503. /**
  504. * Expands the fold at the specified physical line index.
  505. * @param line A physical line index
  506. * @param fully If true, all subfolds will also be expanded
  507. * @since jEdit 4.0pre3
  508. */
  509. public int expandFold(int line, boolean fully)
  510. {
  511. // the first sub-fold. used by JEditTextArea.expandFold().
  512. int returnValue = -1;
  513. int lineCount = buffer.getLineCount();
  514. int start = 0;
  515. int end = lineCount - 1;
  516. int delta = 0;
  517. try
  518. {
  519. buffer.writeLock();
  520. int initialFoldLevel = buffer.getFoldLevel(line);
  521. //{{{ Find fold start and fold end...
  522. if(line != lineCount - 1
  523. && offsetMgr.isLineVisible(line,index)
  524. && !offsetMgr.isLineVisible(line + 1,index)
  525. && buffer.getFoldLevel(line + 1) > initialFoldLevel)
  526. {
  527. // this line is the start of a fold
  528. start = line + 1;
  529. for(int i = line + 1; i < lineCount; i++)
  530. {
  531. if(/* offsetMgr.isLineVisible(i,index) && */
  532. buffer.getFoldLevel(i) <= initialFoldLevel)
  533. {
  534. end = i - 1;
  535. break;
  536. }
  537. }
  538. }
  539. else
  540. {
  541. boolean ok = false;
  542. // scan backwards looking for the start
  543. for(int i = line - 1; i >= 0; i--)
  544. {
  545. if(offsetMgr.isLineVisible(i,index) && buffer.getFoldLevel(i) < initialFoldLevel)
  546. {
  547. start = i + 1;
  548. ok = true;
  549. break;
  550. }
  551. }
  552. if(!ok)
  553. {
  554. // no folds in buffer
  555. return -1;
  556. }
  557. for(int i = line + 1; i < lineCount; i++)
  558. {
  559. if((offsetMgr.isLineVisible(i,index) &&
  560. buffer.getFoldLevel(i) < initialFoldLevel)
  561. || i == getLastVisibleLine())
  562. {
  563. end = i - 1;
  564. break;
  565. }
  566. }
  567. } //}}}
  568. //{{{ Expand the fold...
  569. // we need a different value of initialFoldLevel here!
  570. initialFoldLevel = buffer.getFoldLevel(start);
  571. for(int i = start; i <= end; i++)
  572. {
  573. buffer.getFoldLevel(i);
  574. }
  575. for(int i = start; i <= end; i++)
  576. {
  577. if(buffer.getFoldLevel(i) > initialFoldLevel)
  578. {
  579. if(returnValue == -1
  580. && i != 0
  581. && buffer.isFoldStart(i - 1))
  582. {
  583. returnValue = i - 1;
  584. }
  585. if(!offsetMgr.isLineVisible(i,index) && fully)
  586. {
  587. delta++;
  588. offsetMgr.setLineVisible(i,index,true);
  589. }
  590. }
  591. else if(!offsetMgr.isLineVisible(i,index))
  592. {
  593. delta++;
  594. offsetMgr.setLineVisible(i,index,true);
  595. }
  596. }
  597. offsetMgr.setVirtualLineCount(index,
  598. offsetMgr.getVirtualLineCount(index)
  599. + delta);
  600. //}}}
  601. if(!fully && !offsetMgr.isLineVisible(line,index))
  602. {
  603. // this is a hack, and really needs to be done better.
  604. expandFold(line,false);
  605. return returnValue;
  606. }
  607. }
  608. finally
  609. {
  610. buffer.writeUnlock();
  611. }
  612. foldStructureChanged();
  613. int virtualLine = physicalToVirtual(start);
  614. int firstLine = textArea.getFirstLine();
  615. int visibleLines = textArea.getVisibleLines();
  616. if(virtualLine + delta >= firstLine + visibleLines
  617. && delta < visibleLines - 1)
  618. {
  619. textArea.setFirstLine(virtualLine + delta - visibleLines + 1);
  620. }
  621. return returnValue;
  622. } //}}}
  623. //{{{ expandAllFolds() method
  624. /**
  625. * Expands all folds.
  626. * @since jEdit 4.0pre1
  627. */
  628. public void expandAllFolds()
  629. {
  630. try
  631. {
  632. buffer.writeLock();
  633. narrowed = false;
  634. if(offsetMgr.getVirtualLineCount(index) == buffer.getLineCount())
  635. return;
  636. offsetMgr.setVirtualLineCount(index,buffer.getLineCount());
  637. for(int i = 0; i < buffer.getLineCount(); i++)
  638. {
  639. offsetMgr.setLineVisible(i,index,true);
  640. }
  641. foldStructureChanged();
  642. }
  643. finally
  644. {
  645. buffer.writeUnlock();
  646. }
  647. } //}}}
  648. //{{{ expandFolds() method
  649. /**
  650. * This method should only be called from <code>actions.xml</code>.
  651. * @since jEdit 4.0pre1
  652. */
  653. public void expandFolds(char digit)
  654. {
  655. if(digit < '1' || digit > '9')
  656. {
  657. Toolkit.getDefaultToolkit().beep();
  658. return;
  659. }
  660. else
  661. expandFolds((int)(digit - '1') + 1);
  662. } //}}}
  663. //{{{ expandFolds() method
  664. /**
  665. * Expands all folds with the specified fold level.
  666. * @param foldLevel The fold level
  667. * @since jEdit 4.0pre1
  668. */
  669. public void expandFolds(int foldLevel)
  670. {
  671. try
  672. {
  673. buffer.writeLock();
  674. narrowed = false;
  675. // so that getFoldLevel() calling fireFoldLevelsChanged()
  676. // won't break
  677. offsetMgr.setVirtualLineCount(index,buffer.getLineCount());
  678. int newVirtualLineCount = 0;
  679. foldLevel = (foldLevel - 1) * buffer.getIndentSize() + 1;
  680. /* this ensures that the first line is always visible */
  681. boolean seenVisibleLine = false;
  682. for(int i = 0; i < buffer.getLineCount(); i++)
  683. {
  684. if(!seenVisibleLine || buffer.getFoldLevel(i) < foldLevel)
  685. {
  686. seenVisibleLine = true;
  687. offsetMgr.setLineVisible(i,index,true);
  688. newVirtualLineCount++;
  689. }
  690. else
  691. offsetMgr.setLineVisible(i,index,false);
  692. }
  693. offsetMgr.setVirtualLineCount(index,newVirtualLineCount);
  694. }
  695. finally
  696. {
  697. buffer.writeUnlock();
  698. }
  699. foldStructureChanged();
  700. } //}}}
  701. //{{{ narrow() method
  702. /**
  703. * Narrows the visible portion of the buffer to the specified
  704. * line range.
  705. * @param start The first line
  706. * @param end The last line
  707. * @since jEdit 4.0pre1
  708. */
  709. public void narrow(int start, int end)
  710. {
  711. if(start > end || start < 0 || end >= offsetMgr.getLineCount())
  712. throw new ArrayIndexOutOfBoundsException(start + ", " + end);
  713. // ideally, this should somehow be rolled into the below loop.
  714. if(start != offsetMgr.getLineCount() - 1
  715. && !offsetMgr.isLineVisible(start + 1,index))
  716. expandFold(start,false);
  717. int virtualLineCount = offsetMgr.getVirtualLineCount(index);
  718. for(int i = 0; i < start; i++)
  719. {
  720. if(offsetMgr.isLineVisible(i,index))
  721. {
  722. virtualLineCount--;
  723. offsetMgr.setLineVisible(i,index,false);
  724. }
  725. }
  726. for(int i = end + 1; i < buffer.getLineCount(); i++)
  727. {
  728. if(offsetMgr.isLineVisible(i,index))
  729. {
  730. virtualLineCount--;
  731. offsetMgr.setLineVisible(i,index,false);
  732. }
  733. }
  734. offsetMgr.setVirtualLineCount(index,virtualLineCount);
  735. narrowed = true;
  736. foldStructureChanged();
  737. // Hack... need a more direct way of obtaining a view?
  738. // JEditTextArea.getView() method?
  739. GUIUtilities.getView(textArea).getStatus().setMessageAndClear(
  740. jEdit.getProperty("view.status.narrow"));
  741. } //}}}
  742. //{{{ Methods for Buffer class to call
  743. //{{{ _grab() method
  744. /**
  745. * Do not call this method. The only reason it is public is so
  746. * that the <code>Buffer</code> class can call it.
  747. */
  748. public final void _grab(int index)
  749. {
  750. this.index = index;
  751. lastPhysical = lastVirtual = -1;
  752. } //}}}
  753. //{{{ _release() method
  754. /**
  755. * Do not call this method. The only reason it is public is so
  756. * that the <code>Buffer</code> class can call it.
  757. */
  758. public final void _release()
  759. {
  760. index = -1;
  761. } //}}}
  762. //{{{ _getIndex() method
  763. /**
  764. * Do not call this method. The only reason it is public is so
  765. * that the <code>Buffer</code> class can call it.
  766. */
  767. public final int _getIndex()
  768. {
  769. return index;
  770. } //}}}
  771. //{{{ _invalidate() method
  772. /**
  773. * Do not call this method. The only reason it is public is so
  774. * that the <code>Buffer</code> class can call it.
  775. */
  776. public void _invalidate(int startLine)
  777. {
  778. if(lastPhysical >= startLine)
  779. lastPhysical = lastVirtual = -1;
  780. } //}}}
  781. //}}}
  782. //{{{ foldStructureChanged() method
  783. /**
  784. * This method is only public so that the EditPane class can call it in
  785. * response to a buffer's fold handler change.
  786. * @since jEdit 4.0pre8
  787. */
  788. public void foldStructureChanged()
  789. {
  790. lastPhysical = lastVirtual = -1;
  791. textArea.foldStructureChanged();
  792. } //}}}
  793. //{{{ Private members
  794. //{{{ Instance variables
  795. private Buffer buffer;
  796. private OffsetManager offsetMgr;
  797. private JEditTextArea textArea;
  798. private int index;
  799. private int lastPhysical;
  800. private int lastVirtual;
  801. private boolean narrowed;
  802. //}}}
  803. //}}}
  804. }