001: /*
002: * :tabSize=8:indentSize=8:noTabs=false:
003: * :folding=explicit:collapseFolds=1:
004: *
005: * ShowRecentMenu.java
006: * Copyright (C) 2002 Kris Kopicki
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package macos.menu;
024:
025: //{{{ Imports
026: import java.awt.event.*;
027: import java.io.File;
028: import java.util.List;
029: import javax.swing.*;
030: import javax.swing.event.*;
031: import org.gjt.sp.jedit.*;
032: import org.gjt.sp.jedit.browser.*;
033: import macos.*;
034:
035: //}}}
036:
037: public class ShowRecentMenu extends JMenu implements MenuListener {
038: //{{{ Constructor
039: public ShowRecentMenu() {
040: super (jEdit.getProperty("MacOSPlugin.menu.recent.label"));
041: addMenuListener(this );
042: } //}}}
043:
044: //{{{ construct() method
045: private void construct() {
046: List recent = BufferHistory.getHistory();
047: JMenuItem item;
048: File file;
049: int max = recent.size();
050: int min = max - 20;
051:
052: if (max == 0) {
053: item = new JMenuItem(jEdit
054: .getProperty("MacOSPlugin.menu.recent.none"));
055: item.setEnabled(false);
056: add(item);
057: return;
058: }
059:
060: if (min < 0)
061: min = 0;
062:
063: for (int i = max - 1; i >= min; i--) {
064: file = new File(((BufferHistory.Entry) recent.get(i)).path);
065: item = new ShowRecentMenuItem(file.getName(), file
066: .getPath());
067: item.setIcon(FileCellRenderer.fileIcon);
068: add(item);
069: }
070: } //}}}
071:
072: //{{{ menuSelected() method
073: public void menuSelected(MenuEvent e) {
074: construct();
075: } //}}}
076:
077: //{{{ menuDeselected() method
078: public void menuDeselected(MenuEvent e) {
079: removeAll();
080: } //}}}
081:
082: //{{{ menuCanceled() method
083: public void menuCanceled(MenuEvent e) {
084: } //}}}
085:
086: //{{{ ShowRecentMenuItem class
087: class ShowRecentMenuItem extends JMenuItem {
088: String path;
089:
090: public ShowRecentMenuItem(String name, String path) {
091: super (name);
092: this .path = path;
093: addActionListener(new ShowFileAction());
094: }
095:
096: class ShowFileAction implements ActionListener {
097: public void actionPerformed(ActionEvent e) {
098: MacOSActions.showInFinder(path);
099: }
100: }
101: } //}}}
102: }
|