PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/menu/RecentDirectoriesProvider.java

#
Java | 136 lines | 92 code | 17 blank | 27 comment | 12 complexity | 2abe72f8a4d6705f8b4ad0135cbf26f1 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. * RecentDirectoriesProvider.java - Recent directory list menu
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 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. package org.gjt.sp.jedit.menu;
  23. //{{{ Imports
  24. import javax.swing.event.*;
  25. import javax.swing.*;
  26. import java.awt.event.*;
  27. import java.util.Vector;
  28. import org.gjt.sp.jedit.browser.*;
  29. import org.gjt.sp.jedit.gui.HistoryModel;
  30. import org.gjt.sp.jedit.*;
  31. //}}}
  32. public class RecentDirectoriesProvider implements DynamicMenuProvider
  33. {
  34. //{{{ updateEveryTime() method
  35. public boolean updateEveryTime()
  36. {
  37. return true;
  38. } //}}}
  39. //{{{ update() method
  40. public void update(JMenu menu)
  41. {
  42. final View view = GUIUtilities.getView(menu);
  43. //{{{ ActionListener...
  44. ActionListener actionListener = new ActionListener()
  45. {
  46. public void actionPerformed(ActionEvent evt)
  47. {
  48. VFSBrowser.browseDirectory(view,evt.getActionCommand());
  49. view.getStatus().setMessage(null);
  50. }
  51. }; //}}}
  52. //{{{ MouseListener...
  53. MouseListener mouseListener = new MouseAdapter()
  54. {
  55. public void mouseEntered(MouseEvent evt)
  56. {
  57. view.getStatus().setMessage(
  58. ((JMenuItem)evt.getSource())
  59. .getActionCommand());
  60. }
  61. public void mouseExited(MouseEvent evt)
  62. {
  63. view.getStatus().setMessage(null);
  64. }
  65. }; //}}}
  66. HistoryModel model = HistoryModel.getModel("vfs.browser.path");
  67. if(model.getSize() == 0)
  68. {
  69. JMenuItem menuItem = new JMenuItem(
  70. jEdit.getProperty("no-recent-dirs.label"));
  71. menuItem.setEnabled(false);
  72. menu.add(menuItem);
  73. return;
  74. }
  75. boolean sort = jEdit.getBooleanProperty("sortRecent");
  76. int maxItems = jEdit.getIntegerProperty("menu.spillover",20);
  77. Vector menuItems = new Vector();
  78. for(int i = 0; i < model.getSize(); i++)
  79. {
  80. String path = model.getItem(i);
  81. JMenuItem menuItem = new JMenuItem(MiscUtilities.getFileName(path));
  82. menuItem.setActionCommand(path);
  83. menuItem.addActionListener(actionListener);
  84. menuItem.addMouseListener(mouseListener);
  85. menuItem.setIcon(FileCellRenderer.dirIcon);
  86. if(sort)
  87. menuItems.addElement(menuItem);
  88. else
  89. {
  90. if(menu.getMenuComponentCount() >= maxItems
  91. && i != model.getSize() - 1)
  92. {
  93. JMenu newMenu = new JMenu(
  94. jEdit.getProperty("common.more"));
  95. menu.add(newMenu);
  96. menu = newMenu;
  97. }
  98. menu.add(menuItem);
  99. }
  100. }
  101. if(sort)
  102. {
  103. MiscUtilities.quicksort(menuItems,
  104. new MiscUtilities.MenuItemCompare());
  105. for(int i = 0; i < menuItems.size(); i++)
  106. {
  107. if(menu.getMenuComponentCount() >= maxItems
  108. && i != 0)
  109. {
  110. JMenu newMenu = new JMenu(
  111. jEdit.getProperty("common.more"));
  112. menu.add(newMenu);
  113. menu = newMenu;
  114. }
  115. menu.add((JMenuItem)menuItems.elementAt(i));
  116. }
  117. }
  118. } //}}}
  119. }