Skip to content

Commit

Permalink
Moved some things around to better organize an model API package.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Mar 3, 2015
1 parent 0b8484f commit dfb334f
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 39 deletions.
1 change: 1 addition & 0 deletions manifest.mf
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions src/com/willwinder/universalgcodesender/MainWindow.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
*/
}
}

This file was deleted.

@@ -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 <http://www.gnu.org/licenses/>.
*/

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();
Expand Down
@@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender.model;

import com.willwinder.universalgcodesender.Utils.ControlState;

/**
*
* @author wwinder
*/
public interface ControlStateListener {
public void ControlStateChanged(ControlState newState);
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/com/willwinder/universalgcodesender/pendantui/PendantUI.java
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -303,7 +303,7 @@ public boolean isManualControlEnabled() {
}
}

public MainWindowAPI getMainWindow() {
public BackendAPI getMainWindow() {
return mainWindow;
}

Expand All @@ -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;
}

Expand Down
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit dfb334f

Please sign in to comment.