PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/jars/MacOS/macos/menu/ShowRecentMenu.java

#
Java | 111 lines | 69 code | 13 blank | 29 comment | 4 complexity | 24009bb87bd9951cc3edcfeea9b1a7b8 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. * :tabSize=8:indentSize=8:noTabs=false:
  3. * :folding=explicit:collapseFolds=1:
  4. *
  5. * ShowRecentMenu.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. package macos.menu;
  23. //{{{ Imports
  24. import java.awt.event.*;
  25. import java.io.File;
  26. import java.util.Vector;
  27. import javax.swing.*;
  28. import javax.swing.event.*;
  29. import org.gjt.sp.jedit.*;
  30. import org.gjt.sp.jedit.browser.*;
  31. import macos.*;
  32. //}}}
  33. public class ShowRecentMenu extends JMenu implements MenuListener
  34. {
  35. //{{{ Constructor
  36. public ShowRecentMenu()
  37. {
  38. super(jEdit.getProperty("MacOSPlugin.menu.recent.label"));
  39. addMenuListener(this);
  40. } //}}}
  41. //{{{ construct() method
  42. private void construct()
  43. {
  44. Vector recent = BufferHistory.getBufferHistory();
  45. JMenuItem item;
  46. File file;
  47. int max = recent.size();
  48. int min = max - 20;
  49. if (max == 0)
  50. {
  51. item = new JMenuItem(jEdit.getProperty("MacOSPlugin.menu.recent.none"));
  52. item.setEnabled(false);
  53. add(item);
  54. return;
  55. }
  56. if (min < 0)
  57. min = 0;
  58. for (int i=max-1; i >= min ; i--)
  59. {
  60. file = new File(((BufferHistory.Entry)recent.get(i)).path);
  61. item = new ShowRecentMenuItem(file.getName(),file.getPath());
  62. item.setIcon(FileCellRenderer.fileIcon);
  63. add(item);
  64. }
  65. } //}}}
  66. //{{{ menuSelected() method
  67. public void menuSelected(MenuEvent e)
  68. {
  69. construct();
  70. } //}}}
  71. //{{{ menuDeselected() method
  72. public void menuDeselected(MenuEvent e)
  73. {
  74. removeAll();
  75. } //}}}
  76. //{{{ menuCanceled() method
  77. public void menuCanceled(MenuEvent e)
  78. {
  79. } //}}}
  80. //{{{ ShowRecentMenuItem class
  81. class ShowRecentMenuItem extends JMenuItem
  82. {
  83. String path;
  84. public ShowRecentMenuItem(String name, String path)
  85. {
  86. super(name);
  87. this.path = path;
  88. addActionListener(new ShowFileAction());
  89. }
  90. class ShowFileAction implements ActionListener
  91. {
  92. public void actionPerformed(ActionEvent e)
  93. {
  94. MacOSActions.showInFinder(path);
  95. }
  96. }
  97. } //}}}
  98. }