Class SwingSession

java.lang.Object
jaxx.runtime.swing.session.SwingSession

public class SwingSession
extends java.lang.Object
Use to store and restore position and size of application. Default supported widgets are:
  • java.awt.Window (and subclasses)
  • javax.swing.JTabbedPane (and subclasses)
  • javax.swing.JSplitPane (and subclasses)
  • org.jdesktop.swingx.JXTable (and subclasses)
  • javax.swing.JTable (and subclasses)
usage:
  • create SwingSession object
  • add component that you want save
  • explicite call to save
You can use same SwingSession for multiple window but in this case you must have setName for each window with different name, otherwize there are collision between window component and result is undetermisitic. This code is partialy inspired from http://kenai.com/projects/bsaf/pages/Home project. This project is under LGPL v2.1 license. We can't reuse directly this library because to many fields and methods are private and we can't implements it and modify some behavior.
Since:
2.5.16
Author:
poussin, kmorin
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static interface  SwingSession.Action  
    static class  SwingSession.RestoreStateAction  
    static class  SwingSession.SaveStateAction  
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected boolean autoSave  
    protected java.io.File file  
    protected java.util.Set<java.awt.Component> registeredComponent  
    protected java.util.Map<java.lang.Class,​State> stateManager
    State object registered to get and set State.
    protected java.util.Map<java.lang.String,​State> states
    state of all component added with add method.
  • Constructor Summary

    Constructors
    Constructor Description
    SwingSession​(java.io.File file, boolean autoSave)  
    SwingSession​(java.io.File file, boolean autoSave, java.util.Map<java.lang.Class,​State> additionalStates)  
  • Method Summary

    Modifier and Type Method Description
    void add​(java.awt.Component c)  
    void add​(java.awt.Component c, boolean replace)  
    void addToStateManager​(java.lang.Class component, State state)  
    protected void finalize()  
    protected java.lang.String getComponentName​(java.awt.Component c)  
    java.io.File getFile()  
    State getStateManager​(java.lang.Class clazz)  
    State getStates​(java.lang.String path)  
    void loadSafeStates()
    Loads safely the states from the file.
    java.util.Map<java.lang.String,​State> loadStates​(java.io.File file)
    Loads the states from the file
    static SwingSession newSession​(java.io.File file, boolean autoSave)
    Deprecated.
    since 2.10, the default behaviour is now to safely load the incoming file
    static SwingSession newSession​(java.io.File file, boolean autoSave, java.util.Map<java.lang.Class,​State> additionalStates)
    Deprecated.
    since 2.10, the default behaviour is now to safely load the incoming file
    void remove​(java.awt.Component c)
    Remove component from component to save
    void save()  
    void setFile​(java.io.File file)  
    void setStates​(java.lang.String path, State state)  
    void updateState()  
    protected void walkThroughComponent​(java.lang.String path, java.util.Collection<java.awt.Component> roots, SwingSession.Action action)  

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • file

      protected java.io.File file
    • autoSave

      protected boolean autoSave
    • registeredComponent

      protected java.util.Set<java.awt.Component> registeredComponent
    • stateManager

      protected java.util.Map<java.lang.Class,​State> stateManager
      State object registered to get and set State. key: class of component managed by the state; value: the state
    • states

      protected java.util.Map<java.lang.String,​State> states
      state of all component added with add method. key: path of compoenent; value: State
  • Constructor Details

    • SwingSession

      public SwingSession​(java.io.File file, boolean autoSave)
    • SwingSession

      public SwingSession​(java.io.File file, boolean autoSave, java.util.Map<java.lang.Class,​State> additionalStates)
  • Method Details

    • newSession

      @Deprecated public static SwingSession newSession​(java.io.File file, boolean autoSave)
      Deprecated.
      since 2.10, the default behaviour is now to safely load the incoming file
      Create a new swing session with the given parameters. If it fails to read the given file, then it will delete it from the fs and starts with a new empty file.
      Returns:
      the new swing session
      Since:
      2.8.6
    • newSession

      @Deprecated public static SwingSession newSession​(java.io.File file, boolean autoSave, java.util.Map<java.lang.Class,​State> additionalStates)
      Deprecated.
      since 2.10, the default behaviour is now to safely load the incoming file
      Create a new swing session with the given parameters. If it fails to read the given file, then it will delete it from the fs and starts with a new empty file.
      Returns:
      the new swing session
      Since:
      2.8.6
    • getFile

      public java.io.File getFile()
    • setFile

      public void setFile​(java.io.File file)
    • loadSafeStates

      public void loadSafeStates()
      Loads safely the states from the file. If could not read the internal file, then will try to delete it.
      Since:
      2.10
    • finalize

      protected void finalize() throws java.lang.Throwable
      Overrides:
      finalize in class java.lang.Object
      Throws:
      java.lang.Throwable
    • save

      public void save() throws java.io.IOException
      Throws:
      java.io.IOException
    • loadStates

      public java.util.Map<java.lang.String,​State> loadStates​(java.io.File file) throws java.io.IOException
      Loads the states from the file
      Throws:
      java.io.IOException
    • updateState

      public void updateState()
    • add

      public void add​(java.awt.Component c)
    • add

      public void add​(java.awt.Component c, boolean replace)
    • remove

      public void remove​(java.awt.Component c)
      Remove component from component to save
      Parameters:
      c -
    • getComponentName

      protected java.lang.String getComponentName​(java.awt.Component c)
    • getStateManager

      public State getStateManager​(java.lang.Class clazz)
    • addToStateManager

      public void addToStateManager​(java.lang.Class component, State state)
    • getStates

      public State getStates​(java.lang.String path)
    • setStates

      public void setStates​(java.lang.String path, State state)
    • walkThroughComponent

      protected void walkThroughComponent​(java.lang.String path, java.util.Collection<java.awt.Component> roots, SwingSession.Action action)