adalogo.gui.editor

Class FileHandler

Implemented Interfaces:
DocumentListener
Known Direct Subclasses:
AdaLogoFileHandler

public abstract class FileHandler
extends java.lang.Object
implements DocumentListener

file handler. this class provides actions and methods to save and load files to a textpane.

Nested Class Summary

protected static interface
FileHandler.FileChooser

Field Summary

protected File
currentFile
the currently loaded file.
protected boolean
currentFileChanged
true if the document is changed after last save.
protected Date
currentFileDate
the date of the current file loaded.
protected String
currentFileName
the filename of the currently loaded file.
protected boolean
dontCheckFileOnDisk
if this is true no check file on disk will be done.
protected boolean
dontFireChange
if this is true no change event will be fired.
Action
newAction
Action
openAction
Action
revertAction
Action
saveAction
Action
saveAsAction

Constructor Summary

FileHandler(JTextPane textPane)
constructor

Method Summary

void
addFileHandlerListener(FileHandler.FileHandlerListener listener)
void
changedUpdate(DocumentEvent e)
void
checkFileOnDisk()
this will check the currently loaded file against the file on disk, and warn the user if file on disk has changed.
protected void
errorCannotCreateFile(String name)
protected void
errorCannotReadFromFile(String name)
protected void
errorCannotWriteToFile(String name)
protected void
errorFileDoesNotExist(String name)
protected FileHandler.FileChooser
getFileChooser()
protected File
getNewDocumentFile()
protected InputStream
getNewDocumentStream()
void
insertUpdate(DocumentEvent e)
void
newDocument()
load a new document in the text component.
protected boolean
okToLoadNewDocument()
protected boolean
okToOpenDocument()
protected boolean
okToOverwriteFile(String name)
protected boolean
okToReloadFileFromDisk(String name)
protected boolean
okToRevertDocument(String name)
void
openDocument()
let user open a new document.
void
openDocument(File file)
this method might never be called, but it is here anyway
void
openDocument(InputStream in, String name)
this method is called to load examples from the jar as stream
void
removeUpdate(DocumentEvent e)
void
revertDocument()
revert the current loaded file with the file on disk.
void
saveAsDocument()
let user save document to file.
void
saveAsDocument(File file)
this method might never be called, but it is here anyway
void
saveAsDocument(OutputStream out, String name)
this method might never be called, but it is here anyway
void
saveDocument()
save the current loaded file.

Field Details

currentFile

protected File currentFile
the currently loaded file. this will be null if load from stream.


currentFileChanged

protected boolean currentFileChanged
true if the document is changed after last save.


currentFileDate

protected Date currentFileDate
the date of the current file loaded. this will be used to check the loaded file against the file on disk.


currentFileName

protected String currentFileName
the filename of the currently loaded file. this will always have a value even if load from stream.


dontCheckFileOnDisk

protected boolean dontCheckFileOnDisk
if this is true no check file on disk will be done. this is dirty hack to prevent check file on disk to occur on less favourable events (for example when save/load dialog is open).


dontFireChange

protected boolean dontFireChange
if this is true no change event will be fired. cheap hack to prevent title updating during save load operation.


newAction

public Action newAction


openAction

public Action openAction


revertAction

public Action revertAction


saveAction

public Action saveAction


saveAsAction

public Action saveAsAction

Constructor Details

FileHandler

public FileHandler(JTextPane textPane)
constructor

Method Details

addFileHandlerListener

public void addFileHandlerListener(FileHandler.FileHandlerListener listener)


changedUpdate

public void changedUpdate(DocumentEvent e)


checkFileOnDisk

public void checkFileOnDisk()
this will check the currently loaded file against the file on disk, and warn the user if file on disk has changed. this will be called from the timer started in constructor.


errorCannotCreateFile

protected void errorCannotCreateFile(String name)


errorCannotReadFromFile

protected void errorCannotReadFromFile(String name)


errorCannotWriteToFile

protected void errorCannotWriteToFile(String name)


errorFileDoesNotExist

protected void errorFileDoesNotExist(String name)


getFileChooser

protected FileHandler.FileChooser getFileChooser()


getNewDocumentFile

protected File getNewDocumentFile()


getNewDocumentStream

protected InputStream getNewDocumentStream()


insertUpdate

public void insertUpdate(DocumentEvent e)


newDocument

public void newDocument()
load a new document in the text component.

See Also:
getNewDocumentFile(), getNewDocumentStream()


okToLoadNewDocument

protected boolean okToLoadNewDocument()


okToOpenDocument

protected boolean okToOpenDocument()


okToOverwriteFile

protected boolean okToOverwriteFile(String name)


okToReloadFileFromDisk

protected boolean okToReloadFileFromDisk(String name)


okToRevertDocument

protected boolean okToRevertDocument(String name)


openDocument

public void openDocument()
let user open a new document. called from action.

See Also:
okToOpenDocument(), getFileChooser(), FileHandler.FileChooser, errorFileDoesNotExist(String), errorCannotReadFromFile(String), loadFromFile(File)


openDocument

public void openDocument(File file)
this method might never be called, but it is here anyway


openDocument

public void openDocument(InputStream in,
                         String name)
this method is called to load examples from the jar as stream


removeUpdate

public void removeUpdate(DocumentEvent e)


revertDocument

public void revertDocument()
revert the current loaded file with the file on disk.


saveAsDocument

public void saveAsDocument()
let user save document to file. called from action.

See Also:
getFileChooser(), FileHandler.FileChooser, okToOverwriteFile(String), errorCannotCreateFile(String), errorCannotWriteToFile(String), saveToFile(File)


saveAsDocument

public void saveAsDocument(File file)
this method might never be called, but it is here anyway


saveAsDocument

public void saveAsDocument(OutputStream out,
                           String name)
this method might never be called, but it is here anyway


saveDocument

public void saveDocument()
save the current loaded file.