01: /*
02: * :tabSize=8:indentSize=8:noTabs=false:
03: * :folding=explicit:collapseFolds=1:
04: *
05: * ShowRecentDirMenu.java
06: * Copyright (C) 2002 Kris Kopicki
07: *
08: * This program is free software; you can redistribute it and/or
09: * 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 macos.menu;
24:
25: //{{{ Imports
26: import java.awt.event.*;
27: import java.io.File;
28: import java.util.Vector;
29: import javax.swing.*;
30: import javax.swing.event.*;
31: import org.gjt.sp.jedit.*;
32: import org.gjt.sp.jedit.browser.*;
33: import org.gjt.sp.jedit.gui.*;
34: import macos.*;
35:
36: //}}}
37:
38: public class ShowRecentDirMenu extends JMenu implements MenuListener {
39: //{{{ Constructor
40: public ShowRecentDirMenu() {
41: super (jEdit.getProperty("MacOSPlugin.menu.recentDir.label"));
42: addMenuListener(this );
43: } //}}}
44:
45: //{{{ construct() method
46: private void construct() {
47: HistoryModel model = HistoryModel.getModel("vfs.browser.path");
48: JMenuItem item;
49: File file;
50: int max = model.getSize();
51:
52: if (max == 0) {
53: item = new JMenuItem(jEdit
54: .getProperty("MacOSPlugin.menu.recentDir.none"));
55: item.setEnabled(false);
56: add(item);
57: return;
58: }
59:
60: for (int i = 0; i < max; i++) {
61: file = new File(model.getItem(i));
62: item = new ShowRecentDirMenuItem(file.getName(), file
63: .getPath());
64: item.setIcon(FileCellRenderer.dirIcon);
65: add(item);
66: }
67: } //}}}
68:
69: //{{{ menuSelected() method
70: public void menuSelected(MenuEvent e) {
71: construct();
72: } //}}}
73:
74: //{{{ menuDeselected() method
75: public void menuDeselected(MenuEvent e) {
76: removeAll();
77: } //}}}
78:
79: //{{{ menuCanceled() method
80: public void menuCanceled(MenuEvent e) {
81: } //}}}
82:
83: //{{{ ShowRecentDirMenuItem class
84: class ShowRecentDirMenuItem extends JMenuItem {
85: String path;
86:
87: public ShowRecentDirMenuItem(String name, String path) {
88: super (name);
89: this .path = path;
90: addActionListener(new ShowFileAction());
91: }
92:
93: class ShowFileAction implements ActionListener {
94: public void actionPerformed(ActionEvent e) {
95: MacOSActions.showInFinder(path);
96: }
97: }
98: } //}}}
99: }
|