Class SwingSession


  • public class SwingSession
    extends 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
    • Field Detail

      • file

        protected File file
      • autoSave

        protected final boolean autoSave
      • registeredComponent

        protected final Set<Component> registeredComponent
      • stateManager

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

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

      • SwingSession

        public SwingSession​(File file,
                            boolean autoSave)
      • SwingSession

        public SwingSession​(File file,
                            boolean autoSave,
                            Map<Class,​State> additionalStates)
    • Method Detail

      • newSession

        @Deprecated
        public static SwingSession newSession​(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​(File file,
                                              boolean autoSave,
                                              Map<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 File getFile()
      • setFile

        public void setFile​(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
      • updateState

        public void updateState()
      • add

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

        public void remove​(Component c)
        Remove component from component to save
        Parameters:
        c -
      • getStateManager

        public State getStateManager​(Class clazz)
      • addToStateManager

        public void addToStateManager​(Class component,
                                      State state)
      • setStates

        public void setStates​(String path,
                              State state)