1 22 23 package org.gjt.sp.jedit; 24 25 import javax.swing.Timer ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import org.gjt.sp.util.Log; 30 32 36 class Autosave implements ActionListener 37 { 38 public static void setInterval(int interval) 40 { 41 if(interval == 0) 42 { 43 if(timer != null) 44 { 45 timer.stop(); 46 timer = null; 47 } 48 49 return; 50 } 51 52 interval *= 1000; 53 54 if(timer == null) 55 { 56 timer = new Timer (interval,new Autosave()); 57 timer.start(); 58 } 59 else 60 timer.setDelay(interval); 61 } 63 public static void stop() 65 { 66 if(timer != null) 67 timer.stop(); 68 } 70 public void actionPerformed(ActionEvent evt) 72 { 73 82 83 if(jEdit.getViewCount() != 0 85 && PerspectiveManager.isPerspectiveDirty()) 86 { 87 PerspectiveManager.setPerspectiveDirty(false); 88 PerspectiveManager.savePerspective(true); 89 } 90 91 Buffer[] bufferArray = jEdit.getBuffers(); 92 for(int i = 0; i < bufferArray.length; i++) 93 bufferArray[i].autosave(); 94 95 Log.flushStream(); 97 } 99 private static Timer timer; 101 102 private Autosave() {} 103 } 105 | Popular Tags |