diff --git a/ugs-classic/src/main/java/com/willwinder/universalgcodesender/MainWindow.java b/ugs-classic/src/main/java/com/willwinder/universalgcodesender/MainWindow.java index 310258b0fc..369e9f0a5a 100644 --- a/ugs-classic/src/main/java/com/willwinder/universalgcodesender/MainWindow.java +++ b/ugs-classic/src/main/java/com/willwinder/universalgcodesender/MainWindow.java @@ -1843,21 +1843,17 @@ public void UGSEvent(UGSEvent evt) { case FILE_STREAM_COMPLETE: remainingTimeValueLabel.setText(Utils.formattedMillis(0)); remainingRowsValueLabel.setText("" + backend.getNumRemainingRows()); - if (fileStateEvent.isSuccess()) { - EventQueue.invokeLater(() -> { - JOptionPane.showMessageDialog(new JFrame(), - Localization.getString("mainWindow.ui.jobComplete") + " " + Utils.formattedMillis(backend.getSendDuration()), - Localization.getString("success"), JOptionPane.INFORMATION_MESSAGE); - try { - Thread.sleep(1000); - } catch (InterruptedException ex) {} - - // Stop the timer after a delay to make sure it is updated. - timer.stop(); - }); - } else { - displayErrorDialog(Localization.getString("mainWindow.error.jobComplete")); - } + EventQueue.invokeLater(() -> { + JOptionPane.showMessageDialog(new JFrame(), + Localization.getString("mainWindow.ui.jobComplete") + " " + Utils.formattedMillis(backend.getSendDuration()), + Localization.getString("success"), JOptionPane.INFORMATION_MESSAGE); + try { + Thread.sleep(1000); + } catch (InterruptedException ex) {} + + // Stop the timer after a delay to make sure it is updated. + timer.stop(); + }); break; default: break; diff --git a/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java b/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java index 7e6140f5c8..d36c8c30d5 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/AbstractController.java @@ -33,7 +33,6 @@ This file is part of Universal Gcode Sender (UGS). import org.apache.commons.lang3.time.StopWatch; import java.io.IOException; -import java.io.NotActiveException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -652,7 +651,7 @@ private void updateNumCommands() { } // No longer a listener event - protected void fileStreamComplete(String filename, boolean success) { + protected void fileStreamComplete(String filename) { String duration = com.willwinder.universalgcodesender.Utils. @@ -661,7 +660,7 @@ protected void fileStreamComplete(String filename, boolean success) { this.dispatchConsoleMessage(MessageType.INFO,"\n**** Finished sending file in "+duration+" ****\n\n"); this.streamStopWatch.stop(); this.isStreaming = false; - dispatchStreamComplete(filename, success); + dispatchStreamComplete(filename); } @Override @@ -687,8 +686,6 @@ public void communicatorPausedOnError() { } else { this.pauseStreaming(); - // In check mode there is no state transition, so we need to manually make the notification. - this.dispatchStateChange(COMM_SENDING_PAUSED); } } catch (Exception ignored) { logger.log(Level.SEVERE, "Couldn't set the state to paused."); @@ -703,10 +700,7 @@ public void checkStreamFinished() { rowsRemaining() <= 0 && (state == ControllerState.CHECK || state == ControllerState.IDLE)) { String streamName = "queued commands"; - - // Make sure the GUI gets updated when the file finishes - this.dispatchStateChange(getCommunicatorState()); - this.fileStreamComplete(streamName, true); + this.fileStreamComplete(streamName); } } @@ -788,9 +782,6 @@ public void rawResponseListener(String response) { protected void setCurrentState(CommunicatorState state) { this.currentState = state; - if (!this.handlesAllStateChangeEvents()) { - this.dispatchStateChange(state); - } } @Override @@ -810,11 +801,7 @@ public void removeListener(ControllerListener listener) { } protected void dispatchStatusString(ControllerStatus status) { - if (listeners != null) { - for (ControllerListener c : listeners) { - c.statusStringListener(status); - } - } + listeners.forEach(l -> l.statusStringListener(status)); } protected void dispatchConsoleMessage(MessageType type, String message) { @@ -825,58 +812,28 @@ protected void dispatchConsoleMessage(MessageType type, String message) { } } - protected void dispatchStateChange(CommunicatorState state) { - if (listeners != null) { - for (ControllerListener c : listeners) { - c.controlStateChange(state); - } - } - } - - protected void dispatchStreamComplete(String filename, Boolean success) { - if (listeners != null) { - for (ControllerListener c : listeners) { - c.fileStreamComplete(filename, success); - } - } + protected void dispatchStreamComplete(String filename) { + listeners.forEach(l -> l.fileStreamComplete(filename)); } protected void dispatchCommandSkipped(GcodeCommand command) { - if (listeners != null) { - for (ControllerListener c : listeners) { - c.commandSkipped(command); - } - } + listeners.forEach(l -> l.commandSkipped(command)); } protected void dispatchCommandSent(GcodeCommand command) { - if (listeners != null) { - for (ControllerListener c : listeners) { - c.commandSent(command); - } - } + listeners.forEach(l -> l.commandSent(command)); } protected void dispatchCommandComplete(GcodeCommand command) { - if (listeners != null) { - for (ControllerListener c : listeners) { - c.commandComplete(command); - } - } + listeners.forEach(l -> l.commandComplete(command)); } protected void dispatchAlarm(Alarm alarm) { - if (listeners != null) { - listeners.forEach(l -> l.receivedAlarm(alarm)); - } + listeners.forEach(l -> l.receivedAlarm(alarm)); } protected void dispatchProbeCoordinates(Position p) { - if (listeners != null) { - for (ControllerListener c : listeners) { - c.probeCoordinates(p); - } - } + listeners.forEach(l -> l.probeCoordinates(p)); } protected String getUnitsCode() { diff --git a/ugs-core/src/com/willwinder/universalgcodesender/GrblController.java b/ugs-core/src/com/willwinder/universalgcodesender/GrblController.java index 6df8ec288f..f33d9d2c12 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/GrblController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/GrblController.java @@ -90,11 +90,6 @@ public GrblController() { this(new GrblCommunicator()); } - @Override - public boolean handlesAllStateChangeEvents() { - return capabilities.hasCapability(GrblCapabilitiesConstants.REAL_TIME); - } - @Override public Capabilities getCapabilities() { return capabilities; @@ -163,7 +158,6 @@ else if (GrblUtils.isOkErrorAlarmResponse(response)) { Alarm alarm = GrblUtils.parseAlarmResponse(response); dispatchAlarm(alarm); dispatchStatusString(controllerStatus); - dispatchStateChange(COMM_IDLE); } // If there is an active command, mark it as completed with error @@ -250,7 +244,6 @@ else if (GrblUtils.isGrblFeedbackMessage(response, capabilities)) { this.dispatchConsoleMessage(MessageType.VERBOSE, grblFeedbackMessage + "\n"); setDistanceModeCode(grblFeedbackMessage.getDistanceMode()); setUnitsCode(grblFeedbackMessage.getUnits()); - dispatchStateChange(COMM_IDLE); } else if (GrblUtils.isGrblSettingMessage(response)) { @@ -343,7 +336,6 @@ protected void cancelSendBeforeEvent() throws Exception { else if (!paused && this.capabilities.hasCapability(GrblCapabilitiesConstants.REAL_TIME)) { try { this.pauseStreaming(); - this.dispatchStateChange(CommunicatorState.COMM_SENDING_PAUSED); } catch (Exception e) { // Oh well, was worth a shot. System.out.println("Exception while trying to issue a soft reset: " + e.getMessage()); @@ -628,11 +620,6 @@ private void handleStatusString(final String string) { detectAxisCapabilityFromControllerStatus(Axis.B, CapabilitiesConstants.B_AXIS); detectAxisCapabilityFromControllerStatus(Axis.C, CapabilitiesConstants.C_AXIS); - // Make UGS more responsive to the state being reported by GRBL. - if (before != getCommunicatorState()) { - this.dispatchStateChange(getCommunicatorState()); - } - // GRBL 1.1 jog complete transition if (beforeState == ControllerState.JOG && controllerStatus.getState() == ControllerState.IDLE) { this.comm.cancelSend(); @@ -655,9 +642,6 @@ private void handleStatusString(final String string) { // If the machine goes into idle, we no longer need to cancel. if (controllerStatus.getState() == ControllerState.IDLE || controllerStatus.getState() == ControllerState.CHECK) { isCanceling = false; - - // Make sure the GUI gets updated - this.dispatchStateChange(getCommunicatorState()); } // Otherwise check if the machine is Hold/Queue and stopped. else if ((controllerStatus.getState() == ControllerState.HOLD || controllerStatus.getState() == ControllerState.DOOR) && lastLocation.equals(this.controllerStatus.getMachineCoord())) { diff --git a/ugs-core/src/com/willwinder/universalgcodesender/IController.java b/ugs-core/src/com/willwinder/universalgcodesender/IController.java index 14b0367e23..f9263cf7b4 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/IController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/IController.java @@ -181,14 +181,6 @@ public interface IController { * In case a controller reset is detected. */ void resetBuffers(); - - /** - * Indicator to abstract GUIBackend implementation that the contract class - * will handle ALL state change events. When this returns true it means - * things like completing the final command in a stream will not - * automatically re-enable buttons. - */ - boolean handlesAllStateChangeEvents(); /* Stream content diff --git a/ugs-core/src/com/willwinder/universalgcodesender/SmoothieController.java b/ugs-core/src/com/willwinder/universalgcodesender/SmoothieController.java index d9bd0a3385..8c76f1fe05 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/SmoothieController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/SmoothieController.java @@ -195,7 +195,6 @@ private void handleStatusResponse(String response) { UnitUtils.Units currentUnits = getCurrentGcodeState().getUnits(); controllerStatus = SmoothieUtils.getStatusFromStatusString(controllerStatus, response, currentUnits); - dispatchStateChange(getCommunicatorState()); dispatchStatusString(controllerStatus); } @@ -235,11 +234,6 @@ public void performHomingCycle() throws Exception { dispatchStatusString(controllerStatus); } - @Override - public boolean handlesAllStateChangeEvents() { - return false; - } - @Override public Capabilities getCapabilities() { return capabilities; diff --git a/ugs-core/src/com/willwinder/universalgcodesender/TinyGController.java b/ugs-core/src/com/willwinder/universalgcodesender/TinyGController.java index 61fd59bab9..140afca57c 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/TinyGController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/TinyGController.java @@ -86,11 +86,6 @@ protected void setControllerState(ControllerState controllerState) { dispatchStatusString(controllerStatus); } - @Override - public boolean handlesAllStateChangeEvents() { - return false; - } - @Override public Capabilities getCapabilities() { return capabilities; diff --git a/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java b/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java index 15884d4b5c..b385cbe390 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/firmware/fluidnc/FluidNCController.java @@ -589,11 +589,6 @@ public void resetBuffers() { communicator.resetBuffers(); } - @Override - public boolean handlesAllStateChangeEvents() { - return true; - } - @Override public GcodeCommand createCommand(String command) throws Exception { return new FluidNCCommand(command); diff --git a/ugs-core/src/com/willwinder/universalgcodesender/listeners/ControllerListener.java b/ugs-core/src/com/willwinder/universalgcodesender/listeners/ControllerListener.java index 12f421c134..bc86aed00b 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/listeners/ControllerListener.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/listeners/ControllerListener.java @@ -20,7 +20,6 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.universalgcodesender.model.Alarm; import com.willwinder.universalgcodesender.model.Position; -import com.willwinder.universalgcodesender.model.CommunicatorState; import com.willwinder.universalgcodesender.types.GcodeCommand; /** @@ -29,16 +28,10 @@ This file is part of Universal Gcode Sender (UGS). * @author wwinder */ public interface ControllerListener { - /** - * The controller has modified the state by itself, such as pausing a job on - * an error. - */ - void controlStateChange(CommunicatorState state); - /** * The file streaming has completed. */ - void fileStreamComplete(String filename, boolean success); + void fileStreamComplete(String filename); /** * If an alarm is received from the controller @@ -51,12 +44,12 @@ public interface ControllerListener { * A command in the stream has been skipped. */ void commandSkipped(GcodeCommand command); - + /** * A command has successfully been sent to the controller. */ void commandSent(GcodeCommand command); - + /** * A command has been processed by the the controller. */ @@ -71,4 +64,4 @@ public interface ControllerListener { * Controller status information. */ void statusStringListener(ControllerStatus status); -} \ No newline at end of file +} diff --git a/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java b/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java index edc4109614..d7a1d2e453 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/model/GUIBackend.java @@ -74,7 +74,7 @@ public class GUIBackend implements BackendAPI, ControllerListener, SettingChange private boolean streamFailed = false; private boolean autoconnect = false; - private GcodeParser gcp = new GcodeParser(); + private final GcodeParser gcp = new GcodeParser(); private ControllerStatus controllerStatus = new ControllerStatus(); @Override @@ -675,12 +675,8 @@ public void requestParserState() throws Exception { // Controller Listener // ///////////////////////// @Override - public void controlStateChange(CommunicatorState state) { - } - - @Override - public void fileStreamComplete(String filename, boolean success) { - this.sendUGSEvent(new FileStateEvent(FileState.FILE_STREAM_COMPLETE, filename, success)); + public void fileStreamComplete(String filename) { + this.sendUGSEvent(new FileStateEvent(FileState.FILE_STREAM_COMPLETE, filename)); } @Override diff --git a/ugs-core/src/com/willwinder/universalgcodesender/model/events/FileStateEvent.java b/ugs-core/src/com/willwinder/universalgcodesender/model/events/FileStateEvent.java index 5a436f755f..4172a83a32 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/model/events/FileStateEvent.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/model/events/FileStateEvent.java @@ -27,7 +27,6 @@ This file is part of Universal Gcode Sender (UGS). public class FileStateEvent implements UGSEvent { private final FileState fileState; private final String file; - private final boolean success; /** * Create a file state event @@ -39,23 +38,8 @@ public class FileStateEvent implements UGSEvent { * @param filepath the file related to the file event. */ public FileStateEvent(FileState state, String filepath) { - this(state, filepath, true); - } - - /** - * Create a file state event - * FILE_LOADING: This event provides a path to an unprocessed gcode file. - * FILE_LOADED: This event provides a path to a processed gcode file which - * should be opened with a GcodeStreamReader. - * - * @param state the new file state. - * @param filepath the file related to the file event. - * @param success if the given file state was a success, usually used together with {@link FileState#FILE_STREAM_COMPLETE} to indicate if file was sent - */ - public FileStateEvent(FileState state, String filepath, boolean success) { this.fileState = state; this.file = filepath; - this.success = success; } public FileState getFileState() { @@ -65,8 +49,4 @@ public FileState getFileState() { public String getFile() { return file; } - - public boolean isSuccess() { - return success; - } } diff --git a/ugs-core/test/com/willwinder/universalgcodesender/AbstractControllerTest.java b/ugs-core/test/com/willwinder/universalgcodesender/AbstractControllerTest.java index 235061bef9..7c4b626159 100644 --- a/ugs-core/test/com/willwinder/universalgcodesender/AbstractControllerTest.java +++ b/ugs-core/test/com/willwinder/universalgcodesender/AbstractControllerTest.java @@ -120,7 +120,7 @@ public void setUp() throws Exception { /////////////// // UTILITIES // /////////////// - private void openInstanceExpectUtility(String port, int portRate, boolean handleStateChange) throws Exception { + private void openInstanceExpectUtility(String port, int portRate) throws Exception { instance.openCommAfterEvent(); expect(expectLastCall()).anyTimes(); mockMessageService.dispatchMessage(anyObject(), anyString()); @@ -131,7 +131,6 @@ private void openInstanceExpectUtility(String port, int portRate, boolean handle mockCommunicator.connect(or(eq(ConnectionDriver.JSERIALCOMM), eq(ConnectionDriver.JSSC)), eq(port), eq(portRate)); expect(instance.isCommOpen()).andReturn(false).once(); expect(instance.isCommOpen()).andReturn(true).anyTimes(); - expect(instance.handlesAllStateChangeEvents()).andReturn(handleStateChange).anyTimes(); } private void streamInstanceExpectUtility() throws Exception { expect(mockCommunicator.areActiveCommands()).andReturn(false).anyTimes(); @@ -141,7 +140,7 @@ private void streamInstanceExpectUtility() throws Exception { expect(expectLastCall()).once(); } private void startStreamExpectation(String port, int rate) throws Exception { - openInstanceExpectUtility(port, rate, false); + openInstanceExpectUtility(port, rate); streamInstanceExpectUtility(); // Making sure the commands get queued. @@ -235,7 +234,7 @@ public void testQueueCommand() throws Exception { String port = "/some/port"; int rate = 1234; - openInstanceExpectUtility(port, rate, false); + openInstanceExpectUtility(port, rate); streamInstanceExpectUtility(); // Making sure the commands get queued. @@ -263,7 +262,7 @@ public void testQueueCommands() throws Exception { String port = "/some/port"; int rate = 1234; - openInstanceExpectUtility(port, rate, false); + openInstanceExpectUtility(port, rate); streamInstanceExpectUtility(); // Making sure the commands get queued. diff --git a/ugs-core/test/com/willwinder/universalgcodesender/GrblControllerTest.java b/ugs-core/test/com/willwinder/universalgcodesender/GrblControllerTest.java index 791a502c74..fbcbf2c67c 100644 --- a/ugs-core/test/com/willwinder/universalgcodesender/GrblControllerTest.java +++ b/ugs-core/test/com/willwinder/universalgcodesender/GrblControllerTest.java @@ -1560,7 +1560,6 @@ public void errorInCheckModeSending() throws Exception { assertEquals(ControllerState.CHECK, gc.getControllerStatus().getState()); assertFalse(gc.isPaused()); verify(communicator, times(1)).sendByteImmediately(GRBL_PAUSE_COMMAND); - verify(controllerListener, times(1)).controlStateChange(COMM_SENDING_PAUSED); } @Test