From dfb334f4376fbbf19384dc91e26b76096c88f241 Mon Sep 17 00:00:00 2001 From: winder Date: Tue, 3 Mar 2015 09:52:38 -0500 Subject: [PATCH] Moved some things around to better organize an model API package. --- manifest.mf | 1 + .../universalgcodesender/MainWindow.java | 10 +-- .../connection/ConnectionFactory.java | 37 +++++++++++ .../listeners/ControlStateListener.java | 16 ----- .../BackendAPI.java} | 29 ++++++++- .../model/BackendAPIReadOnly.java | 61 +++++++++++++++++++ .../model/ControlStateListener.java | 29 +++++++++ .../{ => model}/GUIBackend.java | 30 ++++++--- .../pendantui/PendantUI.java | 10 +-- .../pendantui/PendantUITest.java | 4 +- 10 files changed, 188 insertions(+), 39 deletions(-) create mode 100644 src/com/willwinder/universalgcodesender/connection/ConnectionFactory.java delete mode 100644 src/com/willwinder/universalgcodesender/listeners/ControlStateListener.java rename src/com/willwinder/universalgcodesender/{MainWindowAPI.java => model/BackendAPI.java} (68%) create mode 100644 src/com/willwinder/universalgcodesender/model/BackendAPIReadOnly.java create mode 100644 src/com/willwinder/universalgcodesender/model/ControlStateListener.java rename src/com/willwinder/universalgcodesender/{ => model}/GUIBackend.java (94%) diff --git a/manifest.mf b/manifest.mf index 730102c228..495d98a3f1 100644 --- a/manifest.mf +++ b/manifest.mf @@ -11,6 +11,7 @@ Class-Path: lib/jssc.jar lib/jogl-all-natives-linux-armv6.jar lib/jogl-all-natives-linux-i586.jar lib/jogl-all-natives-macosx-universal.jar + lib/gluegen.jar lib/gluegen-rt.jar lib/gluegen-rt-natives-windows-i586.jar lib/gluegen-rt-natives-linux-amd64.jar diff --git a/src/com/willwinder/universalgcodesender/MainWindow.java b/src/com/willwinder/universalgcodesender/MainWindow.java index 9979c880f2..a04c399abf 100644 --- a/src/com/willwinder/universalgcodesender/MainWindow.java +++ b/src/com/willwinder/universalgcodesender/MainWindow.java @@ -25,6 +25,7 @@ This file is part of Universal Gcode Sender (UGS). package com.willwinder.universalgcodesender; +import com.willwinder.universalgcodesender.model.GUIBackend; import com.willwinder.universalgcodesender.i18n.Localization; import com.willwinder.universalgcodesender.listeners.ControllerListener; import com.willwinder.universalgcodesender.pendantui.PendantUI; @@ -35,7 +36,7 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.universalgcodesender.uielements.StepSizeSpinnerModel; import com.willwinder.universalgcodesender.visualizer.VisualizerWindow; import com.willwinder.universalgcodesender.Utils.Units; -import com.willwinder.universalgcodesender.listeners.ControlStateListener; +import com.willwinder.universalgcodesender.model.ControlStateListener; import java.awt.Color; import java.awt.Dimension; import java.awt.KeyEventDispatcher; @@ -1437,16 +1438,11 @@ private void opencloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//G this.backend.connect(firmware, port, baudRate); if (this.backend.getFile() != null) { - try { - this.backend.setFile(this.backend.getFile()); - } catch (Exception e) { - MainWindow.displayErrorDialog(e.getMessage()); - } if (this.vw != null) { vw.setGcodeFile(this.backend.getFile().getAbsolutePath()); } - } + // Let the command field grab focus. commandTextField.grabFocus(); } catch (Exception e) { diff --git a/src/com/willwinder/universalgcodesender/connection/ConnectionFactory.java b/src/com/willwinder/universalgcodesender/connection/ConnectionFactory.java new file mode 100644 index 0000000000..cf1b603388 --- /dev/null +++ b/src/com/willwinder/universalgcodesender/connection/ConnectionFactory.java @@ -0,0 +1,37 @@ +/* + Copywrite 2015 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.universalgcodesender.connection; + +/** + * + * @author wwinder + */ +public class ConnectionFactory { + static public Connection getConnectionFor(String address, int baud) { + return new JSSCConnection(); + + /* + if (JSSCConnection.supports(address, baud)) { + return new JSSCConnection(); + } + + return null; + */ + } +} diff --git a/src/com/willwinder/universalgcodesender/listeners/ControlStateListener.java b/src/com/willwinder/universalgcodesender/listeners/ControlStateListener.java deleted file mode 100644 index 8e1f281ad6..0000000000 --- a/src/com/willwinder/universalgcodesender/listeners/ControlStateListener.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.willwinder.universalgcodesender.listeners; - -import com.willwinder.universalgcodesender.Utils.ControlState; - -/** - * - * @author will - */ -public interface ControlStateListener { - public void ControlStateChanged(ControlState newState); -} diff --git a/src/com/willwinder/universalgcodesender/MainWindowAPI.java b/src/com/willwinder/universalgcodesender/model/BackendAPI.java similarity index 68% rename from src/com/willwinder/universalgcodesender/MainWindowAPI.java rename to src/com/willwinder/universalgcodesender/model/BackendAPI.java index c84daef206..18aa000c3f 100644 --- a/src/com/willwinder/universalgcodesender/MainWindowAPI.java +++ b/src/com/willwinder/universalgcodesender/model/BackendAPI.java @@ -1,10 +1,35 @@ -package com.willwinder.universalgcodesender; +/** + * API used by front ends to interface with the model. + */ +/* + Copywrite 2015 Will Winder + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ + +package com.willwinder.universalgcodesender.model; + +import com.willwinder.universalgcodesender.AbstractController; +import com.willwinder.universalgcodesender.Settings; +import com.willwinder.universalgcodesender.Utils; import com.willwinder.universalgcodesender.Utils.ControlState; import com.willwinder.universalgcodesender.pendantui.SystemStateBean; import java.io.File; -public interface MainWindowAPI { +public interface BackendAPI { // Config options public void setFile(File file) throws Exception; public File getFile(); diff --git a/src/com/willwinder/universalgcodesender/model/BackendAPIReadOnly.java b/src/com/willwinder/universalgcodesender/model/BackendAPIReadOnly.java new file mode 100644 index 0000000000..85e8325bce --- /dev/null +++ b/src/com/willwinder/universalgcodesender/model/BackendAPIReadOnly.java @@ -0,0 +1,61 @@ +/** + * Read only API used by front ends to interface with the model. + */ + +/* + Copywrite 2015 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.universalgcodesender.model; + +import com.willwinder.universalgcodesender.Settings; +import com.willwinder.universalgcodesender.Utils; +import com.willwinder.universalgcodesender.pendantui.SystemStateBean; +import java.io.File; + +/** + * + * @author wwinder + */ +public interface BackendAPIReadOnly { + // Config options + public File getFile(); + + // Controller status + public boolean isConnected(); + public boolean isSending(); + public boolean isPaused(); + public boolean canPause(); + public boolean canCancel(); + public boolean canSend(); + public Utils.ControlState getControlState(); + + // Send status + public long getNumRows(); + public long getNumSentRows(); + public long getNumRemainingRows(); + + public long getSendDuration(); + public long getSendRemainingDuration(); + public String getPauseResumeText(); + + // Bulk status getter. + public void updateSystemState(SystemStateBean systemStateBean); + + // Shouldn't be needed often. + public Settings getSettings(); +} diff --git a/src/com/willwinder/universalgcodesender/model/ControlStateListener.java b/src/com/willwinder/universalgcodesender/model/ControlStateListener.java new file mode 100644 index 0000000000..46e98896c9 --- /dev/null +++ b/src/com/willwinder/universalgcodesender/model/ControlStateListener.java @@ -0,0 +1,29 @@ +/* + Copywrite 2015 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.universalgcodesender.model; + +import com.willwinder.universalgcodesender.Utils.ControlState; + +/** + * + * @author wwinder + */ +public interface ControlStateListener { + public void ControlStateChanged(ControlState newState); +} diff --git a/src/com/willwinder/universalgcodesender/GUIBackend.java b/src/com/willwinder/universalgcodesender/model/GUIBackend.java similarity index 94% rename from src/com/willwinder/universalgcodesender/GUIBackend.java rename to src/com/willwinder/universalgcodesender/model/GUIBackend.java index 8895ab6dcb..af3cb70a2d 100644 --- a/src/com/willwinder/universalgcodesender/GUIBackend.java +++ b/src/com/willwinder/universalgcodesender/model/GUIBackend.java @@ -1,14 +1,30 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + Copywrite 2015 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . */ -package com.willwinder.universalgcodesender; +package com.willwinder.universalgcodesender.model; +import com.willwinder.universalgcodesender.AbstractController; +import com.willwinder.universalgcodesender.FirmwareUtils; +import com.willwinder.universalgcodesender.Settings; +import com.willwinder.universalgcodesender.Utils; import com.willwinder.universalgcodesender.Utils.ControlState; import com.willwinder.universalgcodesender.Utils.Units; import com.willwinder.universalgcodesender.i18n.Localization; -import com.willwinder.universalgcodesender.listeners.ControlStateListener; import com.willwinder.universalgcodesender.listeners.ControllerListener; import com.willwinder.universalgcodesender.pendantui.SystemStateBean; import com.willwinder.universalgcodesender.types.GcodeCommand; @@ -27,9 +43,9 @@ /** * - * @author will + * @author wwinder */ -public class GUIBackend implements MainWindowAPI, ControllerListener { +public class GUIBackend implements BackendAPI, BackendAPIReadOnly, ControllerListener { private static final Logger logger = Logger.getLogger(GUIBackend.class.getName()); private AbstractController controller = null; diff --git a/src/com/willwinder/universalgcodesender/pendantui/PendantUI.java b/src/com/willwinder/universalgcodesender/pendantui/PendantUI.java index 0bd2131914..827337e481 100644 --- a/src/com/willwinder/universalgcodesender/pendantui/PendantUI.java +++ b/src/com/willwinder/universalgcodesender/pendantui/PendantUI.java @@ -29,7 +29,7 @@ import org.eclipse.jetty.util.resource.Resource; import com.google.gson.Gson; -import com.willwinder.universalgcodesender.MainWindowAPI; +import com.willwinder.universalgcodesender.model.BackendAPI; import com.willwinder.universalgcodesender.Utils; import com.willwinder.universalgcodesender.Utils.Units; import com.willwinder.universalgcodesender.i18n.Localization; @@ -44,12 +44,12 @@ */ public class PendantUI implements ControllerListener{ private static final Logger logger = Logger.getLogger(PendantUI.class.getName()); - private MainWindowAPI mainWindow; + private BackendAPI mainWindow; private Server server = null; private int port = 8080; private SystemStateBean systemState = new SystemStateBean(); - public PendantUI(MainWindowAPI mainWindow) { + public PendantUI(BackendAPI mainWindow) { this.mainWindow = mainWindow; } @@ -303,7 +303,7 @@ public boolean isManualControlEnabled() { } } - public MainWindowAPI getMainWindow() { + public BackendAPI getMainWindow() { return mainWindow; } @@ -315,7 +315,7 @@ public void setServer(Server server) { this.server = server; } - public void setMainWindow(MainWindowAPI mainWindow) { + public void setMainWindow(BackendAPI mainWindow) { this.mainWindow = mainWindow; } diff --git a/test/com/willwinder/universalgcodesender/pendantui/PendantUITest.java b/test/com/willwinder/universalgcodesender/pendantui/PendantUITest.java index a75129d116..c68a35dd86 100644 --- a/test/com/willwinder/universalgcodesender/pendantui/PendantUITest.java +++ b/test/com/willwinder/universalgcodesender/pendantui/PendantUITest.java @@ -18,7 +18,7 @@ import com.google.gson.Gson; import com.willwinder.universalgcodesender.AbstractController; import com.willwinder.universalgcodesender.Utils.ControlState; -import com.willwinder.universalgcodesender.MainWindowAPI; +import com.willwinder.universalgcodesender.model.BackendAPI; import com.willwinder.universalgcodesender.Settings; import com.willwinder.universalgcodesender.Utils.Units; import com.willwinder.universalgcodesender.pendantui.PendantConfigBean.StepSizeOption; @@ -30,7 +30,7 @@ public class PendantUITest { private final MockUGSController controller = new MockUGSController(); private final SystemStateBean systemState = new SystemStateBean(); - public class MockMainWindow implements MainWindowAPI{ + public class MockMainWindow implements BackendAPI{ public String commandText; @Override