PageRenderTime 348ms CodeModel.GetById 140ms RepoModel.GetById 116ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/Autosave.java

#
Java | 77 lines | 42 code | 11 blank | 24 comment | 11 complexity | 29aafa432b557ec2c25f33f53c06d95a 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. * Autosave.java - Autosave manager
  3. * Copyright (C) 1998, 1999, 2000 Slava Pestov
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package org.gjt.sp.jedit;
  20. import javax.swing.Timer;
  21. import java.awt.event.ActionEvent;
  22. import java.awt.event.ActionListener;
  23. /**
  24. * @author Slava Pestov
  25. * @version $Id: Autosave.java 3930 2001-12-02 07:34:52Z spestov $
  26. */
  27. class Autosave implements ActionListener
  28. {
  29. public static void setInterval(int interval)
  30. {
  31. if(interval == 0)
  32. {
  33. if(timer != null)
  34. {
  35. timer.stop();
  36. timer = null;
  37. }
  38. return;
  39. }
  40. interval *= 1000;
  41. if(timer == null)
  42. {
  43. timer = new Timer(interval,new Autosave());
  44. timer.start();
  45. }
  46. else
  47. timer.setDelay(interval);
  48. }
  49. public static void stop()
  50. {
  51. if(timer != null)
  52. timer.stop();
  53. }
  54. public void actionPerformed(ActionEvent evt)
  55. {
  56. // save list of open files
  57. if(jEdit.getFirstView() != null)
  58. jEdit.saveOpenFiles(jEdit.getFirstView());
  59. Buffer[] bufferArray = jEdit.getBuffers();
  60. for(int i = 0; i < bufferArray.length; i++)
  61. bufferArray[i].autosave();
  62. }
  63. // private members
  64. private static Timer timer;
  65. private Autosave() {}
  66. }