001: /*
002: * FoldHandler.java - Fold handler interface
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2001, 2005 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.buffer;
024:
025: import javax.swing.text.Segment;
026:
027: /**
028: * Interface for obtaining the fold level of a specified line.<p>
029: *
030: * Plugins can provide fold handlers by defining entries in their
031: * <code>services.xml</code> files like so:
032: *
033: * <pre><SERVICE CLASS="org.gjt.sp.jedit.buffer.FoldHandler" NAME="<i>name</i>">
034: * new <i>MyFoldHandler<i>();
035: *</SERVICE></pre>
036: *
037: * See {@link org.gjt.sp.jedit.ServiceManager} for details.
038: *
039: * @author Slava Pestov
040: * @version $Id: FoldHandler.java 9860 2007-06-27 20:58:22Z kpouer $
041: * @since jEdit 4.3pre3
042: */
043: public abstract class FoldHandler {
044: /**
045: * The service type. See {@link org.gjt.sp.jedit.ServiceManager}.
046: * @since jEdit 4.2pre1
047: * @deprecated use {@link org.gjt.sp.jedit.ServiceManager.ServiceFoldHandlerProvider}
048: */
049: @Deprecated
050: public static final String SERVICE = "org.gjt.sp.jedit.buffer.FoldHandler";
051:
052: /** The FoldHandlerProvider. */
053: public static FoldHandlerProvider foldHandlerProvider;
054:
055: //{{{ getName() method
056: /**
057: * Returns the internal name of this FoldHandler
058: * @return The internal name of this FoldHandler
059: * @since jEdit 4.0pre6
060: */
061: public String getName() {
062: return name;
063: }
064:
065: //}}}
066:
067: //{{{ getFoldLevel() method
068: /**
069: * Returns the fold level of the specified line.
070: * @param buffer The buffer in question
071: * @param lineIndex The line index
072: * @param seg A segment the fold handler can use to obtain any
073: * text from the buffer, if necessary
074: * @return The fold level of the specified line
075: * @since jEdit 4.0pre1
076: */
077: public abstract int getFoldLevel(JEditBuffer buffer, int lineIndex,
078: Segment seg);
079:
080: //}}}
081:
082: //{{{ equals() method
083: /**
084: * Returns if the specified fold handler is equal to this one.
085: * @param o The object
086: */
087: public boolean equals(Object o) {
088: // Default implementation... subclasses can extend this.
089: if (o == null)
090: return false;
091: else
092: return getClass() == o.getClass();
093: } //}}}
094:
095: //{{{ hashCode() method
096: public int hashCode() {
097: return getClass().hashCode();
098: } //}}}
099:
100: //{{{ getFoldHandler() method
101: /**
102: * Returns the fold handler with the specified name, or null if
103: * there is no registered handler with that name.
104: * @param name The name of the desired fold handler
105: * @since jEdit 4.0pre6
106: */
107: public static FoldHandler getFoldHandler(String name) {
108: return foldHandlerProvider.getFoldHandler(name);
109: }
110:
111: //}}}
112:
113: //{{{ getFoldModes() method
114: /**
115: * Returns an array containing the names of all registered fold
116: * handlers.
117: *
118: * @since jEdit 4.0pre6
119: */
120: public static String[] getFoldModes() {
121: return foldHandlerProvider.getFoldModes();
122: }
123:
124: //}}}
125:
126: //{{{ FoldHandler() constructor
127: protected FoldHandler(String name) {
128: this .name = name;
129: }
130:
131: //}}}
132:
133: //{{{ toString() method
134: public String toString() {
135: return name;
136: } //}}}
137:
138: private String name;
139: }
|