Class MapBinder

java.lang.Object
se.datadosen.util.MapBinder

public class MapBinder
extends java.lang.Object
Utility class for synchronizing a Swing GUI with a Map object. Synchronization is performed when calling getMap() and syncUI(). Matching is done where the name of a map key corresponds to the name of a GUI element. Currently handles JText components, JCheckBox, JComboBox and JColorSelector
This is a successor to PropertyBinder that keeps the datatypes of component values instead of converting all to strings like PropertyBinder does Copyright (c) 2003, David Ekholm Datadosen
Since:
8.8.1
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  MapBinder.ComponentBinder
    Add support for other component types
  • Constructor Summary

    Constructors 
    Constructor Description
    MapBinder()  
  • Method Summary

    Modifier and Type Method Description
    static java.util.Map<java.lang.String,​java.lang.Object> getMap​(JComponentHolder jComponentHolder)
    Read properties from a UI.
    static java.util.Map<java.lang.String,​java.lang.Object> getMap​(JComponentHolder jComponentHolder, java.util.Map<java.lang.String,​java.lang.Object> existing)
    Read properties from a UI.
    static MapBinder.ComponentBinder registerComponentBinder​(java.lang.Class componentClass, MapBinder.ComponentBinder binder)
    Add support for other component types (subclasses of JComponent)
    static void syncUI​(java.util.Map<java.lang.String,​java.lang.Object> props, JComponentHolder jComponentHolder)
    Update a UI from a Map object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getMap

      public static java.util.Map<java.lang.String,​java.lang.Object> getMap​(JComponentHolder jComponentHolder)
      Read properties from a UI.
      Parameters:
      jComponentHolder - object containing Swing type member variables/components
      Returns:
      A property object where the keys have the same names as the member components
    • getMap

      public static java.util.Map<java.lang.String,​java.lang.Object> getMap​(JComponentHolder jComponentHolder, java.util.Map<java.lang.String,​java.lang.Object> existing)
      Read properties from a UI.
      Parameters:
      jComponentHolder - object containing Swing type member variables/components
      existing - Properties object to add properties to
      Returns:
      A property object where the keys have the same names as the member components
      Throws:
      java.lang.RuntimeException
    • syncUI

      public static void syncUI​(java.util.Map<java.lang.String,​java.lang.Object> props, JComponentHolder jComponentHolder)
      Update a UI from a Map object.
      Parameters:
      props - Properties to pass to UI
      jComponentHolder - object containing Swing type member variables/components to be synchronized.
      Throws:
      java.lang.RuntimeException
    • registerComponentBinder

      public static MapBinder.ComponentBinder registerComponentBinder​(java.lang.Class componentClass, MapBinder.ComponentBinder binder)
      Add support for other component types (subclasses of JComponent)
      Parameters:
      componentClass -
      binder -
      Returns:
      Since:
      8.4