soc.game
Interface SOCGameOption.ChangeListener

Enclosing class:
SOCGameOption

public static interface SOCGameOption.ChangeListener

Listener for option value changes at the client during game creation. When the user changes an option, allows a related option to change. For example, when the max players is changed to 5 or 6, the listener can check the box for "use 6-player board".

Once written, a newer server can't do anything to update an older client's ChangeListener code, so be careful and write them defensively.

Callback method is valueChanged(SOCGameOption, Object, Object, Map). Called from NewGameOptionsFrame.

For server-side consistency adjustment of values before creating games, add code to SOCGameOption.adjustOptionsToKnown(Map, Map, boolean) that's equivalent to your ChangeListener.

Since:
1.1.13
See Also:
SOCGameOption.addChangeListener(ChangeListener)

Method Summary
 void valueChanged(SOCGameOption opt, java.lang.Object oldValue, java.lang.Object newValue, java.util.Map<java.lang.String,SOCGameOption> currentOpts)
          Called when the user changes opt's value during game creation.
 

Method Detail

valueChanged

void valueChanged(SOCGameOption opt,
                  java.lang.Object oldValue,
                  java.lang.Object newValue,
                  java.util.Map<java.lang.String,SOCGameOption> currentOpts)
Called when the user changes opt's value during game creation. Not called when a game option's setters are called.

If you change any other currentOpts values, be sure to call SOCGameOption.refreshDisplay() to update the GUI. Do not call refreshDisplay() on opt.

Remember that the related option may not be present in currentOpts because different servers may have different default options, or different versions.

Write this method carefully, because the server can't update a client's buggy version. Although calls to this method are surrounded by a try/catch(Throwable) block, a bug-free version is best for the user.

For SOCGameOption.OTYPE_STR or OTYPE_STRHIDE, this method is called once for each character entered or deleted.

For SOCGameOption.OTYPE_INT or OTYPE_INTBOOL, this method is called once for each digit typed or deleted, so long as the resulting number is parsable and within the min/max range for the option.

For SOCGameOption.OTYPE_ENUMBOOL or OTYPE_INTBOOL, if both the boolean and int value fields are set at once, then after updating both fields, valueChanged will be called twice (boolean and then int). If the boolean value is cleared to false, there won't be a second call for the int value, because when cleared the game option has no effect.

Parameters:
opt - Option that has changed, already updated to new value
oldValue - Old value; an Integer, Boolean, or String.
newValue - New value; always the same class as oldValue
currentOpts - The current value of all SOCGameOptions in this set