PageRenderTime 135ms CodeModel.GetById 130ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/menu/FavoritesProvider.java

#
Java | 107 lines | 71 code | 8 blank | 28 comment | 4 complexity | f24363138795b6317b16d5ccba6e9a5a MD5 | raw file
  1/*
  2 * FavoritesProvider.java - Favorites list menu
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2003 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.menu;
 24
 25//{{{ Imports
 26import javax.swing.event.*;
 27import javax.swing.*;
 28import java.awt.event.*;
 29import org.gjt.sp.jedit.browser.*;
 30import org.gjt.sp.jedit.io.*;
 31import org.gjt.sp.jedit.*;
 32//}}}
 33
 34public class FavoritesProvider implements DynamicMenuProvider
 35{
 36	//{{{ updateEveryTime() method
 37	public boolean updateEveryTime()
 38	{
 39		return false;
 40	} //}}}
 41
 42	//{{{ update() method
 43	public void update(JMenu menu)
 44	{
 45		final View view = GUIUtilities.getView(menu);
 46
 47		//{{{ ActionListeners
 48		ActionListener fileListener = new ActionListener()
 49		{
 50			public void actionPerformed(ActionEvent evt)
 51			{
 52				jEdit.openFile(view,evt.getActionCommand());
 53			}
 54		};
 55
 56		ActionListener dirListener = new ActionListener()
 57		{
 58			public void actionPerformed(ActionEvent evt)
 59			{
 60				VFSBrowser.browseDirectory(view,
 61					evt.getActionCommand());
 62			}
 63		}; //}}}
 64
 65		VFS.DirectoryEntry[] favorites
 66			= FavoritesVFS.getFavorites();
 67		if(favorites.length == 0)
 68		{
 69			JMenuItem mi = new JMenuItem(
 70				jEdit.getProperty(
 71				"vfs.browser.favorites"
 72				+ ".no-favorites.label"));
 73			mi.setEnabled(false);
 74			menu.add(mi);
 75		}
 76		else
 77		{
 78			MiscUtilities.quicksort(favorites,
 79				new VFS.DirectoryEntryCompare(
 80				jEdit.getBooleanProperty("vfs.browser.sortMixFilesAndDirs"),
 81				jEdit.getBooleanProperty("vfs.browser.sortIgnoreCase")));
 82			for(int i = 0; i < favorites.length; i++)
 83			{
 84				VFS.DirectoryEntry favorite
 85					= favorites[i];
 86				JMenuItem mi = new JMenuItem(favorite.path);
 87				mi.setIcon(FileCellRenderer
 88					.getIconForFile(
 89					favorite,false));
 90				if(favorite.type ==
 91					VFS.DirectoryEntry.FILE)
 92				{
 93					mi.addActionListener(fileListener);
 94				}
 95				else
 96				{
 97					mi.addActionListener(dirListener);
 98				}
 99				menu.add(mi);
100			}
101		}
102	} //}}}
103
104	//{{{ Private members
105	private String dir;
106	//}}}
107}