|
What this is
Other links
The source code/* * KillRing.java - Stores deleted text * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2003 Slava Pestov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.gjt.sp.jedit.buffer; import com.microstar.xml.*; import javax.swing.event.ListDataListener; import javax.swing.ListModel; import java.io.*; import java.util.*; import org.gjt.sp.jedit.*; import org.gjt.sp.util.Log; public class KillRing { //{{{ propertiesChanged() method public static void propertiesChanged() { int newSize = jEdit.getIntegerProperty("history",25); if(ring == null) ring = new UndoManager.Remove[newSize]; else if(newSize != ring.length) { UndoManager.Remove[] newRing = new UndoManager.Remove[ newSize]; ListModel model = new RingListModel(); int newCount = Math.min(model.getSize(),newSize); for(int i = 0; i < newCount; i++) { newRing[i] = (UndoManager.Remove) model.getElementAt(i); } ring = newRing; count = newCount; wrap = false; } else if(count == ring.length) { count = 0; wrap = true; } } //}}} //{{{ getListModel() method public static ListModel getListModel() { return new RingListModel(); } //}}} //{{{ load() method public static void load() { String settingsDirectory = jEdit.getSettingsDirectory(); if(settingsDirectory == null) return; File killRing = new File(MiscUtilities.constructPath( settingsDirectory,"killring.xml")); if(!killRing.exists()) return; killRingModTime = killRing.lastModified(); Log.log(Log.MESSAGE,KillRing.class,"Loading killring.xml"); KillRingHandler handler = new KillRingHandler(); XmlParser parser = new XmlParser(); Reader in = null; parser.setHandler(handler); try { in = new BufferedReader(new FileReader(killRing)); parser.parse(null, null, in); } catch(XmlException xe) { int line = xe.getLine(); String message = xe.getMessage(); Log.log(Log.ERROR,KillRing.class,killRing + ":" + line + ": " + message); } catch(FileNotFoundException fnf) { //Log.log(Log.DEBUG,BufferHistory.class,fnf); } catch(Exception e) { Log.log(Log.ERROR,KillRing.class,e); } finally { try { if(in != null) in.close(); } catch(IOException io) { Log.log(Log.ERROR,KillRing.class,io); } } ring = (UndoManager.Remove[])handler.list.toArray( new UndoManager.Remove[handler.list.size()]); count = ring.length; } //}}} //{{{ save() method public static void save() { String settingsDirectory = jEdit.getSettingsDirectory(); if(settingsDirectory == null) return; File file1 = new File(MiscUtilities.constructPath( settingsDirectory, "#killring.xml#save#")); File file2 = new File(MiscUtilities.constructPath( settingsDirectory, "killring.xml")); if(file2.exists() && file2.lastModified() != killRingModTime) { Log.log(Log.WARNING,KillRing.class,file2 + " changed on disk; will not save recent" + " files"); return; } jEdit.backupSettingsFile(file2); Log.log(Log.MESSAGE,KillRing.class,"Saving killring.xml"); String lineSep = System.getProperty("line.separator"); BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(file1)); out.write(""); out.write(lineSep); out.write(""); out.write(lineSep); out.write(" |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.