Class Listen


  • public class Listen
    extends java.lang.Object
    Utility class to adapt classic swing listener patterns to a more Java-8 style of code.
    • Constructor Summary

      Constructors 
      Constructor Description
      Listen()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void toAction​(javax.swing.AbstractButton button, java.lang.Runnable r)  
      static void toAction​(javax.swing.JTextField field, java.lang.Runnable r)  
      static <T> void toCombobox​(javax.swing.JComboBox<T> combobox, java.util.function.Consumer<T> listener)  
      static Listen.PopupMenuAdapter toComboboxPopup​(javax.swing.JComboBox<?> menu)  
      static void toDisplayable​(javax.swing.JComponent component, java.util.function.Consumer<java.lang.Boolean> onChange)
      Listens to when a component is added into or removed from the component hierarchy, changing it's displayable flag.
      static void toDocumentChange​(javax.swing.text.Document document, java.util.function.Consumer<java.lang.String> onChange)
      Will be called any time a document changes, and will deliver the new text of the document to the provided listener
      static void toDocumentChange​(javax.swing.text.JTextComponent component, java.util.function.Consumer<java.lang.String> onChange)
      Will be called any time a document changes, and will deliver the new text of the document to the provided listener
      static void toDoubleClick​(javax.swing.JComponent component, java.lang.Runnable r)  
      static void toDoubleClick​(javax.swing.JComponent component, java.util.function.Consumer<java.awt.event.MouseEvent> r)  
      static void toFocusGained​(java.awt.Component component, java.lang.Runnable r)  
      static void toFocusLost​(java.awt.Component component, java.lang.Runnable r)  
      static void toKeyEvents​(javax.swing.JTextField textField, java.awt.event.KeyAdapter keyAdapter)  
      static Listen.PopupMenuAdapter toPopupMenu​(com.jidesoft.popup.JidePopup menu)  
      static Listen.PopupMenuAdapter toPopupMenu​(javax.swing.JPopupMenu menu)  
      static void toPopupTrigger​(javax.swing.JComponent component, java.lang.Runnable r)  
      static void toPopupTrigger​(javax.swing.JComponent component, java.util.function.Consumer<java.awt.event.MouseEvent> r)  
      static void toPress​(javax.swing.JComponent component, java.lang.Runnable r)  
      static java.lang.Runnable toProperty​(java.awt.Component component, java.lang.String propertyName, java.util.function.Consumer<java.lang.Object> consumer)  
      static void toStateChange​(java.awt.ItemSelectable checkBox, java.util.function.Consumer<java.lang.Boolean> listener)  
      • Methods inherited from class java.lang.Object

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

      • Listen

        public Listen()
    • Method Detail

      • toProperty

        public static java.lang.Runnable toProperty​(java.awt.Component component,
                                                    java.lang.String propertyName,
                                                    java.util.function.Consumer<java.lang.Object> consumer)
      • toAction

        public static void toAction​(javax.swing.AbstractButton button,
                                    java.lang.Runnable r)
      • toAction

        public static void toAction​(javax.swing.JTextField field,
                                    java.lang.Runnable r)
      • toPress

        public static void toPress​(javax.swing.JComponent component,
                                   java.lang.Runnable r)
      • toDoubleClick

        public static void toDoubleClick​(javax.swing.JComponent component,
                                         java.lang.Runnable r)
      • toDoubleClick

        public static void toDoubleClick​(javax.swing.JComponent component,
                                         java.util.function.Consumer<java.awt.event.MouseEvent> r)
      • toPopupTrigger

        public static void toPopupTrigger​(javax.swing.JComponent component,
                                          java.lang.Runnable r)
      • toPopupTrigger

        public static void toPopupTrigger​(javax.swing.JComponent component,
                                          java.util.function.Consumer<java.awt.event.MouseEvent> r)
      • toStateChange

        public static void toStateChange​(java.awt.ItemSelectable checkBox,
                                         java.util.function.Consumer<java.lang.Boolean> listener)
      • toCombobox

        public static <T> void toCombobox​(javax.swing.JComboBox<T> combobox,
                                          java.util.function.Consumer<T> listener)
      • toFocusGained

        public static void toFocusGained​(java.awt.Component component,
                                         java.lang.Runnable r)
      • toFocusLost

        public static void toFocusLost​(java.awt.Component component,
                                       java.lang.Runnable r)
      • toDocumentChange

        public static void toDocumentChange​(javax.swing.text.JTextComponent component,
                                            java.util.function.Consumer<java.lang.String> onChange)
        Will be called any time a document changes, and will deliver the new text of the document to the provided listener
      • toDocumentChange

        public static void toDocumentChange​(javax.swing.text.Document document,
                                            java.util.function.Consumer<java.lang.String> onChange)
        Will be called any time a document changes, and will deliver the new text of the document to the provided listener
      • toDisplayable

        public static void toDisplayable​(javax.swing.JComponent component,
                                         java.util.function.Consumer<java.lang.Boolean> onChange)
        Listens to when a component is added into or removed from the component hierarchy, changing it's displayable flag.
      • toKeyEvents

        public static void toKeyEvents​(javax.swing.JTextField textField,
                                       java.awt.event.KeyAdapter keyAdapter)