Class StateMonitor
java.lang.Object
se.datadosen.component.StateMonitor
- All Implemented Interfaces:
ItemListener,PropertyChangeListener,EventListener,ChangeListener,DocumentListener,ListDataListener
- Direct Known Subclasses:
StateMonitor.StateMonitorImpl
public abstract class StateMonitor
extends Object
implements ItemListener, DocumentListener, PropertyChangeListener, ChangeListener, 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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(ComboBoxModel model) add(JComponent... comps) add(JRadioButton comp) Since 11add(JTextComponent comp) add(JColorSelector comp) voidJTextComponent listenervoidvoiddone()Calls onChange().static voidenable(boolean test, JComponent comp) static voidenable(boolean test, JComponent... comps) static voidenable(boolean test, JComponent comp1, JComponent comp2) static voidenable(boolean test, JComponent comp1, JComponent comp2, JComponent comp3) static voidenable(boolean test, JComponent comp1, JComponent comp2, JComponent comp3, JComponent comp4) static voidenable(boolean test, JComponent comp1, JComponent comp2, JComponent comp3, JComponent comp4, JComponent comp5) The source component that triggered the onChange eventvoidJTextComponent listenervoidListDataListener listenersvoidvoidSince jAlbum 12.5, only fires onChange when a new item is selected JComboBox and Checkbox listenermonitoring(JComponent... comps) Convenience way of creating StateMonitor using lambda expressionsabstract voidonChange()Override in your subclass to be notified on component state eventsvoidJColorSelector listenervoidJTextComponent listenervoidJSpinner listener
-
Field Details
-
source
-
-
Constructor Details
-
StateMonitor
public StateMonitor() -
StateMonitor
-
StateMonitor
-
-
Method Details
-
add
-
add
- Since:
- 8.5.4
-
add
-
add
- Since:
- 8.7
-
add
Since 11 -
add
-
add
-
add
-
add
- Parameters:
list-- Since:
- 14.1.12
-
add
-
add
-
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
-
enable
-
enable
-
enable
public static void enable(boolean test, JComponent comp1, JComponent comp2, JComponent comp3, JComponent comp4) -
enable
public static void enable(boolean test, JComponent comp1, JComponent comp2, JComponent comp3, JComponent comp4, JComponent comp5) -
enable
-
itemStateChanged
Since jAlbum 12.5, only fires onChange when a new item is selected JComboBox and Checkbox listener- Specified by:
itemStateChangedin interfaceItemListener
-
insertUpdate
JTextComponent listener- Specified by:
insertUpdatein interfaceDocumentListener
-
removeUpdate
JTextComponent listener- Specified by:
removeUpdatein interfaceDocumentListener
-
changedUpdate
JTextComponent listener- Specified by:
changedUpdatein interfaceDocumentListener
-
stateChanged
JSpinner listener- Specified by:
stateChangedin interfaceChangeListener
-
propertyChange
JColorSelector listener- Specified by:
propertyChangein interfacePropertyChangeListener
-
intervalAdded
ListDataListener listeners- Specified by:
intervalAddedin interfaceListDataListener
-
intervalRemoved
- Specified by:
intervalRemovedin interfaceListDataListener
-
contentsChanged
- Specified by:
contentsChangedin interfaceListDataListener
-
monitoring
Convenience way of creating StateMonitor using lambda expressions- Parameters:
comps- to monitor- Returns:
- Since:
- 14
- See Also:
-