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;
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A simple state
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class State implements StateInterface {
|
public class State implements StateInterface {
|
||||||
@ -16,16 +18,26 @@ public class State implements StateInterface {
|
|||||||
private JComponent indicator;
|
private JComponent indicator;
|
||||||
private StateManager stateManager;
|
private StateManager stateManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new state
|
||||||
|
*/
|
||||||
public 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) {
|
public <C extends JComponent> C setIndicator(C indicator) {
|
||||||
this.indicator = indicator;
|
this.indicator = indicator;
|
||||||
indicator.setBorder(DISABLED_BORDER);
|
indicator.setBorder(DISABLED_BORDER);
|
||||||
return indicator;
|
return indicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStateManager(StateManager stateManager) {
|
void setStateManager(StateManager stateManager) {
|
||||||
this.stateManager = stateManager;
|
this.stateManager = stateManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +53,13 @@ public class State implements StateInterface {
|
|||||||
indicator.setBorder(DISABLED_BORDER);
|
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) {
|
public ToolTipAction createToolTipAction(String name, Icon icon) {
|
||||||
return new ToolTipAction(name, icon) {
|
return new ToolTipAction(name, icon) {
|
||||||
@Override
|
@Override
|
||||||
@ -50,6 +69,9 @@ public class State implements StateInterface {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activates this state
|
||||||
|
*/
|
||||||
public void activate() {
|
public void activate() {
|
||||||
stateManager.setState(this);
|
stateManager.setState(this);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package de.neemann.digital.gui.state;
|
package de.neemann.digital.gui.state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A simple state
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public interface StateInterface {
|
public interface StateInterface {
|
||||||
|
/**
|
||||||
|
* Is called if the state is entered
|
||||||
|
*/
|
||||||
void enter();
|
void enter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is called if the state is leaved
|
||||||
|
*/
|
||||||
void leave();
|
void leave();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
package de.neemann.digital.gui.state;
|
package de.neemann.digital.gui.state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Organizes the state switches
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class StateManager {
|
public class StateManager {
|
||||||
|
|
||||||
private StateInterface actualState;
|
private StateInterface actualState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*/
|
||||||
public StateManager() {
|
public StateManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activates the given state
|
||||||
|
*
|
||||||
|
* @param state the state to activate
|
||||||
|
*/
|
||||||
public void setState(StateInterface state) {
|
public void setState(StateInterface state) {
|
||||||
if (actualState != null)
|
if (actualState != null)
|
||||||
actualState.leave();
|
actualState.leave();
|
||||||
@ -18,6 +28,13 @@ public class StateManager {
|
|||||||
actualState.enter();
|
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) {
|
public <T extends State> T register(T state) {
|
||||||
state.setStateManager(this);
|
state.setStateManager(this);
|
||||||
return state;
|
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