[Jsxe-cvs] SF.net SVN: jsxe: [1104] branches/jsxe2
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-04 19:17:55
|
Revision: 1104 Author: ian_lewis Date: 2006-08-04 12:17:41 -0700 (Fri, 04 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1104&view=rev Log Message: ----------- More porting of jEdit's VFS to jsXe Modified Paths: -------------- branches/jsxe2/Changelog branches/jsxe2/messages/messages branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentEvent.java branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentListener.java branches/jsxe2/src/net/sourceforge/jsxe/dom2/ls/XMLDocumentIORequest.java branches/jsxe2/src/net/sourceforge/jsxe/io/FileRootsVFS.java branches/jsxe2/src/net/sourceforge/jsxe/io/FileVFS.java branches/jsxe2/src/net/sourceforge/jsxe/io/VFS.java branches/jsxe2/src/net/sourceforge/jsxe/io/VFSManager.java branches/jsxe2/src/net/sourceforge/jsxe/properties branches/jsxe2/src/net/sourceforge/jsxe/util/MiscUtilities.java Modified: branches/jsxe2/Changelog =================================================================== --- branches/jsxe2/Changelog 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/Changelog 2006-08-04 19:17:41 UTC (rev 1104) @@ -1,3 +1,7 @@ +08/03/2006 Ian Lewis <Ian...@me...> + + * More porting of jEdit's VFS classes to jsXe + 07/29/2006 Ian Lewis <Ian...@me...> * Added some more code for multi-threaded IO support. Modified: branches/jsxe2/messages/messages =================================================================== --- branches/jsxe2/messages/messages 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/messages/messages 2006-08-04 19:17:41 UTC (rev 1104) @@ -179,6 +179,15 @@ DocumentBuffer.Close.Message={0} unsaved! Save it now? DocumentBuffer.Close.Message.Title=Unsaved Changes +#{{{ I/O status messages +vfs.status.load=Loading {0} +vfs.status.save=Saving {0} +vfs.status.autosave=Autosaving {0} +vfs.status.listing-directory=Listing {0} +vfs.status.deleting=Deleting {0} +vfs.status.renaming=Renaming {0} to {1} +#}}} + #{0} file name DocumentBuffer.Saved.Message={0} Saved DocumentBuffer.Closed.Message={0} Closed @@ -250,6 +259,21 @@ #}}} +#{{{ VFS +vfs.browser.name=Name +vfs.browser.type=Type +vfs.browser.type.file=File +vfs.browser.type.directory=Directory +vfs.browser.type.filesystem=File system +vfs.browser.status=Status +vfs.browser.status.no=No access +vfs.browser.status.ro=Read only +vfs.browser.status.append=Append only +vfs.browser.status.rw=Read/write +vfs.browser.size=Size +vfs.browser.modified=Last modified +#}}} + #{{{ Dialogs #{{{ Download resource dialog Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -32,8 +32,13 @@ import net.sourceforge.jsxe.dom2.event.*; import net.sourceforge.jsxe.util.Log; import net.sourceforge.jsxe.util.MiscUtilities; +import net.sourceforge.jsxe.util.ReadWriteLock; //}}} +//{{{ Swing classes +import javax.swing.text.Segment; +//}}} + //{{{ DOM classes import org.w3c.dom.*; import org.w3c.dom.events.*; @@ -44,10 +49,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.HashMap; +import java.util.*; import java.net.URI; //}}} @@ -112,6 +114,8 @@ * serialize method. */ public static final String LINE_SEPARATOR = "line-separator"; + + public static final String ENCODING_AUTODETECT = "encoding.autodetect"; //}}} //{{{ XMLDocument constructor @@ -361,7 +365,7 @@ }//}}} //{{{ setProperty() - public void settProperty(String key, String value) { + public void setProperty(String key, String value) { synchronized(propertyLock) { if (value == null) { m_properties.remove(key); Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentEvent.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentEvent.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentEvent.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -25,6 +25,7 @@ package net.sourceforge.jsxe.dom2.event; import net.sourceforge.jsxe.dom2.*; +import java.util.EventObject; /** * XMLDocumentEvents are modifications to the structure of the XMLDocument. @@ -35,9 +36,8 @@ * @see XMLDocument * @since jsXe 0.5 pre3 */ -public interface XMLDocumentEvent extends EventListener { +public class XMLDocumentEvent extends EventObject { - private XMLDocument m_document; private int m_offset; private int m_length; private short m_type; @@ -51,7 +51,7 @@ * */ public XMLDocumentEvent(XMLDocument doc, int offset, String text, short type) { - m_document = doc; + super(doc); m_type = type; m_length = text.length(); m_offset = offset; @@ -62,7 +62,7 @@ * Gets the document that was updated. */ public XMLDocument getDocument() { - return m_document; + return (XMLDocument)getSource(); }//}}} //{{{ getOffset() Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentListener.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentListener.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom2/event/XMLDocumentListener.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -25,10 +25,11 @@ package net.sourceforge.jsxe.dom2.event; import net.sourceforge.jsxe.dom2.*; +import java.util.EventListener; public interface XMLDocumentListener extends EventListener { - public void propertyChanged(PropertyChangeEvent event); + public void propertyChanged(PropertyChangedEvent event); public void insertUpdate(XMLDocumentEvent event); Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom2/ls/XMLDocumentIORequest.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom2/ls/XMLDocumentIORequest.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom2/ls/XMLDocumentIORequest.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -32,6 +32,8 @@ import java.util.Vector; import net.sourceforge.jsxe.io.*; import net.sourceforge.jsxe.*; +import net.sourceforge.jsxe.gui.TabbedView; +import net.sourceforge.jsxe.dom2.XMLDocument; import net.sourceforge.jsxe.util.*; //}}} @@ -82,7 +84,7 @@ /** * An insert file request. */ - public static final int INSERT = 3; + // public static final int INSERT = 3; /** * Magic numbers used for auto-detecting Unicode and GZIP files. @@ -136,14 +138,22 @@ case AUTOSAVE: autosave(); break; - case INSERT: - insert(); - break; + // case INSERT: + // insert(); + // break; default: throw new InternalError(); } } //}}} - + + //{{{ getLoadData() + /** + * Gets the data loaded from a load request. + */ + public SegmentBuffer getLoadData() { + return m_loadData; + }//}}} + //{{{ toString() method public String toString() { @@ -175,6 +185,7 @@ private Object session; private VFS vfs; private String path; + private SegmentBuffer m_loadData; //}}} //{{{ load() method @@ -215,7 +226,7 @@ } catch(CharConversionException ch) { Log.log(Log.ERROR,this,ch); - Object[] pp = { buffer.getProperty(Buffer.ENCODING), ch.toString() }; + Object[] pp = { buffer.getProperty(XMLDocument.ENCODING), ch.toString() }; VFSManager.error(view,path,"IO.Error.Encoding.Error",pp); @@ -223,7 +234,7 @@ } catch(UnsupportedEncodingException uu) { Log.log(Log.ERROR,this,uu); - Object[] pp = { buffer.getProperty(Buffer.ENCODING), + Object[] pp = { buffer.getProperty(XMLDocument.ENCODING), uu.toString() }; VFSManager.error(view,path,"IO.Error.Encoding.Error",pp); @@ -274,11 +285,11 @@ private Reader autodetect(InputStream in) throws IOException { in = new BufferedInputStream(in); - String encoding = buffer.getStringProperty(Buffer.ENCODING); + String encoding = buffer.getStringProperty(XMLDocument.ENCODING); if (!in.markSupported()) { Log.log(Log.WARNING,this,"Mark not supported: " + in); } else { - if(buffer.getBooleanProperty(Buffer.ENCODING_AUTODETECT)) { + if(buffer.getBooleanProperty(XMLDocument.ENCODING_AUTODETECT)) { in.mark(XML_PI_LENGTH); int b1 = in.read(); int b2 = in.read(); @@ -300,13 +311,13 @@ encoding = "UTF-8"; } else { - if (b1 == GZIP_MAGIC_1 && b2 == GZIP_MAGIC_2) { - in.reset(); - in = new GZIPInputStream(in); - buffer.setBooleanProperty(Buffer.GZIPPED,true); - // auto-detect encoding within the gzip stream. - return autodetect(in); - } else { + // if (b1 == GZIP_MAGIC_1 && b2 == GZIP_MAGIC_2) { + // in.reset(); + // in = new GZIPInputStream(in); + // buffer.setBooleanProperty(Buffer.GZIPPED,true); + // // auto-detect encoding within the gzip stream. + // return autodetect(in); + // } else { if ((b1 == UNICODE_MAGIC_1 && b2 == UNICODE_MAGIC_2) || (b1 == UNICODE_MAGIC_2 @@ -314,7 +325,7 @@ { in.reset(); encoding = "UTF-16"; - buffer.setProperty(Buffer.ENCODING,encoding); + buffer.setProperty(XMLDocument.ENCODING,encoding); } else { if (b1 == UTF8_MAGIC_1 && b2 == UTF8_MAGIC_2 && b3 == UTF8_MAGIC_3) @@ -358,7 +369,7 @@ in.reset(); } } - } + // } } } } @@ -367,15 +378,14 @@ } //}}} //{{{ read() method - private SegmentBuffer read(Reader in, long length, - boolean insert) throws IOException - { + private SegmentBuffer read(Reader in, long length, boolean insert) throws IOException { + /* we guess an initial size for the array */ - IntegerArray endOffsets = new IntegerArray( - Math.max(1,(int)(length / 50))); + // IntegerArray endOffsets = new IntegerArray( + // Math.max(1,(int)(length / 50))); // only true if the file size is known - boolean trackProgress = (!buffer.isTemporary() && length != 0); + boolean trackProgress = (length != 0); if (trackProgress) { setProgressValue(0); @@ -447,7 +457,7 @@ seg.append(buf,lastLine,i - lastLine); seg.append('\n'); - endOffsets.add(seg.count); + // endOffsets.add(seg.count); if(trackProgress && lineCount++ % PROGRESS_INTERVAL == 0) setProgressValue(seg.count); @@ -485,7 +495,7 @@ seg.append(buf,lastLine, i - lastLine); seg.append('\n'); - endOffsets.add(seg.count); + // endOffsets.add(seg.count); if(trackProgress && lineCount++ % PROGRESS_INTERVAL == 0) setProgressValue(seg.count); lastLine = i + 1; @@ -539,39 +549,36 @@ // Chop trailing newline and/or ^Z (if any) int bufferLength = seg.count; - if(bufferLength != 0) - { + if (bufferLength != 0) { char ch = seg.array[bufferLength - 1]; if(ch == 0x1a /* DOS ^Z */) seg.count--; } - buffer.setBooleanProperty(Buffer.TRAILING_EOL,false); - if(bufferLength != 0 && jEdit.getBooleanProperty("stripTrailingEOL")) - { - char ch = seg.array[bufferLength - 1]; - if(ch == '\n') - { - buffer.setBooleanProperty(Buffer.TRAILING_EOL,true); - seg.count--; - endOffsets.setSize(endOffsets.getSize() - 1); - } - } + // buffer.setBooleanProperty(Buffer.TRAILING_EOL,false); + // if (bufferLength != 0 && jEdit.getBooleanProperty("stripTrailingEOL")) { + // char ch = seg.array[bufferLength - 1]; + // if (ch == '\n') { + // buffer.setBooleanProperty(Buffer.TRAILING_EOL,true); + // seg.count--; + // // endOffsets.setSize(endOffsets.getSize() - 1); + // } + // } // add a line marker at the end for proper offset manager // operation - endOffsets.add(seg.count + 1); + // endOffsets.add(seg.count + 1); // to avoid having to deal with read/write locks and such, // we insert the loaded data into the buffer in the // post-load cleanup runnable, which runs in the AWT thread. - if(!insert) - { - buffer.setProperty(LOAD_DATA,seg); - buffer.setProperty(END_OFFSETS,endOffsets); - buffer.setProperty(NEW_PATH,path); - if(lineSeparator != null) - buffer.setProperty(Buffer.LINESEP,lineSeparator); + if (!insert) { + m_loadData = seg; + // buffer.setProperty(END_OFFSETS,endOffsets); + // buffer.setProperty(NEW_PATH,path); + if (lineSeparator != null) { + buffer.setProperty(XMLDocument.LINE_SEPARATOR, lineSeparator); + } } // used in insert() @@ -586,7 +593,7 @@ try { String[] args = { vfs.getFileName(path) }; - setStatus(jEdit.getProperty("vfs.status.save",args)); + setStatus(Messages.getMessage("vfs.status.save",args)); // the entire save operation can be aborted... setAbortable(true); @@ -595,12 +602,12 @@ path = MiscUtilities.resolveSymlinks(path); // Only backup once per session - if(buffer.getProperty(Buffer.BACKED_UP) == null - || jEdit.getBooleanProperty("backupEverySave")) - { - vfs._backup(session,path,view); - buffer.setBooleanProperty(Buffer.BACKED_UP,true); - } + // if(buffer.getProperty(Buffer.BACKED_UP) == null + // || jEdit.getBooleanProperty("backupEverySave")) + // { + // vfs._backup(session,path,view); + // buffer.setBooleanProperty(Buffer.BACKED_UP,true); + // } /* if the VFS supports renaming files, we first * save to #<filename>#save#, then rename that @@ -614,7 +621,7 @@ String savePath; boolean twoStageSave = (vfs.getCapabilities() & VFS.RENAME_CAP) != 0 - && jEdit.getBooleanProperty("twoStageSave"); + && jsXe.getBooleanProperty("twoStageSave"); if(twoStageSave) savePath = vfs.getTwoStageSaveName(path); else @@ -632,11 +639,11 @@ // Can't use buffer.getName() here because // it is not changed until the save is // complete - if(savePath.endsWith(".gz")) - buffer.setBooleanProperty(Buffer.GZIPPED,true); + // if(savePath.endsWith(".gz")) + // buffer.setBooleanProperty(Buffer.GZIPPED,true); - if(buffer.getBooleanProperty(Buffer.GZIPPED)) - out = new GZIPOutputStream(out); + // if(buffer.getBooleanProperty(Buffer.GZIPPED)) + // out = new GZIPOutputStream(out); write(buffer,out); @@ -710,7 +717,7 @@ try { String[] args = { vfs.getFileName(path) }; - setStatus(jEdit.getProperty("vfs.status.autosave",args)); + setStatus(Messages.getMessage("vfs.status.autosave",args)); // the entire save operation can be aborted... setAbortable(true); @@ -756,152 +763,204 @@ } //}}} //{{{ write() method - private void write(Buffer buffer, OutputStream _out) - throws IOException - { - BufferedWriter out = null; + // private void write(XMLDocument buffer, OutputStream _out) throws IOException { + // BufferedWriter out = null; - try - { - String encoding = buffer.getStringProperty(Buffer.ENCODING); - if(encoding.equals(MiscUtilities.UTF_8_Y)) - { - // not supported by Java... - _out.write(UTF8_MAGIC_1); - _out.write(UTF8_MAGIC_2); - _out.write(UTF8_MAGIC_3); - _out.flush(); - encoding = "UTF-8"; - } + // try { + // String encoding = buffer.getStringProperty(Buffer.ENCODING); + // if (encoding.equals(MiscUtilities.UTF_8_Y)) { + // // not supported by Java... + // _out.write(UTF8_MAGIC_1); + // _out.write(UTF8_MAGIC_2); + // _out.write(UTF8_MAGIC_3); + // _out.flush(); + // encoding = "UTF-8"; + // } - out = new BufferedWriter( - new OutputStreamWriter(_out,encoding), - IOBUFSIZE); + // out = new BufferedWriter(new OutputStreamWriter(_out,encoding), IOBUFSIZE); - Segment lineSegment = new Segment(); - String newline = buffer.getStringProperty(Buffer.LINESEP); - if(newline == null) - newline = System.getProperty("line.separator"); + // Segment lineSegment = new Segment(); + // String newline = buffer.getStringProperty(Buffer.LINESEP); + // if (newline == null) { + // newline = System.getProperty("line.separator"); + // } - setProgressMaximum(buffer.getLineCount() / PROGRESS_INTERVAL); - setProgressValue(0); + // setProgressMaximum(buffer.getLineCount() / PROGRESS_INTERVAL); + // setProgressValue(0); - int i = 0; - while(i < buffer.getLineCount()) - { - buffer.getLineText(i,lineSegment); - out.write(lineSegment.array,lineSegment.offset, - lineSegment.count); + // int i = 0; + // while (i < buffer.getLineCount()) { + // buffer.getLineText(i,lineSegment); + // out.write(lineSegment.array, lineSegment.offset, lineSegment.count); - if(i != buffer.getLineCount() - 1) - { - out.write(newline); - } + // if (i != buffer.getLineCount() - 1) { + // out.write(newline); + // } - if(++i % PROGRESS_INTERVAL == 0) - setProgressValue(i / PROGRESS_INTERVAL); - } + // if (++i % PROGRESS_INTERVAL == 0) { + // setProgressValue(i / PROGRESS_INTERVAL); + // } + // } - if(jEdit.getBooleanProperty("stripTrailingEOL") - && buffer.getBooleanProperty(Buffer.TRAILING_EOL)) - { - out.write(newline); + // // if(jEdit.getBooleanProperty("stripTrailingEOL") + // // && buffer.getBooleanProperty(Buffer.TRAILING_EOL)) + // // { + // // out.write(newline); + // // } + // } finally { + // if (out != null) { + // out.close(); + // } else { + // _out.close(); + // } + // } + // } //}}} + + //{{{ write() + private void write(XMLDocument buffer, OutputStream out) throws IOException { + + String newLine = getProperty(XMLDocument.LINE_SEPARATOR); + + String encoding = getProperty(XMLDocument.ENCODING); + if (encoding.equals(MiscUtilities.UTF_8_Y)) { + // not supported by Java... + out.write(UTF8_MAGIC_1); + out.write(UTF8_MAGIC_2); + out.write(UTF8_MAGIC_3); + out.flush(); + encoding = "UTF-8"; + } + + //now just write out the text. + int length = buffer.getLength(); + int index = 0; + BufferedWriter outbuf = new BufferedWriter(new OutputStreamWriter(out, encoding), IO_BUFFER_SIZE); + Segment seg = new Segment(); + + while (index < length) { + int size = WRITE_SIZE; + try { + size = Math.min(length - index, WRITE_SIZE); + } catch(NumberFormatException nf) { + Log.log(Log.ERROR, this, nf); } + + // out.write(m_content.getText(index, size).getBytes(getProperty(ENCODING)), index, size); + buffer.getText(index, size, seg); + + int startOffset = seg.offset; + int endOffset = size + seg.offset; + + for (int i=startOffset; i<endOffset; i++) { + if (seg.array[i]=='\n') { + outbuf.write(seg.array, seg.offset, i - seg.offset); + outbuf.write(newLine.toCharArray(), 0, newLine.length()); + + //add 1 because of \n character, + seg.count -= i-seg.offset+1; + seg.offset += i-seg.offset+1; + } + } + + //write the rest + outbuf.write(seg.array, seg.offset, seg.count); + index += size; } - finally - { - if(out != null) - out.close(); - else - _out.close(); - } - } //}}} + + outbuf.close(); + }//}}} + + // //{{{ insert() method + // private void insert() + // { + // InputStream in = null; - //{{{ insert() method - private void insert() - { - InputStream in = null; + // try + // { + // try + // { + // String[] args = { vfs.getFileName(path) }; + // setStatus(jEdit.getProperty("vfs.status.load",args)); + // setAbortable(true); - try - { - try - { - String[] args = { vfs.getFileName(path) }; - setStatus(jEdit.getProperty("vfs.status.load",args)); - setAbortable(true); + // path = vfs._canonPath(session,path,view); - path = vfs._canonPath(session,path,view); + // VFS.DirectoryEntry entry = vfs._getDirectoryEntry( + // session,path,view); + // long length; + // if(entry != null) + // length = entry.length; + // else + // length = 0L; - VFS.DirectoryEntry entry = vfs._getDirectoryEntry( - session,path,view); - long length; - if(entry != null) - length = entry.length; - else - length = 0L; + // in = vfs._createInputStream(session,path,false,view); + // if(in == null) + // return; - in = vfs._createInputStream(session,path,false,view); - if(in == null) - return; + // final SegmentBuffer seg = read( + // autodetect(in),length,true); - final SegmentBuffer seg = read( - autodetect(in),length,true); + // /* we don't do this in Buffer.insert() so that + // we can insert multiple files at once */ + // VFSManager.runInAWTThread(new Runnable() + // { + // public void run() + // { + // view.getTextArea().setSelectedText( + // seg.toString()); + // } + // }); + // } + // catch(IOException io) + // { + // Log.log(Log.ERROR,this,io); + // String[] pp = { io.toString() }; + // VFSManager.error(view,path,"ioerror.read-error",pp); - /* we don't do this in Buffer.insert() so that - we can insert multiple files at once */ - VFSManager.runInAWTThread(new Runnable() - { - public void run() - { - view.getTextArea().setSelectedText( - seg.toString()); - } - }); - } - catch(IOException io) - { - Log.log(Log.ERROR,this,io); - String[] pp = { io.toString() }; - VFSManager.error(view,path,"ioerror.read-error",pp); + // buffer.setBooleanProperty(ERROR_OCCURRED,true); + // } + // } + // catch(WorkThread.Abort a) + // { + // if(in != null) + // { + // try + // { + // in.close(); + // } + // catch(IOException io) + // { + // } + // } - buffer.setBooleanProperty(ERROR_OCCURRED,true); - } - } - catch(WorkThread.Abort a) - { - if(in != null) - { - try - { - in.close(); - } - catch(IOException io) - { - } - } + // buffer.setBooleanProperty(ERROR_OCCURRED,true); + // } + // finally + // { + // try + // { + // vfs._endVFSSession(session,view); + // } + // catch(IOException io) + // { + // Log.log(Log.ERROR,this,io); + // String[] pp = { io.toString() }; + // VFSManager.error(view,path,"ioerror.read-error",pp); - buffer.setBooleanProperty(ERROR_OCCURRED,true); - } - finally - { - try - { - vfs._endVFSSession(session,view); - } - catch(IOException io) - { - Log.log(Log.ERROR,this,io); - String[] pp = { io.toString() }; - VFSManager.error(view,path,"ioerror.read-error",pp); + // buffer.setBooleanProperty(ERROR_OCCURRED,true); + // } + // catch(WorkThread.Abort a) + // { + // buffer.setBooleanProperty(ERROR_OCCURRED,true); + // } + // } + // } //}}} - buffer.setBooleanProperty(ERROR_OCCURRED,true); - } - catch(WorkThread.Abort a) - { - buffer.setBooleanProperty(ERROR_OCCURRED,true); - } - } - } //}}} - + //{{{ Private static members + private static final int READ_SIZE = 5120; + private static final int WRITE_SIZE = 5120; + private static final int IO_BUFFER_SIZE = 32768; //}}} + + //}}} } Modified: branches/jsxe2/src/net/sourceforge/jsxe/io/FileRootsVFS.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/io/FileRootsVFS.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/io/FileRootsVFS.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -1,5 +1,5 @@ /* -FileVFS.java +FileRootsVFS.java :tabSize=4:indentSize=4:noTabs=true: :folding=explicit:collapseFolds=1: @@ -25,7 +25,7 @@ from http://www.fsf.org/copyleft/gpl.txt */ -package org.gjt.sp.jedit.io; +package net.sourceforge.jsxe.io; //{{{ Imports import javax.swing.filechooser.FileSystemView; Modified: branches/jsxe2/src/net/sourceforge/jsxe/io/FileVFS.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/io/FileVFS.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/io/FileVFS.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -30,6 +30,7 @@ import java.io.*; import java.text.*; import java.util.Date; +import net.sourceforge.jsxe.OperatingSystem; import net.sourceforge.jsxe.util.Log; //}}} @@ -89,10 +90,8 @@ } //}}} //{{{ save() method - public boolean save(View view, Buffer buffer, String path) - { - if(OperatingSystem.isUnix()) - { + public boolean save(TabbedView view, XMLDocument buffer, String path) { + if (OperatingSystem.isUnix()) { int permissions = getPermissions(buffer.getPath()); Log.log(Log.DEBUG,this,buffer.getPath() + " has permissions 0" + Integer.toString(permissions,8)); @@ -103,30 +102,30 @@ } //}}} //{{{ insert() method - public boolean insert(View view, Buffer buffer, String path) - { - File file = new File(path); + // public boolean insert(View view, Buffer buffer, String path) + // { + // File file = new File(path); - //{{{ Check if file is valid - if(!file.exists()) - return false; + // //{{{ Check if file is valid + // if(!file.exists()) + // return false; - if(file.isDirectory()) - { - VFSManager.error(view,file.getPath(), - "ioerror.open-directory",null); - return false; - } + // if(file.isDirectory()) + // { + // VFSManager.error(view,file.getPath(), + // "ioerror.open-directory",null); + // return false; + // } - if(!file.canRead()) - { - VFSManager.error(view,file.getPath(), - "ioerror.no-read",null); - return false; - } //}}} + // if(!file.canRead()) + // { + // VFSManager.error(view,file.getPath(), + // "ioerror.no-read",null); + // return false; + // } //}}} - return super.insert(view,buffer,path); - } //}}} + // return super.insert(view,buffer,path); + // } //}}} //{{{ _canonPath() method /** @@ -323,47 +322,47 @@ return retVal; } //}}} - //{{{ _backup() method - public void _backup(Object session, String path, Component comp) - throws IOException - { - // Fetch properties - int backups = jEdit.getIntegerProperty("backups",1); + // //{{{ _backup() method + // public void _backup(Object session, String path, Component comp) + // throws IOException + // { + // // Fetch properties + // int backups = jsXe.getIntegerProperty("backups",1); - if(backups == 0) - return; + // if(backups == 0) + // return; - String backupPrefix = jEdit.getProperty("backup.prefix"); - String backupSuffix = jEdit.getProperty("backup.suffix"); + // String backupPrefix = jsXe.getProperty("backup.prefix"); + // String backupSuffix = jsXe.getProperty("backup.suffix"); - String backupDirectory = jEdit.getProperty("backup.directory"); + // String backupDirectory = jsXe.getProperty("backup.directory"); - int backupTimeDistance = jEdit.getIntegerProperty("backup.minTime",0); - File file = new File(path); + // int backupTimeDistance = jsXe.getIntegerProperty("backup.minTime",0); + // File file = new File(path); - // Check for backup.directory, and create that - // directory if it doesn't exist - if(backupDirectory == null || backupDirectory.length() == 0) - backupDirectory = file.getParent(); - else - { - backupDirectory = MiscUtilities.constructPath( - System.getProperty("user.home"),backupDirectory); + // // Check for backup.directory, and create that + // // directory if it doesn't exist + // if(backupDirectory == null || backupDirectory.length() == 0) + // backupDirectory = file.getParent(); + // else + // { + // backupDirectory = MiscUtilities.constructPath( + // System.getProperty("user.home"),backupDirectory); - // Perhaps here we would want to guard with - // a property for parallel backups or not. - backupDirectory = MiscUtilities.concatPath( - backupDirectory,file.getParent()); + // // Perhaps here we would want to guard with + // // a property for parallel backups or not. + // backupDirectory = MiscUtilities.concatPath( + // backupDirectory,file.getParent()); - File dir = new File(backupDirectory); + // File dir = new File(backupDirectory); - if (!dir.exists()) - dir.mkdirs(); - } + // if (!dir.exists()) + // dir.mkdirs(); + // } - MiscUtilities.saveBackup(file,backups,backupPrefix, - backupSuffix,backupDirectory,backupTimeDistance); - } //}}} + // MiscUtilities.saveBackup(file,backups,backupPrefix, + // backupSuffix,backupDirectory,backupTimeDistance); + // } //}}} //{{{ _createInputStream() method public InputStream _createInputStream(Object session, String path, @@ -390,7 +389,7 @@ } //}}} //{{{ _saveComplete() method - public void _saveComplete(Object session, Buffer buffer, String path, + public void _saveComplete(Object session, XMLDocument buffer, String path, Component comp) { int permissions = buffer.getIntegerProperty(PERMISSIONS_PROPERTY,0); @@ -410,7 +409,7 @@ public static int getPermissions(String path) { int permissions = 0; - if (jEdit.getBooleanProperty("chmodDisabled")) { + if (jsXe.getBooleanProperty("chmodDisabled")) { return permissions; } @@ -448,7 +447,7 @@ * does nothing. */ public static void setPermissions(String path, int permissions) { - if (jEdit.getBooleanProperty("chmodDisabled")) + if (jsXe.getBooleanProperty("chmodDisabled")) return; if (permissions != 0) { Modified: branches/jsxe2/src/net/sourceforge/jsxe/io/VFS.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/io/VFS.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/io/VFS.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -23,7 +23,7 @@ from http://www.fsf.org/copyleft/gpl.txt */ -package net.sourceforge.jsxe.io.io; +package net.sourceforge.jsxe.io; //{{{ Imports import gnu.regexp.*; @@ -33,6 +33,9 @@ import java.util.*; import net.sourceforge.jsxe.msg.PropertiesChanged; import net.sourceforge.jsxe.util.Log; +import net.sourceforge.jsxe.util.MiscUtilities; +import net.sourceforge.jsxe.dom2.ls.XMLDocumentIORequest; +import net.sourceforge.jsxe.gui.Messages; //}}} /** @@ -345,27 +348,26 @@ * @param buffer The buffer * @param path The path */ - public boolean load(View view, Buffer buffer, String path) - { - if((getCapabilities() & READ_CAP) == 0) - { + public boolean load(TabbedView view, XMLDocument buffer, String path) { + if((getCapabilities() & READ_CAP) == 0) { VFSManager.error(view,path,"vfs.not-supported.load",new String[] { name }); return false; } Object session = createVFSSession(path,view); - if(session == null) + if (session == null) { return false; + } - if((getCapabilities() & WRITE_CAP) == 0) + if ((getCapabilities() & WRITE_CAP) == 0) { buffer.setReadOnly(true); + } - BufferIORequest request = new BufferIORequest( - BufferIORequest.LOAD,view,buffer,session,this,path); - if(buffer.isTemporary()) - // this makes HyperSearch much faster - request.run(); - else + XMLDocumentIORequest request = new XMLDocumentIORequest(XMLDocumentIORequest.LOAD,view,buffer,session,this,path); + // if(buffer.isTemporary()) + // // this makes HyperSearch much faster + // request.run(); + // else VFSManager.runInWorkThread(request); return true; @@ -379,55 +381,54 @@ * @param buffer The buffer * @param path The path */ - public boolean save(View view, Buffer buffer, String path) + public boolean save(TabbedView view, XMLDocument buffer, String path) { - if((getCapabilities() & WRITE_CAP) == 0) - { + if ((getCapabilities() & WRITE_CAP) == 0) { VFSManager.error(view,path,"vfs.not-supported.save",new String[] { name }); return false; } Object session = createVFSSession(path,view); - if(session == null) + if (session == null) { return false; + } /* When doing a 'save as', the path to save to (path) * will not be the same as the buffer's previous path * (buffer.getPath()). In that case, we want to create * a backup of the new path, even if the old path was * backed up as well (BACKED_UP property set) */ - if(!path.equals(buffer.getPath())) - buffer.unsetProperty(Buffer.BACKED_UP); + // if (!path.equals(buffer.getPath())) { + // buffer.unsetProperty(Buffer.BACKED_UP); + // } - VFSManager.runInWorkThread(new BufferIORequest( - BufferIORequest.SAVE,view,buffer,session,this,path)); + VFSManager.runInWorkThread(new XMLDocumentIORequest(XMLDocumentIORequest.SAVE,view,buffer,session,this,path)); return true; } //}}} - //{{{ insert() method - /** - * Inserts a file into the specified buffer. The default implementation - * posts an I/O request to the I/O thread. - * @param view The view - * @param buffer The buffer - * @param path The path - */ - public boolean insert(View view, Buffer buffer, String path) - { - if((getCapabilities() & READ_CAP) == 0) - { - VFSManager.error(view,path,"vfs.not-supported.load",new String[] { name }); - return false; - } + // //{{{ insert() method + // /** + // * Inserts a file into the specified buffer. The default implementation + // * posts an I/O request to the I/O thread. + // * @param view The view + // * @param buffer The buffer + // * @param path The path + // */ + // public boolean insert(View view, Buffer buffer, String path) { + + // if ((getCapabilities() & READ_CAP) == 0) { + // VFSManager.error(view,path,"vfs.not-supported.load",new String[] { name }); + // return false; + // } - Object session = createVFSSession(path,view); - if(session == null) - return false; + // Object session = createVFSSession(path,view); + // if(session == null) + // return false; - VFSManager.runInWorkThread(new BufferIORequest( - BufferIORequest.INSERT,view,buffer,session,this,path)); - return true; - } //}}} + // VFSManager.runInWorkThread(new XMLDocumentIORequest( + // XMLDocumentIORequest.INSERT,view,buffer,session,this,path)); + // return true; + // } //}}} // A method name that starts with _ requires a session object @@ -583,11 +584,11 @@ switch(type) { case FILE: - return jEdit.getProperty("vfs.browser.type.file"); + return Messages.getMessage("vfs.browser.type.file"); case DIRECTORY: - return jEdit.getProperty("vfs.browser.type.directory"); + return Messages.getMessage("vfs.browser.type.directory"); case FILESYSTEM: - return jEdit.getProperty("vfs.browser.type.filesystem"); + return Messages.getMessage("vfs.browser.type.filesystem"); default: throw new IllegalArgumentException(); } @@ -595,15 +596,15 @@ if(name.equals(EA_STATUS)) { if (canRead) { if (canWrite) { - return jEdit.getProperty("vfs.browser.status.rw"); + return Messages.getMessage("vfs.browser.status.rw"); } else { - return jEdit.getProperty("vfs.browser.status.ro"); + return Messages.getMessage("vfs.browser.status.ro"); } } else { if (canWrite) { - return jEdit.getProperty("vfs.browser.status.append"); + return Messages.getMessage("vfs.browser.status.append"); } else { - return jEdit.getProperty("vfs.browser.status.no"); + return Messages.getMessage("vfs.browser.status.no"); } } } else { @@ -620,15 +621,15 @@ } } //}}} - //{{{ getColor() method - public Color getColor() { - if (!colorCalculated) { - colorCalculated = true; - color = getDefaultColorFor(name); - } + // //{{{ getColor() method + // public Color getColor() { + // if (!colorCalculated) { + // colorCalculated = true; + // color = getDefaultColorFor(name); + // } - return color; - } //}}} + // return color; + // } //}}} //{{{ toString() method public String toString() { @@ -742,7 +743,7 @@ * @param comp The component that will parent error dialog boxes * @exception IOException If an I/O error occurs */ - public void _saveComplete(Object session, Buffer buffer, String path, + public void _saveComplete(Object session, XMLDocument buffer, String path, Component comp) throws IOException {} //}}} //{{{ _endVFSSession() method @@ -764,22 +765,22 @@ * Returns color of the specified file name, by matching it against * user-specified regular expressions. */ - public static Color getDefaultColorFor(String name) { - synchronized(lock) { - if (colors == null) { - loadColors(); - } + // public static Color getDefaultColorFor(String name) { + // synchronized(lock) { + // if (colors == null) { + // loadColors(); + // } - for (int i = 0; i < colors.size(); i++) { - ColorEntry entry = (ColorEntry)colors.elementAt(i); - if (entry.re.isMatch(name)) { - return entry.color; - } - } + // for (int i = 0; i < colors.size(); i++) { + // ColorEntry entry = (ColorEntry)colors.elementAt(i); + // if (entry.re.isMatch(name)) { + // return entry.color; + // } + // } - return null; - } - } //}}} + // return null; + // } + // } //}}} //{{{ DirectoryEntryCompare class /** @@ -819,26 +820,21 @@ private String name; private int caps; private String[] extAttrs; - private static Vector colors; + // private static Vector colors; private static Object lock = new Object(); //{{{ Class initializer - static - { - EditBus.addToBus(new EBComponent() - { - public void handleMessage(EBMessage msg) - { - if(msg instanceof PropertiesChanged) - { - synchronized(lock) - { - colors = null; - } - } - } - }); - } //}}} + // static { + // EditBus.addToBus(new EBListener() { + // public void handleMessage(EBMessage msg) { + // if (msg instanceof PropertiesChanged) { + // synchronized(lock) { + // colors = null; + // } + // } + // } + // }); + // } //}}} //{{{ _listDirectory() method private void _listDirectory(Object session, ArrayList stack, @@ -892,38 +888,38 @@ } //}}} //{{{ loadColors() method - private static void loadColors() - { - synchronized(lock) - { - colors = new Vector(); + // private static void loadColors() + // { + // synchronized(lock) + // { + // colors = new Vector(); - if(!jEdit.getBooleanProperty("vfs.browser.colorize")) - return; + // if(!jEdit.getBooleanProperty("vfs.browser.colorize")) + // return; - String glob; - int i = 0; - while((glob = jEdit.getProperty("vfs.browser.colors." + i + ".glob")) != null) - { - try - { - colors.addElement(new ColorEntry( - new RE(MiscUtilities.globToRE(glob)), - jEdit.getColorProperty( - "vfs.browser.colors." + i + ".color", - Color.black))); - } - catch(REException e) - { - Log.log(Log.ERROR,VFS.class,"Invalid regular expression: " - + glob); - Log.log(Log.ERROR,VFS.class,e); - } + // String glob; + // int i = 0; + // while((glob = jEdit.getProperty("vfs.browser.colors." + i + ".glob")) != null) + // { + // try + // { + // colors.addElement(new ColorEntry( + // new RE(MiscUtilities.globToRE(glob)), + // jEdit.getColorProperty( + // "vfs.browser.colors." + i + ".color", + // Color.black))); + // } + // catch(REException e) + // { + // Log.log(Log.ERROR,VFS.class,"Invalid regular expression: " + // + glob); + // Log.log(Log.ERROR,VFS.class,e); + // } - i++; - } - } - } //}}} + // i++; + // } + // } + // } //}}} //{{{ ColorEntry class static class ColorEntry Modified: branches/jsxe2/src/net/sourceforge/jsxe/io/VFSManager.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/io/VFSManager.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/io/VFSManager.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -23,7 +23,7 @@ from http://www.fsf.org/copyleft/gpl.txt */ -package org.gjt.sp.jedit.io; +package net.sourceforge.jsxe.io; //{{{ Imports import javax.swing.JOptionPane; @@ -37,11 +37,10 @@ import java.util.LinkedList; import java.util.List; import java.util.Vector; -import org.gjt.sp.jedit.gui.ErrorListDialog; -import org.gjt.sp.jedit.msg.VFSUpdate; -import org.gjt.sp.jedit.*; -import org.gjt.sp.util.Log; -import org.gjt.sp.util.WorkThreadPool; +import net.sourceforge.jsxe.gui.ErrorListDialog; +import net.sourceforge.jsxe.msg.VFSUpdate; +import net.sourceforge.jsxe.util.Log; +import net.sourceforge.jsxe.WorkThreadPool; //}}} /** Modified: branches/jsxe2/src/net/sourceforge/jsxe/properties =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/properties 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/properties 2006-08-04 19:17:41 UTC (rev 1104) @@ -15,6 +15,12 @@ ioThreadCount=4 +encoding.autodetect=true + +twoStageSave=false + +chmodDisabled=true + #{{{ Plugin Manager Default Dimensions #pluginmgr.x=100 #pluginmgr.y=100 Modified: branches/jsxe2/src/net/sourceforge/jsxe/util/MiscUtilities.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/util/MiscUtilities.java 2006-08-03 19:18:36 UTC (rev 1103) +++ branches/jsxe2/src/net/sourceforge/jsxe/util/MiscUtilities.java 2006-08-04 19:17:41 UTC (rev 1104) @@ -34,7 +34,7 @@ import java.util.*; import javax.swing.JMenuItem; - +import java.text.DecimalFormat; import javax.swing.JPopupMenu; import java.awt.Component; import javax.swing.JComponent; @@ -872,6 +872,28 @@ return s1.equals(s2); } //}}} + //{{{ formatFileSize() method + public static final DecimalFormat KB_FORMAT = new DecimalFormat("#.# KB"); + public static final DecimalFormat MB_FORMAT = new DecimalFormat("#.# MB"); + + /** + * Formats the given file size into a nice string (123 bytes, 10.6 KB, + * 1.2 MB). + * @param length The size + * @since jsXe 0.5 pre3 + */ + public static String formatFileSize(long length) { + if (length < 1024) { + return length + " bytes"; + } else { + if (length < 1024*1024) { + return KB_FORMAT.format((double)length / 1024); + } else { + return MB_FORMAT.format((double)length / 1024 / 1024); + } + } + } //}}} + //}}} //{{{ Sorting methods This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |