Class BeanBinder


  • public class BeanBinder
    extends java.lang.Object
    Utility class for synchronizing a Swing GUI with JavaBean properties. Also synchronizes a bean with a property file or command line parameters. Synchronization is performed when calling getProperties() and setProperties(). Matching is done where the name of a property corresponds to the name of a GUI element.
    Copyright (c) 2005, David Ekholm Datadosen
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  BeanBinder.Bindeable
      Support for other component types
    • Constructor Summary

      Constructors 
      Constructor Description
      BeanBinder()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addBinderListener​(BinderListener listener)  
      void addUI​(java.awt.Container ui)
      Add user interface to participate in readModel and writeModel calls
      void addUI​(java.awt.Container... newUIs)
      Add user interface to participate in readModel and writeModel calls
      static java.lang.Object cloneProperties​(java.lang.Object fromBean, java.lang.Object toBean)  
      static void debug​(java.lang.Object bean, java.lang.Object jComponentHolder)  
      protected void fireModelRead()  
      protected void fireWriteModel()  
      static java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.Object bean)
      Return an unprocessed String to Object Map of this bean Static methods are ignored
      static java.util.Properties getProperties​(java.lang.Object bean)
      Return a java.util.Property object representing the state of a JavaBean
      static java.util.Properties getProperties​(java.lang.Object bean, boolean nullProperties)
      Return a java.util.Property object representing the state of a JavaBean
      static void getProperties​(java.lang.Object bean, java.awt.Container jComponentHolder)
      Update a Swing GUI with the properties from a JavaBean.
      static void getProperties​(java.lang.Object bean, java.util.List<java.awt.Container> holders)  
      static java.util.Properties getProperties​(java.lang.Object bean, java.util.Properties existing)
      Return a java.util.Property object representing the state of a JavaBean
      static boolean isSynchingUI()
      Return true if we're currently synching a UI from a bean on the same thread as calling thread (see getProperties(Object bean, Object jComponentHolder)
      static java.util.Properties parseArgsOptions​(java.lang.String[] args)
      Utility method to generate a Property object from command line parameters
      void readModel​(java.lang.Object bean)
      Like getProperties, but non static (uses user interface array from constructor) and fires modelRead to listeners
      void removeBinderListener​(BinderListener listener)  
      void removeUI​(java.lang.Object ui)
      Remove user interface from participating in readModel and writeModel calls
      static void setProperties​(java.lang.Object bean, java.awt.Container jComponentHolder)
      Update a JavaBean from a Swing GUI.
      static void setProperties​(java.lang.Object bean, java.util.List<java.awt.Container> uis)
      Update a JavaBean from a Swing GUI.
      static void setProperties​(java.lang.Object bean, java.util.Map props)
      Set JavaBean properties given a Map object
      void writeModel​(java.lang.Object bean)
      Like setProperties, but non static (uses user interface array from constructor) and fires writeModel to listeners
      • Methods inherited from class java.lang.Object

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

      • BeanBinder

        public BeanBinder()
    • Method Detail

      • addBinderListener

        public void addBinderListener​(BinderListener listener)
      • removeBinderListener

        public void removeBinderListener​(BinderListener listener)
      • addUI

        public void addUI​(java.awt.Container... newUIs)
        Add user interface to participate in readModel and writeModel calls
        Since:
        13.1
      • addUI

        public void addUI​(java.awt.Container ui)
        Add user interface to participate in readModel and writeModel calls
        Parameters:
        ui -
        Since:
        13.1
      • removeUI

        public void removeUI​(java.lang.Object ui)
        Remove user interface from participating in readModel and writeModel calls
        Parameters:
        ui -
        Since:
        13.1
      • fireWriteModel

        protected void fireWriteModel()
      • fireModelRead

        protected void fireModelRead()
      • debug

        public static void debug​(java.lang.Object bean,
                                 java.lang.Object jComponentHolder)
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getProperties

        public static void getProperties​(java.lang.Object bean,
                                         java.util.List<java.awt.Container> holders)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • readModel

        public void readModel​(java.lang.Object bean)
                       throws java.lang.Exception
        Like getProperties, but non static (uses user interface array from constructor) and fires modelRead to listeners
        Parameters:
        bean -
        Throws:
        java.lang.Exception
      • writeModel

        public void writeModel​(java.lang.Object bean)
        Like setProperties, but non static (uses user interface array from constructor) and fires writeModel to listeners
        Parameters:
        bean -
      • getProperties

        public static void getProperties​(java.lang.Object bean,
                                         java.awt.Container jComponentHolder)
        Update a Swing GUI with the properties from a JavaBean. Currently supports the following types of GUI elements:
        • JTextField
        • JComboBox
        • JCheckBox
        • ButtonGroup (radio buttons)
        Parameters:
        bean - JavaBean to read properties from
        jComponentHolder - object with GUI elements (public instances of JComponent objects)
    • isSynchingUI

      public static boolean isSynchingUI()
      Return true if we're currently synching a UI from a bean on the same thread as calling thread (see getProperties(Object bean, Object jComponentHolder)
    • cloneProperties

      public static java.lang.Object cloneProperties​(java.lang.Object fromBean,
                                                     java.lang.Object toBean)
                                              throws BeanBinderException
      Returns:
      toBean
      Throws:
      BeanBinderException
      Since:
      v12
    • getProperties

      public static java.util.Properties getProperties​(java.lang.Object bean)
                                                throws java.lang.Exception
      Return a java.util.Property object representing the state of a JavaBean
      Throws:
      java.lang.Exception
    • getMap

      public static java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.Object bean)
                                                                           throws BeanBinderException
      Return an unprocessed String to Object Map of this bean Static methods are ignored
      Parameters:
      bean -
      Returns:
      Throws:
      BeanBinderException
      Since:
      15.2.3
    • getProperties

      public static java.util.Properties getProperties​(java.lang.Object bean,
                                                       java.util.Properties existing)
                                                throws java.lang.Exception
      Return a java.util.Property object representing the state of a JavaBean
      Parameters:
      bean - JavaBean to read properties from
      existing - Existing properties object to add properties to
      Throws:
      java.lang.Exception
    • getProperties

      public static java.util.Properties getProperties​(java.lang.Object bean,
                                                       boolean nullProperties)
                                                throws java.lang.Exception
      Return a java.util.Property object representing the state of a JavaBean
      Parameters:
      bean - JavaBean to read properties from
      nullProperties - if null-value properties are to be included
      Throws:
      java.lang.Exception
    • setProperties

      public static void setProperties​(java.lang.Object bean,
                                       java.util.Map props)
                                throws BeanBinderException
      Set JavaBean properties given a Map object
      Throws:
      BeanBinderException
    • setProperties

      public static void setProperties​(java.lang.Object bean,
                                       java.util.List<java.awt.Container> uis)
      Update a JavaBean from a Swing GUI. See getProperties() for a list of supported GUI elements.
      Parameters:
      bean - JavaBean to set properties on
      uis - objects with GUI elements (public instances of JComponent objects)
    • setProperties

      public static void setProperties​(java.lang.Object bean,
                                       java.awt.Container jComponentHolder)
                                throws BeanBinderException
      Update a JavaBean from a Swing GUI. See getProperties() for a list of supported GUI elements.
      Parameters:
      bean - JavaBean to set properties on
      jComponentHolder - object with GUI elements (public instances of JComponent objects)
      Throws:
      BeanBinderException
    • parseArgsOptions

      public static java.util.Properties parseArgsOptions​(java.lang.String[] args)
      Utility method to generate a Property object from command line parameters