PageRenderTime 61ms CodeModel.GetById 26ms app.highlight 21ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/jars/MacOS/macos/menu/ShowRecentDirMenu.java

#
Java | 108 lines | 67 code | 12 blank | 29 comment | 3 complexity | d470e39892e904fbaa7db73fce5bd22f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1/* 
  2 * :tabSize=8:indentSize=8:noTabs=false:
  3 * :folding=explicit:collapseFolds=1:
  4 *
  5 * ShowRecentDirMenu.java
  6 * Copyright (C) 2002 Kris Kopicki
  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 macos.menu;
 24
 25//{{{ Imports
 26import java.awt.event.*;
 27import java.io.File;
 28import java.util.Vector;
 29import javax.swing.*;
 30import javax.swing.event.*;
 31import org.gjt.sp.jedit.*;
 32import org.gjt.sp.jedit.browser.*;
 33import org.gjt.sp.jedit.gui.*;
 34import macos.*;
 35//}}}
 36
 37public class ShowRecentDirMenu extends JMenu implements MenuListener
 38{
 39	//{{{ Constructor
 40	public ShowRecentDirMenu()
 41	{
 42		super(jEdit.getProperty("MacOSPlugin.menu.recentDir.label"));
 43		addMenuListener(this);
 44	} //}}}
 45	
 46	//{{{ construct() method
 47	private void construct()
 48	{
 49		HistoryModel model = HistoryModel.getModel("vfs.browser.path");
 50		JMenuItem item;
 51		File file;
 52		int max = model.getSize();
 53		
 54		if (max == 0)
 55		{
 56			item = new JMenuItem(jEdit.getProperty("MacOSPlugin.menu.recentDir.none"));
 57			item.setEnabled(false);
 58			add(item);
 59			return;
 60		}
 61		
 62		for (int i=0; i < max ; i++)
 63		{
 64			file = new File(model.getItem(i));
 65			item = new ShowRecentDirMenuItem(file.getName(),file.getPath());
 66			item.setIcon(FileCellRenderer.dirIcon);
 67			add(item);
 68		}
 69	} //}}}
 70	
 71	//{{{ menuSelected() method
 72	public void menuSelected(MenuEvent e)
 73	{
 74		construct();
 75	} //}}}
 76	
 77	//{{{ menuDeselected() method
 78	public void menuDeselected(MenuEvent e)
 79	{
 80		removeAll();
 81	} //}}}
 82	
 83	//{{{ menuCanceled() method
 84	public void menuCanceled(MenuEvent e)
 85	{
 86	} //}}}
 87	
 88	//{{{ ShowRecentDirMenuItem class
 89	class ShowRecentDirMenuItem extends JMenuItem
 90	{
 91		String path;
 92		
 93		public ShowRecentDirMenuItem(String name, String path)
 94		{
 95			super(name);
 96			this.path = path;
 97			addActionListener(new ShowFileAction());
 98		}
 99		
100		class ShowFileAction implements ActionListener
101		{
102			public void actionPerformed(ActionEvent e)
103			{
104				MacOSActions.showInFinder(path);
105			}
106		}
107	} //}}}
108}