uibindings

Create bindings between user interface (UI) controls and private settings on a card.
Binding( name, uiControl, gameComponent, [sheetsToUpdate] ) constructor
Binding.prototype.update()
Binding.prototype.initComponent()
Binding.prototype.controlToSetting( control )
Binding.prototype.settingToControl( value, control )
ActiveBinding( name, uiControl, gameComponent, sheetsToUpdate ) : Binding constructor
Bindings( editor, [gameComponent] ) constructor
Bindings.prototype.add( name, control, [sheets], [bindClass] )
Bindings.prototype.addAll( bindingArray )
Bindings.prototype.createUpdateFunction()
Bindings.prototype.createPopulateFunction()
Bindings.prototype.bind()
Bindings.prototype.toString()
Bindings.getBindingClass( componentClass ) static
Bindings.registerBindingClass( componentClass, bindingClass ) static
CheckBoxBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor
ListBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor
ItemComboBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor
GateComboBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor
ComboBoxBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor
SpinnerBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor
SliderBinding( name, uiControl, gameComponent, sheetsToUpdate ) : SpinnerBinding constructor
HSBPanelBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Create bindings between user interface (UI) controls and private settings on a card.

Bindings automate the details of synchronizing the state of the user interface controls with the state of an edited game component.

Binding( name, uiControl, gameComponent, [sheetsToUpdate] ) constructor

A Binding is an association between a UI component and part of the game component's state, usually one of the game component's private settings. When the UI component is activated by the user, calling Binding.update() will convert the state of the UI component into a game component setting and use this to update the game component so that it matches the state of the UI component. When the game component is loaded from a file, calling Binding.initComponent() will read the game component's state and update the state of the UI component to match it.

When you create a binding, you provide a name, a UI control, a game component, and an array of numbers. The array of numbers is a list of card faces (0 for front, 1 for back, 2 for the investigator marker) that need to be updated when the bound state changes. For example, if the bound state represented a monster's toughness, then you would use [1], because this information only appears on the back of a monster token.

The Binding Process
When the update() method is called, it will first call controlToSetting() to convert the state of the UI component into a setting value (a string). It will then look in the private settings of the game component for a setting with the provided name. If the setting does not exist or is different from the the setting returned from controlToSetting(), then it will copy the new value into the game component's private settings and mark the sheets listed in the list of card faces as being out of date. update() returns true if it updated the component.

When the initComponent() method is called, it will first fetch the named setting from the game component's private settings and then call settingToControl() to modify the state of the control to reflect the setting value.

Writing Binding Classes
The Binding base class will copy the text that a user writes in a text component to a private setting (for update()) and will set the text in the component to the value of the private setting (for initComponent(). For other kinds of components, you need to create an appropriate subclass that knows about the specific kind of control it is binding the game component state to. To create a subclass you only need to override the controlToSetting() and settingToControl() methods to handle the new type of control. For example, the following binding will bind a checkbox to a yes/no setting value in the game component:

 function CheckboxBinding( name, uiControl, gameComponent, sheetsToUpdate ) {
     // call superclass constructor
     Binding.call( this, name, uiControl, gameComponent, sheetsToUpdate );
 }

 subclass( CheckboxBinding, Binding );

 CheckboxBinding.prototype.toSetting = function controlToSetting( control ) {
     if( control.selected )
         return "yes";
     else
         return "no";
 }

 CheckboxBinding.prototype.settingToControl = function settingToControl( control, value ) {
     control.selected = value.equals( "yes" );
 }

If you wish to create more advanced binding behaviours, such as calling methods on the game component instead of setting custom settings, you can override update() and initComponent. It is critical that the update() method returns true if and only if the setting is updated with a different value.

name the name of the binding; this is used as the setting key to bind the control to
uiControl the UI component that takes part in the binding
gameComponent the game component to bind with the UI component
sheetsToUpdate an aray of sheet indices that depend on the bound setting

Binding.prototype.update()

Updates the UI component setting using the current value of the control.

returns true if the setting has changed

Binding.prototype.initComponent()

Updates the UI component using the current setting value.

Binding.prototype.controlToSetting( control )

Convert the state of the control to a setting string. Subclasses override this to customize how the control's state is represented in the game component's private settings.

control the control whose state must be converted to a string

returns a string representing the state of the control

Binding.prototype.settingToControl( value, control )

Change the state of the control to reflect the provided setting value. Subclasses override this to customize how the control's state is represented in the game component's private settings.

value the string value to be represented by the control
control the UI component to modify

ActiveBinding( name, uiControl, gameComponent, sheetsToUpdate ) : Binding constructor

An ActiveBinding is a type of binding that can determine for itself when it needs to update the game component because of a change to the state of the UI control. For example, the binding might install a listener on the control that will be notified when the control is updated. The listener would then call update() when it is notified of a change by the control.

To create a new type of active binding, you must subclass ActiveBinding and override the installActivationHandler() method to make the binding active. (Typically, this means adding a listener to this.control.) This base class adds an ActionListener to this.control, which is sufficient for many kinds of component.

name the name of the binding; this is used as the setting key to bind the control to
uiControl the UI component that takes part in the binding
gameComponent the game component to bind with the UI component
sheetsToUpdate an array of sheet indices that depend on the bound setting

Bindings( editor, [gameComponent] ) constructor

A collection of bindings for a group of custom controls in editor that are bound to settings in gameComponent. If gameComponent is not specified, the game component currently installed in the editor will be used.

editor the editor that will contain the bound controls
gameComponent the game component that that will be edited using the controls

Bindings.prototype.add( name, control, [sheets], [bindClass] )

Create a new Binding of type bindClass and add it to this set of bindings. The binding is created as if by calling new BindClass( name, control, gameComponent, sheets ).

If BindClass is not specified, then a default class will be searched for using Bindings.getBindingClass().

name the setting key to use for the binding
control the UI control that will be used to edit the setting
sheetsToUpdate an array of sheet indices that depend on the bound setting
bindClass the optional Binding contructor to be used to create the binding

Bindings.prototype.addAll( bindingArray )

Adds multiple bindings to this set of bindings. The arguments to this method are arrays of binding arguments as they would appear when calling Bindings.add(). For example:
 bindings.bindAll(
     [ "determination", detmCtrl, [0] ],
     [ "special-effect", effectField, [1] ],
     [ "hint", hintField, [0,1] ]
 );

bindingArray an array of arrays of binding arguments

Bindings.prototype.createUpdateFunction()

Returns a function that will call update() for all of the bindings in this set.

returns an update function for these bindings

Bindings.prototype.createPopulateFunction()

Returns a function that will call initComponent() for all of the bindings in this set.

returns a field populator function for these bindings

Bindings.prototype.bind()

Creates and install listeners on the editor associated with this Bindings instance that will bind the editor controls with the component settings.

Bindings.prototype.toString()

Returns a string representation of all of the bindings associated with this Bindings instance.

Bindings.getBindingClass( componentClass ) static

Returns the default binding class for a component of type componentClass. If there is no default binding class for the component class, this method returns null.

If componentClass itself does not have a registered binding class, then this method will search up the chain of superclasses of the component's class and return the first registered binding class it finds.

Bindings.registerBindingClass( componentClass, bindingClass ) static

Registers a subclass of Binding as the default binding class for components of type componentClass, which may either be a Java Class object or a string that names a Java class.

componentClass a type of component that will be bound using bindingClass
bindingClass a constructor for a binding class that can convert between setting strings and component state

CheckBoxBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Binds swing.JCheckBox to a yes/no setting that can be fetched with gameComponent.settings.getYesNo( name ).

ListBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Binds swing.JLists. If the items stored in the control's model provide the method toBindingValue(), then this value is used to represent that item as a settings value. Otherwise, the item's toString() representation is used.

ItemComboBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Binds the components returned by PluginContext.createInterfaceComponent( PluginContext.ComponentType.ITEM_COMBO ) and LOCATION_COMBO.

GateComboBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Binds the components returned by PluginContext.createInterfaceComponent( PluginContext.ComponentType.GATE_COMBO ).

ComboBoxBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Binds swing.JComboBoxes. If the items stored in the control's model provide the method toBindingValue(), then this value is used to represent that item as a settings value. Otherwise, the item's toString() representation is used.

SpinnerBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Binds swing.JSpinners that use integer models (including those made with the spinner() function in the uicontrols library) to an integer digit string that can be fetched with gameComponent.settings.getInt( name ).

SliderBinding( name, uiControl, gameComponent, sheetsToUpdate ) : SpinnerBinding constructor

Binds swing.JSliders to an integer digit string that can be fetched with gameComponent.settings.getInt( name ).

HSBPanelBinding( name, uiControl, gameComponent, sheetsToUpdate ) : ActiveBinding constructor

Binds arkham.HSBPanels to a comma-separated list of hue, saturation, and brightness values. Hue is represented as a relative angle (in degrees); saturation and brightness and represented as numbers between 0 and 1 (inclusive). Tints can be fetched as an array of three float values by calling Settings.tint( gameComponent.settings.get( name ) ). The returned array represents the tint in the same format as that used by a tint filters, which expresses the hue as an angle between 0 and 1.

Index    Contents