se.datadosen.component
Class StateMonitor

java.lang.Object
  extended by se.datadosen.component.StateMonitor
All Implemented Interfaces:
java.awt.event.ItemListener, java.beans.PropertyChangeListener, java.util.EventListener, javax.swing.event.ChangeListener, javax.swing.event.DocumentListener

public abstract class StateMonitor
extends java.lang.Object
implements java.awt.event.ItemListener, javax.swing.event.DocumentListener, java.beans.PropertyChangeListener, javax.swing.event.ChangeListener

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
protected  java.lang.Object source
           
 
Constructor Summary
StateMonitor()
           
 
Method Summary
 StateMonitor add(javax.swing.JCheckBox comp)
           
 StateMonitor add(JColorSelector comp)
           
 StateMonitor add(javax.swing.JComboBox comp)
           
 StateMonitor add(javax.swing.JRadioButton comp)
           
 StateMonitor add(javax.swing.JSpinner comp)
           
 StateMonitor add(javax.swing.text.JTextComponent comp)
           
 void changedUpdate(javax.swing.event.DocumentEvent e)
          JTextComponent listener
 void done()
          Calls onChange().
static void enable(boolean test, javax.swing.JComponent... comps)
           
static void enable(boolean test, javax.swing.JComponent comp)
           
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 itemStateChanged(java.awt.event.ItemEvent e)
          JComboBox and Checkbox listener
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()
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.text.JTextComponent comp)

add

public StateMonitor add(JColorSelector comp)

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)
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