PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/buffer/FoldHandler.java

#
Java | 154 lines | 45 code | 14 blank | 95 comment | 3 complexity | b5139e164f21d1f2c425c51f406e4754 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. * FoldHandler.java - Fold handler interface
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2001, 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.buffer;
  23. import java.util.List;
  24. import javax.swing.text.Segment;
  25. /**
  26. * Interface for obtaining the fold level of a specified line.<p>
  27. *
  28. * Plugins can provide fold handlers by defining entries in their
  29. * <code>services.xml</code> files like so:
  30. *
  31. * <pre>&lt;SERVICE CLASS="org.gjt.sp.jedit.buffer.FoldHandler" NAME="<i>name</i>"&gt;
  32. * new <i>MyFoldHandler<i>();
  33. *&lt;/SERVICE&gt;</pre>
  34. *
  35. * See {@link org.gjt.sp.jedit.ServiceManager} for details.
  36. *
  37. * @author Slava Pestov
  38. * @version $Id: FoldHandler.java 18919 2010-11-04 10:52:55Z kpouer $
  39. * @since jEdit 4.3pre3
  40. */
  41. public abstract class FoldHandler
  42. {
  43. /** The FoldHandlerProvider. */
  44. public static FoldHandlerProvider foldHandlerProvider;
  45. //{{{ getName() method
  46. /**
  47. * Returns the internal name of this FoldHandler
  48. * @return The internal name of this FoldHandler
  49. * @since jEdit 4.0pre6
  50. */
  51. public String getName()
  52. {
  53. return name;
  54. }
  55. //}}}
  56. //{{{ getFoldLevel() method
  57. /**
  58. * Returns the fold level of the specified line.
  59. * @param buffer The buffer in question
  60. * @param lineIndex The line index
  61. * @param seg A segment the fold handler can use to obtain any
  62. * text from the buffer, if necessary
  63. * @return The fold level of the specified line
  64. * @since jEdit 4.0pre1
  65. */
  66. public abstract int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment seg);
  67. //}}}
  68. //{{{ getPrecedingFoldLevels() method
  69. /**
  70. * Returns the fold levels of the lines preceding the specified line,
  71. * which depend on the specified line.
  72. * @param buffer The buffer in question
  73. * @param lineIndex The line index
  74. * @param seg A segment the fold handler can use to obtain any
  75. * @param lineFoldLevel The fold level of the specified line
  76. * @return The fold levels of the preceding lines, in decreasing line
  77. * number order (i.e. bottomost line first).
  78. * @since jEdit 4.3pre18
  79. */
  80. public List<Integer> getPrecedingFoldLevels(JEditBuffer buffer,
  81. int lineIndex, Segment seg, int lineFoldLevel)
  82. {
  83. return null;
  84. }
  85. //}}}
  86. //{{{ equals() method
  87. /**
  88. * Returns if the specified fold handler is equal to this one.
  89. * @param o The object
  90. */
  91. public boolean equals(Object o)
  92. {
  93. // Default implementation... subclasses can extend this.
  94. if(o == null)
  95. return false;
  96. else
  97. return getClass() == o.getClass();
  98. } //}}}
  99. //{{{ hashCode() method
  100. public int hashCode()
  101. {
  102. return getClass().hashCode();
  103. } //}}}
  104. //{{{ getFoldHandler() method
  105. /**
  106. * Returns the fold handler with the specified name, or null if
  107. * there is no registered handler with that name.
  108. * @param name The name of the desired fold handler
  109. * @since jEdit 4.0pre6
  110. */
  111. public static FoldHandler getFoldHandler(String name)
  112. {
  113. return foldHandlerProvider.getFoldHandler(name);
  114. }
  115. //}}}
  116. //{{{ getFoldModes() method
  117. /**
  118. * Returns an array containing the names of all registered fold
  119. * handlers.
  120. *
  121. * @since jEdit 4.0pre6
  122. */
  123. public static String[] getFoldModes()
  124. {
  125. return foldHandlerProvider.getFoldModes();
  126. }
  127. //}}}
  128. //{{{ FoldHandler() constructor
  129. protected FoldHandler(String name)
  130. {
  131. this.name = name;
  132. }
  133. //}}}
  134. //{{{ toString() method
  135. public String toString()
  136. {
  137. return name;
  138. } //}}}
  139. private final String name;
  140. }