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