    001    /*
    002     * SideKickFoldHandler.java
    003     * :tabSize=8:indentSize=8:noTabs=false:
    004     * :folding=explicit:collapseFolds=1:
    005     *
    006     * Copyright (C) 2003 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 sidekick;
    024
    025    //{{{ Imports
    026    import javax.swing.text.Segment;
    027    import javax.swing.tree.TreePath;
    028    import org.gjt.sp.jedit.buffer.FoldHandler;
    029    import org.gjt.sp.jedit.buffer.JEditBuffer;
    030    //}}}
    031
    032    /**
    033    * Provides a <code>FoldHandler</code> based on the {@link sidekick.Asset}s parsed from the buffer.  Each <code>Asset</code> will become a fold.
    034     */
    035    public class SideKickFoldHandler extends FoldHandler
    036    {
    037            //{{{ SideKickFoldHandler constructor
    038            public SideKickFoldHandler()
    039            {
    040                    super("sidekick");
    041            } //}}}
    042
    043            //{{{ getFoldLevel() method
    044            public int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment seg)
    045            {
    046                    if(lineIndex == 0)
    047                            return 0;
    048
    049                    SideKickParsedData data = (SideKickParsedData)buffer.getProperty(
    050                            SideKickPlugin.PARSED_DATA_PROPERTY);
    051                    if(data == null)
    052                            return 0;
    053                    TreePath path = data.getTreePathForPosition(
    054                            buffer.getLineStartOffset(lineIndex) - 1);
    055                    if(path == null)
    056                            return 0;
    057                    else
    058                            return path.getPathCount();
    059            } //}}}
    060    }