PageRenderTime 72ms CodeModel.GetById 64ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/bundles/plugins-trunk/Ancestor/src/gatchan/jedit/ancestor/AncestorToolBar.java

#
Java | 96 lines | 62 code | 8 blank | 26 comment | 15 complexity | 52ac7c207f261c607c28b26a10678182 MD5 | raw file
 1/*
 2 * AncestorToolBar.java - The ancestor toolbar
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 2007, 2011 Matthieu Casanova
 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 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21package gatchan.jedit.ancestor;
22
23import org.gjt.sp.jedit.Buffer;
24import org.gjt.sp.jedit.View;
25import org.gjt.sp.jedit.MiscUtilities;
26import org.gjt.sp.jedit.io.VFS;
27import org.gjt.sp.jedit.io.VFSManager;
28
29import javax.swing.*;
30import java.util.LinkedList;
31
32/**
33 * @author Matthieu Casanova
34 * @version $Id: Server.java,v 1.33 2007/01/05 15:15:17 matthieu Exp $
35 */
36public class AncestorToolBar extends JToolBar
37{
38	private final View view;
39	private final LinkedList<String> list = new LinkedList<String>();
40
41	//{{{ AncestorToolBar constructor
42	public AncestorToolBar(View view)
43	{
44		this.view = view;
45	} //}}}
46
47	//{{{ setBuffer() method
48	void setBuffer(Buffer buffer)
49	{
50		String path = buffer.getPath();
51
52		list.clear();
53		while (true)
54		{
55			list.addFirst(path);
56			VFS _vfs = VFSManager.getVFSForPath(path);
57			String parent = _vfs.getParentOfPath(path);
58			if (path == null || MiscUtilities.pathsEqual(path, parent))
59				break;
60			path = parent;
61		}
62		int count = getComponentCount() - 1;
63
64		int nbTokens = list.size();
65		if (nbTokens < count)
66		{
67			for (int i = 0; i < count - nbTokens; i++)
68			{
69				remove(0);
70			}
71		}
72		else if (nbTokens > count)
73		{
74			for (int i = 0; i < nbTokens - count; i++)
75			{
76				add(new AncestorButton(), 0);
77			}
78		}
79		int i = 0;
80		int nb = list.size();
81
82		for (String fileName : list)
83		{
84			VFS _vfs = VFSManager.getVFSForPath(fileName);
85			boolean browseable = (_vfs.getCapabilities() & VFS.BROWSE_CAP) != 0;
86			AncestorButton button = (AncestorButton) getComponent(i);
87			button.setAncestor(new Ancestor(view, fileName, _vfs.getFileName(fileName)));
88			i++;
89			button.setEnabled(browseable && nb != i);
90			if (nb - 1 == i)
91			{
92				button.setText("<html><b>" + button.getText() + "</b></html>");
93			}
94		}
95	} //}}}
96}