diff --git a/src/main/java/de/neemann/digital/gui/state/State.java b/src/main/java/de/neemann/digital/gui/state/State.java index 5887cbac8..cff94d57d 100644 --- a/src/main/java/de/neemann/digital/gui/state/State.java +++ b/src/main/java/de/neemann/digital/gui/state/State.java @@ -8,6 +8,8 @@ import javax.swing.border.Border; import java.awt.event.ActionEvent; /** + * A simple state + * * @author hneemann */ public class State implements StateInterface { @@ -16,16 +18,26 @@ public class State implements StateInterface { private JComponent indicator; private StateManager stateManager; + /** + * Creates new state + */ public State() { } + /** + * The JComponent used to indicate the state + * + * @param indicator the JComponent + * @param the type of the JComponent + * @return the JComponent for call chaining + */ public C setIndicator(C indicator) { this.indicator = indicator; indicator.setBorder(DISABLED_BORDER); return indicator; } - public void setStateManager(StateManager stateManager) { + void setStateManager(StateManager stateManager) { this.stateManager = stateManager; } @@ -41,6 +53,13 @@ public class State implements StateInterface { indicator.setBorder(DISABLED_BORDER); } + /** + * Creates a tooltip action which activates the state + * + * @param name the name of the action to create + * @param icon the icon to use + * @return the acttion + */ public ToolTipAction createToolTipAction(String name, Icon icon) { return new ToolTipAction(name, icon) { @Override @@ -50,6 +69,9 @@ public class State implements StateInterface { }; } + /** + * Activates this state + */ public void activate() { stateManager.setState(this); } diff --git a/src/main/java/de/neemann/digital/gui/state/StateInterface.java b/src/main/java/de/neemann/digital/gui/state/StateInterface.java index 7b2cf4564..853f03b9d 100644 --- a/src/main/java/de/neemann/digital/gui/state/StateInterface.java +++ b/src/main/java/de/neemann/digital/gui/state/StateInterface.java @@ -1,11 +1,19 @@ package de.neemann.digital.gui.state; /** + * A simple state + * * @author hneemann */ public interface StateInterface { + /** + * Is called if the state is entered + */ void enter(); + /** + * Is called if the state is leaved + */ void leave(); } diff --git a/src/main/java/de/neemann/digital/gui/state/StateManager.java b/src/main/java/de/neemann/digital/gui/state/StateManager.java index 5e2fffef2..71f6d5afa 100644 --- a/src/main/java/de/neemann/digital/gui/state/StateManager.java +++ b/src/main/java/de/neemann/digital/gui/state/StateManager.java @@ -1,15 +1,25 @@ package de.neemann.digital.gui.state; /** + * Organizes the state switches + * * @author hneemann */ public class StateManager { private StateInterface actualState; + /** + * Creates a new instance + */ public StateManager() { } + /** + * Activates the given state + * + * @param state the state to activate + */ public void setState(StateInterface state) { if (actualState != null) actualState.leave(); @@ -18,6 +28,13 @@ public class StateManager { actualState.enter(); } + /** + * Registers a state to this manager + * + * @param state the state to register + * @param the type of the state + * @return this for call chaining + */ public T register(T state) { state.setStateManager(this); return state; diff --git a/src/main/java/de/neemann/digital/gui/state/package-info.java b/src/main/java/de/neemann/digital/gui/state/package-info.java new file mode 100644 index 000000000..62929ba6f --- /dev/null +++ b/src/main/java/de/neemann/digital/gui/state/package-info.java @@ -0,0 +1,7 @@ +/** + * Used to handle the applications state. + * States a re running, microStepping, editing + * + * @author hneemann + */ +package de.neemann.digital.gui.state;