added some documentation

This commit is contained in:
hneemann 2016-04-17 14:19:13 +02:00
parent c0abf67059
commit cc1befdfae
4 changed files with 55 additions and 1 deletions

View File

@ -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 <C> the type of the JComponent
* @return the JComponent for call chaining
*/
public <C extends JComponent> 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);
}

View File

@ -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();
}

View File

@ -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 <T> the type of the state
* @return this for call chaining
*/
public <T extends State> T register(T state) {
state.setStateManager(this);
return state;

View File

@ -0,0 +1,7 @@
/**
* Used to handle the applications state.
* States a re running, microStepping, editing
*
* @author hneemann
*/
package de.neemann.digital.gui.state;