KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > menu > FavoritesProvider


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
23 package org.gjt.sp.jedit.menu;
24
25 //{{{ Imports
26
import javax.swing.*;
27 import java.awt.event.*;
28 import java.util.Arrays JavaDoc;
29
30 import org.gjt.sp.jedit.browser.*;
31 import org.gjt.sp.jedit.io.*;
32 import org.gjt.sp.jedit.*;
33 //}}}
34

35 public class FavoritesProvider implements DynamicMenuProvider
36 {
37     //{{{ updateEveryTime() method
38
public boolean updateEveryTime()
39     {
40         return false;
41     } //}}}
42

43     //{{{ update() method
44
public void update(JMenu menu)
45     {
46         final View view = GUIUtilities.getView(menu);
47
48         //{{{ ActionListeners
49
ActionListener fileListener = new ActionListener()
50         {
51             public void actionPerformed(ActionEvent evt)
52             {
53                 jEdit.openFile(view,evt.getActionCommand());
54             }
55         };
56
57         ActionListener dirListener = new ActionListener()
58         {
59             public void actionPerformed(ActionEvent evt)
60             {
61                 VFSBrowser.browseDirectory(view,
62                     evt.getActionCommand());
63             }
64         }; //}}}
65

66         VFSFile[] favorites = 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             Arrays.sort(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                 VFSFile favorite = favorites[i];
85                 JMenuItem mi = new JMenuItem(
86                     favorite.getPath());
87                 mi.setIcon(FileCellRenderer
88                     .getIconForFile(
89                     favorite,false));
90                 if(favorite.getType() == VFSFile.FILE)
91                 {
92                     mi.addActionListener(fileListener);
93                 }
94                 else
95                 {
96                     mi.addActionListener(dirListener);
97                 }
98                 menu.add(mi);
99             }
100         }
101     } //}}}
102
}
103
Popular Tags