net.sf.latexdraw.instruments
Class FileLoaderSaver

java.lang.Object
  extended by org.malai.instrument.Instrument
      extended by org.malai.instrument.WidgetInstrument
          extended by net.sf.latexdraw.instruments.FileLoaderSaver
All Implemented Interfaces:
ActionHandler, Preferenciable, Modifiable, Reinitialisable, UndoHandler

public class FileLoaderSaver
extends WidgetInstrument

This instrument saves and loads documents.

This file is part of LaTeXDraw.
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw 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 (at your option) any later version.
LaTeXDraw is distributed 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.

06/01/2010

Since:
3.0
Author:
Arnaud BLOUIN

Field Summary
protected  java.io.File currentFile
          The current file loaded or saved.
protected  javax.swing.JFileChooser fileChooser
          The fileChooser used to save drawings.
static java.lang.String LABEL_OPEN
          The label of the openMenu item
static java.lang.String LABEL_SAVE
          The label of the saveMenu item
static java.lang.String LABEL_SAVE_AS
          The label of the saveAsMenu item
protected  MButton loadButton
          The button used to load documents.
protected  MMenuItem loadMenu
          The menu used to load documents.
protected  MButton newButton
          The button used to create a new document.
protected  MMenuItem newMenu
          The menu used to create a new document.
protected  java.lang.String pathSave
          The path where documents are saved.
protected  PreferencesSetter prefSetter
          The instrument used to manage preferences.
protected  MProgressBar progressBar
          The progress bar used to show the progress of loading and saving operations.
protected  MMenu recentFilesMenu
          The menu that contains the menu item corresponding to the recent documents.
protected  MMenuItem saveAsMenu
          The menu item used to save as a document.
protected  MButton saveButton
          The button used to save documents.
protected  MMenuItem saveMenu
          The menu used to save documents.
protected  javax.swing.JLabel statusBar
          The field where messages are displayed.
protected  UI ui
          The UI to save/open.
 
Fields inherited from class org.malai.instrument.WidgetInstrument
composer
 
Fields inherited from class org.malai.instrument.Instrument
activated, eventables, links, modified
 
Constructor Summary
FileLoaderSaver(UI ui, javax.swing.JLabel statusBar, PreferencesSetter prefSetter)
          Creates the file loader/saver.
 
Method Summary
 java.io.File getCurrentFile()
           
 javax.swing.JFileChooser getDialog(boolean save)
           
 MButton getLoadButton()
           
 MMenuItem getLoadMenu()
           
 MButton getNewButton()
           
 MMenuItem getNewMenu()
           
 java.lang.String getPathSave()
           
 MProgressBar getProgressBar()
           
 MMenu getRecentFilesMenu()
           
 MMenuItem getSaveAsMenu()
           
 MButton getSaveButton()
           
 MMenuItem getSaveMenu()
           
protected  void initialiseLinks()
          Initialises the links of the instrument.
protected  void initialiseWidgets()
          Initialises the widgets of the instrument.
 void onActionDone(Action action)
          Notifies the handler when the given action is done.
 void onActionExecuted(Action action)
          Notifies the handler when the given action is executed.
 void reinit()
          Reinitialises the object.
 void save(boolean generalPreferences, java.lang.String nsURI, org.w3c.dom.Document document, org.w3c.dom.Element root)
          Saves the parameters of the instrument into an XML tag.
 void setActivated(boolean activated)
          Activates or deactivates the instrument.
 void setActivated(boolean activated, boolean hide)
          Activates or deactivates the instrument.
 void setCurrentFile(java.io.File currentFile)
          Sets the current file loaded or saved.
 void setPathSave(java.lang.String pathSave)
          Sets the path where documents are saved.
 void updateRecentMenuItems(java.util.List<java.lang.String> recentDocs)
          Updates the recent menu items.
 
Methods inherited from class org.malai.instrument.WidgetInstrument
getComposer
 
Methods inherited from class org.malai.instrument.Instrument
addEventable, addLink, clearEvents, getLinks, getSizeLinks, hasLinks, interimFeedback, isActivated, isModified, load, onActionAborted, onActionAdded, onActionCancelled, onUndoableAdded, onUndoableRedo, onUndoableUndo, removeLink, setModified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LABEL_SAVE

public static final java.lang.String LABEL_SAVE
The label of the saveMenu item

See Also:
Constant Field Values

LABEL_SAVE_AS

public static final java.lang.String LABEL_SAVE_AS
The label of the saveAsMenu item

See Also:
Constant Field Values

LABEL_OPEN

public static final java.lang.String LABEL_OPEN
The label of the openMenu item

See Also:
Constant Field Values

pathSave

protected java.lang.String pathSave
The path where documents are saved.


currentFile

protected java.io.File currentFile
The current file loaded or saved.


saveButton

protected MButton saveButton
The button used to save documents.


loadButton

protected MButton loadButton
The button used to load documents.


newButton

protected MButton newButton
The button used to create a new document.


saveAsMenu

protected MMenuItem saveAsMenu
The menu item used to save as a document.


saveMenu

protected MMenuItem saveMenu
The menu used to save documents.


loadMenu

protected MMenuItem loadMenu
The menu used to load documents.


newMenu

protected MMenuItem newMenu
The menu used to create a new document.


recentFilesMenu

protected MMenu recentFilesMenu
The menu that contains the menu item corresponding to the recent documents.


fileChooser

protected javax.swing.JFileChooser fileChooser
The fileChooser used to save drawings.


ui

protected UI ui
The UI to save/open.


statusBar

protected javax.swing.JLabel statusBar
The field where messages are displayed.


prefSetter

protected PreferencesSetter prefSetter
The instrument used to manage preferences.


progressBar

protected MProgressBar progressBar
The progress bar used to show the progress of loading and saving operations.

Constructor Detail

FileLoaderSaver

public FileLoaderSaver(UI ui,
                       javax.swing.JLabel statusBar,
                       PreferencesSetter prefSetter)
Creates the file loader/saver.

Parameters:
ui - The user interface that contains the presentations and the instruments to save/load.
statusBar - The status bar where messages are displayed.
prefSetter - The instrument used to manage preferences.
Throws:
java.lang.IllegalArgumentException - If one of the given parameters is null.
java.lang.NullPointerException - If the given UI is null.
Since:
3.0
Method Detail

reinit

public void reinit()
Description copied from interface: Reinitialisable
Reinitialises the object.

Specified by:
reinit in interface Reinitialisable
Overrides:
reinit in class Instrument

onActionDone

public void onActionDone(Action action)
Description copied from interface: ActionHandler
Notifies the handler when the given action is done.

Specified by:
onActionDone in interface ActionHandler
Overrides:
onActionDone in class Instrument
Parameters:
action - The action that ends.

setActivated

public void setActivated(boolean activated,
                         boolean hide)
Description copied from class: WidgetInstrument
Activates or deactivates the instrument. This operation is related to Instrument.setActivated(boolean) but the difference is that is this opedeactivateration another parameter can be used to define is the widgets of the instrument must be hidden: in some cases, deactivating the instrument just implies disabling its widgets (but they are still visible); in some others cases, deactivating the instrument means hiding the widgets. Should be overridden to define the process of hiding the widgets.

Overrides:
setActivated in class WidgetInstrument
Parameters:
activated - True = activation.
hide - If true the widgets will be hidden. Only while deactivating the instrument.

setActivated

public void setActivated(boolean activated)
Description copied from class: Instrument
Activates or deactivates the instrument.

Overrides:
setActivated in class Instrument
Parameters:
activated - True = activation.

initialiseWidgets

protected void initialiseWidgets()
Description copied from class: WidgetInstrument
Initialises the widgets of the instrument.

Specified by:
initialiseWidgets in class WidgetInstrument

initialiseLinks

protected void initialiseLinks()
Description copied from class: Instrument
Initialises the links of the instrument.

Specified by:
initialiseLinks in class Instrument

getPathSave

public java.lang.String getPathSave()
Returns:
The path where documents are saved.
Since:
3.0

setPathSave

public void setPathSave(java.lang.String pathSave)
Sets the path where documents are saved.

Parameters:
pathSave - The path where documents are saved.
Since:
3.0

getCurrentFile

public java.io.File getCurrentFile()
Returns:
The current file loaded or saved.
Since:
3.0

setCurrentFile

public void setCurrentFile(java.io.File currentFile)
Sets the current file loaded or saved.

Parameters:
currentFile - The current file loaded or saved.
Since:
3.0

getSaveButton

public MButton getSaveButton()
Returns:
The button used to save documents.
Since:
3.0

getLoadButton

public MButton getLoadButton()
Returns:
The button used to load documents.
Since:
3.0

getRecentFilesMenu

public MMenu getRecentFilesMenu()
Returns:
The menu that permits to load recent documents.
Since:
3.0

getProgressBar

public MProgressBar getProgressBar()
Returns:
The progress bar used to show the progress of the loading and saving operations.
Since:
3.0

updateRecentMenuItems

public void updateRecentMenuItems(java.util.List<java.lang.String> recentDocs)
Updates the recent menu items.

Parameters:
recentDocs - The list of recent documents.
Since:
3.0

getDialog

public javax.swing.JFileChooser getDialog(boolean save)
Parameters:
save - True: the dialogue box will be configured for saving prupose. Otherwose, for opening purpose.
Returns:
The dialogue box to open or save drawings.
Since:
3.0

save

public void save(boolean generalPreferences,
                 java.lang.String nsURI,
                 org.w3c.dom.Document document,
                 org.w3c.dom.Element root)
Description copied from interface: Preferenciable
Saves the parameters of the instrument into an XML tag.

Specified by:
save in interface Preferenciable
Overrides:
save in class Instrument
Parameters:
generalPreferences - True: this operation is called to save the general preferences of the interactive system. Otherwise, it is called to save a presentation in a document. This parameter is useful when different information must be saved during a presentation backup or a general preferences backup.
nsURI - The namespace that must be added to tags corresponding to the instrument's parameters.
document - The XML document.
root - The root element that will contains the instrument's parameters.

onActionExecuted

public void onActionExecuted(Action action)
Description copied from interface: ActionHandler
Notifies the handler when the given action is executed.

Specified by:
onActionExecuted in interface ActionHandler
Overrides:
onActionExecuted in class Instrument
Parameters:
action - The executed action.

getSaveAsMenu

public MMenuItem getSaveAsMenu()
Returns:
The menu item used to save as a document.
Since:
3.0

getSaveMenu

public MMenuItem getSaveMenu()
Returns:
The menu item used to save a document.
Since:
3.0

getLoadMenu

public MMenuItem getLoadMenu()
Returns:
The menu item used to load a document.
Since:
3.0

getNewButton

public MButton getNewButton()
Returns:
The button used to create a new document.

getNewMenu

public MMenuItem getNewMenu()
Returns:
The menu used to create a new document.