KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > macos > menu > ShowRecentDirMenu


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
23 package macos.menu;
24
25 //{{{ Imports
26
import java.awt.event.*;
27 import java.io.File JavaDoc;
28 import java.util.Vector JavaDoc;
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 public 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 JavaDoc 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 JavaDoc(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 JavaDoc path;
92         
93         public ShowRecentDirMenuItem(String JavaDoc name, String JavaDoc 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
}
109
Popular Tags