mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-18 09:24:42 -04:00
added some documentation
This commit is contained in:
parent
c0abf67059
commit
cc1befdfae
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Used to handle the applications state.
|
||||
* States a re running, microStepping, editing
|
||||
*
|
||||
* @author hneemann
|
||||
*/
|
||||
package de.neemann.digital.gui.state;
|
Loading…
x
Reference in New Issue
Block a user