KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > buffer > FoldHandler


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
23 package org.gjt.sp.jedit.buffer;
24
25 import java.util.*;
26 import javax.swing.text.Segment JavaDoc;
27 import org.gjt.sp.jedit.ServiceManager;
28 import org.gjt.sp.util.StandardUtilities;
29
30 /**
31  * Interface for obtaining the fold level of a specified line.<p>
32  *
33  * Plugins can provide fold handlers by defining entries in their
34  * <code>services.xml</code> files like so:
35  *
36  * <pre>&lt;SERVICE CLASS="org.gjt.sp.jedit.buffer.FoldHandler" NAME="<i>name</i>"&gt;
37  * new <i>MyFoldHandler<i>();
38  *&lt;/SERVICE&gt;</pre>
39  *
40  * See {@link org.gjt.sp.jedit.ServiceManager} for details.
41  *
42  * @author Slava Pestov
43  * @version $Id: FoldHandler.java 5568 2006-07-10 20:52:23Z kpouer $
44  * @since jEdit 4.3pre3
45  */

46 public abstract class FoldHandler
47 {
48     /**
49      * The service type. See {@link org.gjt.sp.jedit.ServiceManager}.
50      * @since jEdit 4.2pre1
51      */

52     public static final String JavaDoc SERVICE = "org.gjt.sp.jedit.buffer.FoldHandler";
53
54     //{{{ getName() method
55
/**
56      * Returns the internal name of this FoldHandler
57      * @return The internal name of this FoldHandler
58      * @since jEdit 4.0pre6
59      */

60     public String JavaDoc getName()
61     {
62         return name;
63     }
64     //}}}
65

66     //{{{ getFoldLevel() method
67
/**
68      * Returns the fold level of the specified line.
69      * @param buffer The buffer in question
70      * @param lineIndex The line index
71      * @param seg A segment the fold handler can use to obtain any
72      * text from the buffer, if necessary
73      * @return The fold level of the specified line
74      * @since jEdit 4.0pre1
75      */

76     public abstract int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment JavaDoc seg);
77     //}}}
78

79     //{{{ equals() method
80
/**
81      * Returns if the specified fold handler is equal to this one.
82      * @param o The object
83      */

84     public boolean equals(Object JavaDoc o)
85     {
86         // Default implementation... subclasses can extend this.
87
if(o == null)
88             return false;
89         else
90             return getClass() == o.getClass();
91     } //}}}
92

93     //{{{ hashCode() method
94
public int hashCode()
95     {
96         return getClass().hashCode();
97     } //}}}
98

99     //{{{ getFoldHandler() method
100
/**
101      * Returns the fold handler with the specified name, or null if
102      * there is no registered handler with that name.
103      * @param name The name of the desired fold handler
104      * @since jEdit 4.0pre6
105      */

106     public static FoldHandler getFoldHandler(String JavaDoc name)
107     {
108         FoldHandler handler = (FoldHandler)ServiceManager
109             .getService(SERVICE,name);
110         return handler;
111     }
112     //}}}
113

114     //{{{ getFoldModes() method
115
/**
116      * Returns an array containing the names of all registered fold
117      * handlers.
118      *
119      * @since jEdit 4.0pre6
120      */

121     public static String JavaDoc[] getFoldModes()
122     {
123         String JavaDoc[] handlers = ServiceManager.getServiceNames(SERVICE);
124         Arrays.sort(handlers,new StandardUtilities.StringCompare());
125         return handlers;
126     }
127     //}}}
128

129     //{{{ FoldHandler() constructor
130
protected FoldHandler(String JavaDoc name)
131     {
132         this.name = name;
133     }
134     //}}}
135

136     //{{{ toString() method
137
public String JavaDoc toString()
138     {
139         return name;
140     } //}}}
141

142     private String JavaDoc name;
143 }
144
Popular Tags