PageRenderTime 126ms CodeModel.GetById 123ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 77 lines | 42 code | 11 blank | 24 comment | 11 complexity | 29aafa432b557ec2c25f33f53c06d95a MD5 | raw file
 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
20package org.gjt.sp.jedit;
21
22import javax.swing.Timer;
23import java.awt.event.ActionEvent;
24import java.awt.event.ActionListener;
25
26/**
27 * @author Slava Pestov
28 * @version $Id: Autosave.java 3930 2001-12-02 07:34:52Z spestov $
29 */
30class Autosave implements ActionListener
31{
32	public static void setInterval(int interval)
33	{
34		if(interval == 0)
35		{
36			if(timer != null)
37			{
38				timer.stop();
39				timer = null;
40			}
41
42			return;
43		}
44
45		interval *= 1000;
46
47		if(timer == null)
48		{
49			timer = new Timer(interval,new Autosave());
50			timer.start();
51		}
52		else
53			timer.setDelay(interval);
54	}
55
56	public static void stop()
57	{
58		if(timer != null)
59			timer.stop();
60	}
61
62	public void actionPerformed(ActionEvent evt)
63	{
64		// save list of open files
65		if(jEdit.getFirstView() != null)
66			jEdit.saveOpenFiles(jEdit.getFirstView());
67
68		Buffer[] bufferArray = jEdit.getBuffers();
69		for(int i = 0; i < bufferArray.length; i++)
70			bufferArray[i].autosave();
71	}
72
73	// private members
74	private static Timer timer;
75
76	private Autosave() {}
77}