//////////////////////////////////////// // Programming project code // UniBw M, 2022, 2023, 2024 // www.unibw.de/inf2 // (c) Mark Minas (mark.minas@unibw.de) //////////////////////////////////////// package pp.dialog; import com.jme3.app.Application; import com.jme3.app.state.AppState; import com.simsilica.lemur.DefaultCheckboxModel; /** * A checkbox model for enabling and disabling app states. * This model links a checkbox with an AppState, so that checking * or unchecking the box enables or disables the state, respectively. */ public class StateCheckboxModel extends DefaultCheckboxModel { private final AppState state; /** * Constructs a StateCheckboxModel for the specified app state class. * * @param app the application containing the state manager * @param stateClass the class of the app state to be controlled */ public StateCheckboxModel(Application app, Class stateClass) { this(app.getStateManager().getState(stateClass)); } /** * Constructs a StateCheckboxModel for the specified app state. * * @param state the app state to be controlled */ public StateCheckboxModel(AppState state) { this.state = state; setChecked(state.isEnabled()); } /** * Sets the checked state of the checkbox and enables or disables * the associated app state accordingly. * * @param checked true to check the box and enable the state, false to uncheck the box and disable the state */ @Override public void setChecked(boolean checked) { super.setChecked(checked); state.setEnabled(checked); } }