Commit 0e797d35 authored by Stefanie Gareis's avatar Stefanie Gareis
Browse files

Simulation speed is now adjustable, Status messages can be written to a status line

parent 7dc2451f
......@@ -18,6 +18,7 @@ $Id$
package org.fortiss.af3.component.ui.simulator;
import static org.conqat.ide.commons.ui.dialog.MessageUtils.showErrorAsync;
import static org.fortiss.tooling.base.ui.utils.StatusUtils.setStatusMessage;
import java.util.ArrayList;
import java.util.List;
......@@ -78,6 +79,9 @@ public class SimulationManager {
/** Default simulation speed => 4 simulation steps per second. */
private static final int DEFAULT_SPEED = 250;
/** Customized simulation speed */
private static int customSpeed = DEFAULT_SPEED;
/** Stores the singleton reference to simulation view. */
public static SimulationManager INSTANCE = new SimulationManager();
......@@ -121,7 +125,7 @@ public class SimulationManager {
simulationThread = new Thread("AF3 Simulation") {
@Override
public void run() {
final int delay = DEFAULT_SPEED;
final int delay = customSpeed;
while(!isInterrupted()) {
long startTime = System.currentTimeMillis();
if(!performingStep) {
......@@ -130,7 +134,7 @@ public class SimulationManager {
if(lastException != null) {
break;
}
long remainingDelay = delay - (System.currentTimeMillis() - startTime);
long remainingDelay = customSpeed - (System.currentTimeMillis() - startTime);
if(remainingDelay > 0) {
try {
sleep(remainingDelay);
......@@ -179,6 +183,26 @@ public class SimulationManager {
fireSimulationEvent(SIMULATION_REFRESH_EVENT);
}
/** Increases the Simulation speed by decreasing the delay 10 ms */
public void speedUp() {
if(customSpeed >= 20) {
customSpeed -= 10;
} else if(customSpeed > 1) {
customSpeed--;
}
setStatusMessage("Time between simulation steps: " + customSpeed + " ms");
}
/** Decreases the Simulation speed by increasing the delay 10 ms */
public void speedDown() {
if(customSpeed >= 10)
customSpeed += 10;
else
customSpeed++;
setStatusMessage("Time between simulation steps: " + customSpeed + " ms");
}
/**
* Shutdown of the simulation manager. Called when plugin is stopped. Must
* not be called from somewhere else.
......
......@@ -239,6 +239,8 @@ public class SimulationView extends ViewPart implements IPropertyListener {
}
simulationViewActionsInstance.initialize.setEnabled(true);
simulationViewActionsInstance.delete.setEnabled(true);
simulationViewActionsInstance.speedUp.setEnabled(true);
simulationViewActionsInstance.speedDown.setEnabled(true);
} else {
for(IAction a : simulationViewActionsInstance.getActions()) {
a.setEnabled(false);
......@@ -267,9 +269,15 @@ public class SimulationView extends ViewPart implements IPropertyListener {
/** Action for stopping and deleting simulation. */
public final Action delete;
/** Action for increasing simulation speed */
public final Action speedUp;
/** Action for decreasing simulation speed */
public final Action speedDown;
/** Returns the actions managed by this class. */
IAction[] getActions() {
return new IAction[] {run, pause, performStep, initialize, delete};
return new IAction[] {run, pause, performStep, initialize, delete, speedUp, speedDown};
}
/** Constructor. */
......@@ -324,6 +332,28 @@ public class SimulationView extends ViewPart implements IPropertyListener {
setUpAction(delete, "Remove", "Remove current Simulation",
getImageDescriptor("icons/simulator/terminate_remove.gif"),
getImageDescriptor("icons/simulator/terminate_remove_disabled.gif"));
speedUp = new Action() {
@Override
public void run() {
SimulationManager.INSTANCE.speedUp();
}
};
setUpAction(speedUp, "SpeedUp", "Decrease time between simulation steps",
getImageDescriptor("icons/simulator/minus.png"),
getImageDescriptor("icons/simulator/minus.png"));
speedDown = new Action() {
@Override
public void run() {
SimulationManager.INSTANCE.speedDown();
}
};
setUpAction(speedDown, "SlowDown", "Increase time between simulation steps",
getImageDescriptor("icons/simulator/plus.png"),
getImageDescriptor("icons/simulator/plus.png"));
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment