Class StateMonitor

  • All Implemented Interfaces:
    java.awt.event.ItemListener, java.beans.PropertyChangeListener, java.util.EventListener, javax.swing.event.ChangeListener, javax.swing.event.DocumentListener, javax.swing.event.ListDataListener
    Direct Known Subclasses:
    StateMonitor.StateMonitorImpl

    public abstract class StateMonitor
    extends java.lang.Object
    implements java.awt.event.ItemListener, javax.swing.event.DocumentListener, java.beans.PropertyChangeListener, javax.swing.event.ChangeListener, javax.swing.event.ListDataListener
    Convenience "master listener" class that allows you to monitor component state events in a uniform and syntactically short way. When a change occurs to any of the added components, onChange is called on the implementing subclass. This class also contains convenient methods for enabling and disabling groups of components Example:
    
     import se.datadosen.component.*;
    
     ControlPanel ui = new ControlPanel() {
     JCheckBox homepageLinking = new JCheckBox("Add Copyright");
     JTextField text = new JTextField("",20);
     JTextField url = new JTextField("",20);
     JColorSelector color = new JColorSelector("Link text color", new JTextField(6));
    
     // Layout controls easily similar to how text is added in a word processor
     add("br", homepageLinking);
     add("br", new JLabel("Link text"));
     add("tab", text);
     add("br", new JLabel("Link URL"));
     add("tab", url);
     add("br", new JLabel("Link color"));
     add("tab", color);
     add(color.getTextComponent());
    
     new StateMonitor() {
     public void onChange() {
     // make "text" editable only if "homepageLinking" is ticked.
     text.setEditable(homepageLinking.isSelected());
     // Make "color" enabled only if there is text entered and "homepageLinking" is ticked
     color.setEnabled(text.getText().length() > 0
     && homepageLinking.isSelected());
     }
     }.add(homepageLinking).add(text).done();
     };
    
     window.setSkinUI(ui); // Installs this user interface in jAlbum's skin section
    
     
    Since:
    8.5
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Object source  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      StateMonitor add​(javax.swing.ComboBoxModel model)  
      StateMonitor add​(javax.swing.JCheckBox comp)  
      StateMonitor add​(javax.swing.JComboBox comp)  
      StateMonitor add​(javax.swing.JComponent... comps)  
      StateMonitor add​(javax.swing.JList list)  
      StateMonitor add​(javax.swing.JRadioButton comp)  
      StateMonitor add​(javax.swing.JSlider comp)
      Since 11
      StateMonitor add​(javax.swing.JSpinner comp)  
      StateMonitor add​(javax.swing.ListModel listModel)  
      StateMonitor add​(javax.swing.text.JTextComponent comp)  
      StateMonitor add​(JColorSelector comp)  
      void changedUpdate​(javax.swing.event.DocumentEvent e)
      JTextComponent listener
      void contentsChanged​(javax.swing.event.ListDataEvent e)  
      void done()
      Calls onChange().
      static void enable​(boolean test, javax.swing.JComponent comp)  
      static void enable​(boolean test, javax.swing.JComponent... comps)  
      static void enable​(boolean test, javax.swing.JComponent comp1, javax.swing.JComponent comp2)  
      static void enable​(boolean test, javax.swing.JComponent comp1, javax.swing.JComponent comp2, javax.swing.JComponent comp3)  
      static void enable​(boolean test, javax.swing.JComponent comp1, javax.swing.JComponent comp2, javax.swing.JComponent comp3, javax.swing.JComponent comp4)  
      static void enable​(boolean test, javax.swing.JComponent comp1, javax.swing.JComponent comp2, javax.swing.JComponent comp3, javax.swing.JComponent comp4, javax.swing.JComponent comp5)  
      java.lang.Object getSource()
      The source component that triggered the onChange event
      void insertUpdate​(javax.swing.event.DocumentEvent e)
      JTextComponent listener
      void intervalAdded​(javax.swing.event.ListDataEvent e)
      ListDataListener listeners
      void intervalRemoved​(javax.swing.event.ListDataEvent e)  
      void itemStateChanged​(java.awt.event.ItemEvent e)
      Since jAlbum 12.5, only fires onChange when a new item is selected JComboBox and Checkbox listener
      static StateMonitor.StateMonitorImpl monitoring​(javax.swing.JComponent... comps)
      Convenience way of creating StateMonitor using lambda expressions
      abstract void onChange()
      Override in your subclass to be notified on component state events
      void propertyChange​(java.beans.PropertyChangeEvent e)
      JColorSelector listener
      void removeUpdate​(javax.swing.event.DocumentEvent e)
      JTextComponent listener
      void stateChanged​(javax.swing.event.ChangeEvent e)
      JSpinner listener
      • Methods inherited from class java.lang.Object

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

      • source

        protected java.lang.Object source
    • Constructor Detail

      • StateMonitor

        public StateMonitor()
      • StateMonitor

        public StateMonitor​(javax.swing.JComponent... comps)
      • StateMonitor

        public StateMonitor​(javax.swing.ComboBoxModel model)
    • Method Detail

      • add

        public StateMonitor add​(javax.swing.JCheckBox comp)
      • add

        public StateMonitor add​(javax.swing.JRadioButton comp)
        Since:
        8.5.4
      • add

        public StateMonitor add​(javax.swing.JComboBox comp)
      • add

        public StateMonitor add​(javax.swing.JSpinner comp)
        Since:
        8.7
      • add

        public StateMonitor add​(javax.swing.JSlider comp)
        Since 11
      • add

        public StateMonitor add​(javax.swing.text.JTextComponent comp)
      • add

        public StateMonitor add​(javax.swing.ComboBoxModel model)
      • add

        public StateMonitor add​(javax.swing.JList list)
        Parameters:
        list -
        Since:
        14.1.12
      • add

        public StateMonitor add​(javax.swing.ListModel listModel)
      • add

        public StateMonitor add​(javax.swing.JComponent... comps)
      • getSource

        public java.lang.Object getSource()
        The source component that triggered the onChange event
      • onChange

        public abstract void onChange()
        Override in your subclass to be notified on component state events
      • done

        public void done()
        Calls onChange(). Put this call at the end of a chain of add() calls to ensure that onChange() is called initially.
      • enable

        public static void enable​(boolean test,
                                  javax.swing.JComponent comp)
      • enable

        public static void enable​(boolean test,
                                  javax.swing.JComponent comp1,
                                  javax.swing.JComponent comp2)
      • enable

        public static void enable​(boolean test,
                                  javax.swing.JComponent comp1,
                                  javax.swing.JComponent comp2,
                                  javax.swing.JComponent comp3)
      • enable

        public static void enable​(boolean test,
                                  javax.swing.JComponent comp1,
                                  javax.swing.JComponent comp2,
                                  javax.swing.JComponent comp3,
                                  javax.swing.JComponent comp4)
      • enable

        public static void enable​(boolean test,
                                  javax.swing.JComponent comp1,
                                  javax.swing.JComponent comp2,
                                  javax.swing.JComponent comp3,
                                  javax.swing.JComponent comp4,
                                  javax.swing.JComponent comp5)
      • enable

        public static void enable​(boolean test,
                                  javax.swing.JComponent... comps)
      • itemStateChanged

        public void itemStateChanged​(java.awt.event.ItemEvent e)
        Since jAlbum 12.5, only fires onChange when a new item is selected JComboBox and Checkbox listener
        Specified by:
        itemStateChanged in interface java.awt.event.ItemListener
      • insertUpdate

        public void insertUpdate​(javax.swing.event.DocumentEvent e)
        JTextComponent listener
        Specified by:
        insertUpdate in interface javax.swing.event.DocumentListener
      • removeUpdate

        public void removeUpdate​(javax.swing.event.DocumentEvent e)
        JTextComponent listener
        Specified by:
        removeUpdate in interface javax.swing.event.DocumentListener
      • changedUpdate

        public void changedUpdate​(javax.swing.event.DocumentEvent e)
        JTextComponent listener
        Specified by:
        changedUpdate in interface javax.swing.event.DocumentListener
      • stateChanged

        public void stateChanged​(javax.swing.event.ChangeEvent e)
        JSpinner listener
        Specified by:
        stateChanged in interface javax.swing.event.ChangeListener
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent e)
        JColorSelector listener
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
      • intervalAdded

        public void intervalAdded​(javax.swing.event.ListDataEvent e)
        ListDataListener listeners
        Specified by:
        intervalAdded in interface javax.swing.event.ListDataListener
      • intervalRemoved

        public void intervalRemoved​(javax.swing.event.ListDataEvent e)
        Specified by:
        intervalRemoved in interface javax.swing.event.ListDataListener
      • contentsChanged

        public void contentsChanged​(javax.swing.event.ListDataEvent e)
        Specified by:
        contentsChanged in interface javax.swing.event.ListDataListener
      • monitoring

        public static StateMonitor.StateMonitorImpl monitoring​(javax.swing.JComponent... comps)
        Convenience way of creating StateMonitor using lambda expressions
        Parameters:
        comps - to monitor
        Returns:
        Since:
        14
        See Also:
        onChange()