mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
StartStopScanningAction no longer holds current state itself
git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@136 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
parent
2c68534ea7
commit
662e111d04
@ -16,7 +16,7 @@ import net.azib.ipscan.core.ScanningProgressCallback;
|
||||
public class StateMachine {
|
||||
|
||||
private ScanningProgressCallback progressCallback;
|
||||
private ScanningState state;
|
||||
private ScanningState state = ScanningState.IDLE;
|
||||
|
||||
public void transitionTo(ScanningState newState) {
|
||||
this.state = newState;
|
||||
@ -30,6 +30,13 @@ public class StateMachine {
|
||||
public boolean isState(ScanningState state) {
|
||||
return this.state == state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return current state
|
||||
*/
|
||||
public ScanningState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setScanningProgressCallback(ScanningProgressCallback progressCallback) {
|
||||
this.progressCallback = progressCallback;
|
||||
|
||||
@ -44,7 +44,7 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
|
||||
private Display display;
|
||||
|
||||
private ScanningState state = ScanningState.IDLE;
|
||||
private StateMachine stateMachine;
|
||||
|
||||
public StartStopScanningAction(ScannerThreadFactory scannerThreadFactory, StateMachine stateMachine, ResultTable resultTable, StatusBar statusBar, FeederGUIRegistry feederRegistry, Button startStopButton) {
|
||||
this.scannerThreadFactory = scannerThreadFactory;
|
||||
@ -54,7 +54,9 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
this.button = startStopButton;
|
||||
this.display = button.getDisplay();
|
||||
|
||||
stateMachine.setScanningProgressCallback(this);
|
||||
this.stateMachine = stateMachine;
|
||||
// TODO: remove this, use state transition notifications
|
||||
this.stateMachine.setScanningProgressCallback(this);
|
||||
|
||||
// pre-load button images
|
||||
buttonImages[ScanningState.IDLE.ordinal()] = new Image(null, Labels.getInstance().getImageAsStream("button.start.img"));
|
||||
@ -69,6 +71,7 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
buttonTexts[ScanningState.KILLING.ordinal()] = Labels.getLabel("button.kill");
|
||||
|
||||
// set the defaultimage
|
||||
ScanningState state = stateMachine.getState();
|
||||
button.setImage(buttonImages[state.ordinal()]);
|
||||
button.setText(buttonTexts[state.ordinal()]);
|
||||
}
|
||||
@ -78,7 +81,7 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
}
|
||||
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
switch (state) {
|
||||
switch (stateMachine.getState()) {
|
||||
case IDLE:
|
||||
// start the scan!
|
||||
resultTable.initNewScan(feederRegistry.current().getInfo());
|
||||
@ -99,8 +102,7 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
}
|
||||
}
|
||||
|
||||
public void scannerStateChanged(ScanningState newState) {
|
||||
this.state = newState;
|
||||
public void scannerStateChanged(final ScanningState state) {
|
||||
if (display.isDisposed())
|
||||
return;
|
||||
display.asyncExec(new Runnable() {
|
||||
@ -144,7 +146,7 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr
|
||||
statusBar.setProgress(percentageComplete);
|
||||
|
||||
// change button image
|
||||
button.setImage(buttonImages[state.ordinal()]);
|
||||
button.setImage(buttonImages[stateMachine.getState().ordinal()]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user