org.nuiton.widget
Class SwingSession

java.lang.Object
  extended by org.nuiton.widget.SwingSession

public class SwingSession
extends Object

Use to store and restore position and size of application. Supported widgets are:

  • java.awt.Window (and subclasses)
  • javax.swing.JTabbedPane (and subclasses)
  • javax.swing.JSplitPane (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.

    Version:
    $Revision: 300 $ Last update: $Date: 2010-11-17 22:35:44 +0100 (mer., 17 nov. 2010) $ by : $Author: sletellier $
    Author:
    poussin

    Nested Class Summary
    static interface SwingSession.Action
               
    static class SwingSession.JSplitPaneState
              State for JSplit FIXME add listener for divider move action
    static class SwingSession.JTabbedPaneState
              State for JTabbedPane
    static class SwingSession.JTableState
              State for JTable.
    static class SwingSession.RestoreStateAction
               
    static class SwingSession.SaveStateAction
               
    static interface SwingSession.State
              get(save) and set(restore) state of object passed in argument
    static class SwingSession.WindowState
              State for Window
     
    Field Summary
    protected  boolean autoSave
               
    protected  File file
               
    protected  LinkedHashSet<Component> registeredComponent
               
    protected  Map<Class,SwingSession.State> stateManager
              State object registered to get and set State.
    protected  Map<String,SwingSession.State> states
              state of all component added with add method.
     
    Constructor Summary
    SwingSession(File file, boolean autoSave)
               
     
    Method Summary
     void add(Component c)
               
    protected  void finalize()
               
    protected  String getComponentName(Component c)
               
     SwingSession.State getStateManager(Class clazz)
               
     SwingSession.State getStates(String path)
               
     Map<String,SwingSession.State> loadStates(File file)
              Loads the states from the file
    static void main(String[] args)
              Just for test rapidly
     void remove(Component c)
              Remove component from component to save
     void save()
               
     void setStates(String path, SwingSession.State state)
               
     void updateState()
               
    protected  void walkThrowComponent(String path, Collection<Component> roots, SwingSession.Action action)
               
     
    Methods inherited from class java.lang.Object
    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    file

    protected File file

    autoSave

    protected boolean autoSave

    registeredComponent

    protected LinkedHashSet<Component> registeredComponent

    stateManager

    protected Map<Class,SwingSession.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,SwingSession.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)
    Method Detail

    finalize

    protected void finalize()
                     throws Throwable
    Overrides:
    finalize in class Object
    Throws:
    Throwable

    save

    public void save()

    loadStates

    public Map<String,SwingSession.State> loadStates(File file)
    Loads the states from the file


    updateState

    public void updateState()

    add

    public void add(Component c)

    remove

    public void remove(Component c)
    Remove component from component to save

    Parameters:
    c -

    getComponentName

    protected String getComponentName(Component c)

    getStateManager

    public SwingSession.State getStateManager(Class clazz)

    getStates

    public SwingSession.State getStates(String path)

    setStates

    public void setStates(String path,
                          SwingSession.State state)

    walkThrowComponent

    protected void walkThrowComponent(String path,
                                      Collection<Component> roots,
                                      SwingSession.Action action)

    main

    public static void main(String[] args)
    Just for test rapidly

    Parameters:
    args -


    Copyright © 2004-2011 CodeLutin. All Rights Reserved.