Package examples
Class LocalStorageExample1
- java.lang.Object
-
- org.jdesktop.application.AbstractBean
-
- org.jdesktop.application.Application
-
- examples.LocalStorageExample1
-
public class LocalStorageExample1 extends Application
A simple demonstration of theLocalStorage
class: loads and saves aLinkedHashMap
(aHashMap
whose entries have a stable order). To try it, add some entries to the Map by pressing the "Add Random Entry" button or by entering key/value strings in the corresponding text fields. Then save the Map (to a file), clear, and load the saved Map. with the corresponding buttons.The map is saved with the
LocalStorage
save
method like this:LinkedHashMap<String, String> map = listModel.getMap(); ApplicationContext.getInstance().getLocalStorage().save(map, "map.xml");
And loaded with theLocalStorage
load
method like this:Object map = ApplicationContext.getInstance().getLocalStorage().load("map.xml"); listModel.setMap((LinkedHashMap<String, String>)map);
TheLocalStorage.save/load
methods can be applied to anything supported by Java Beans Persistence, i.e. any Java Bean as well as most of the primitive and utility Java classes. TheLocalStorage.save
method is implemented with theXMLEncoder
class and theLocalStorage.load
method with theXMLDecoder
class. Take a look at the contents of"map.xml"
by cut and pasting the complete pathname from the bottom of the GUI into your favorite text editor.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jdesktop.application.Application
Application.ExitListener
-
-
Constructor Summary
Constructors Constructor Description LocalStorageExample1()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addKeyValueEntry()
void
addRandomEntry()
void
clearMap()
void
loadMap()
static void
main(java.lang.String[] args)
void
saveMap()
protected void
startup()
Responsible for starting the application; for creating and showing the initial GUI.-
Methods inherited from class org.jdesktop.application.Application
addExitListener, end, exit, exit, getContext, getExitListeners, getInstance, getInstance, hide, initialize, launch, quit, ready, removeExitListener, show, shutdown
-
Methods inherited from class org.jdesktop.application.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Method Detail
-
addKeyValueEntry
@Action public void addKeyValueEntry()
-
addRandomEntry
@Action public void addRandomEntry()
-
clearMap
@Action public void clearMap()
-
loadMap
@Action public void loadMap() throws java.io.IOException
- Throws:
java.io.IOException
-
saveMap
@Action public void saveMap() throws java.io.IOException
- Throws:
java.io.IOException
-
startup
protected void startup()
Description copied from class:Application
Responsible for starting the application; for creating and showing the initial GUI.This method is called by the static
launch
method, subclasses must override it. It runs on the event dispatching thread.- Specified by:
startup
in classApplication
- See Also:
Application.launch(java.lang.Class<T>, java.lang.String[])
,Application.initialize(java.lang.String[])
,Application.shutdown()
-
main
public static void main(java.lang.String[] args)
-
-