Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setting for changing pendant web port. #1860

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public UGSSettingsDialog(String settingsTitle, AbstractUGSSettings panel, Frame
initComponents();
setLocationRelativeTo(parent);

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
saveChanges = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ConnectionSettingsPanel extends AbstractUGSSettings {
Localization.getString("sender.nightly-warning"));
private final Checkbox autoStartPendant = new Checkbox(
Localization.getString("sender.autostartpendant"));
private final Textfield pendantPort = new Textfield(Localization.getString("settings.pendantPort"));
private final JComboBox<Language> languageCombo = new JComboBox<>(AvailableLanguages.getAvailableLanguages().toArray(new Language[0]));
private final JComboBox<String> connectionDriver = new JComboBox<>(ConnectionDriver.getPrettyNames());
private final JTextField workspaceDirectory = new JTextField();
Expand Down Expand Up @@ -92,6 +93,7 @@ public void save() {
//settings.setAutoConnectEnabled(autoConnect.getValue());
settings.setShowNightlyWarning(showNightlyWarning.getValue());
settings.setAutoStartPendant(autoStartPendant.getValue());
settings.setPendantPort(Integer.parseInt(pendantPort.getValue().toString()));
settings.setLanguage(((Language) languageCombo.getSelectedItem()).getLanguageCode());
settings.setConnectionDriver(ConnectionDriver.prettyNameToEnum(connectionDriver.getSelectedItem().toString()));
settings.setWorkspaceDirectory(workspaceDirectory.getText());
Expand Down Expand Up @@ -134,6 +136,9 @@ protected void updateComponentsInternal(Settings s) {
autoStartPendant.setSelected(s.isAutoStartPendant());
add(autoStartPendant, "spanx, wrap");

pendantPort.setValue(String.valueOf(s.getPendantPort()));
add(pendantPort, "spanx, grow");

for (int i = 0; i < languageCombo.getItemCount(); i++) {
Language l = languageCombo.getItemAt(i);
if (l.getLanguageCode().equals(s.getLanguage())) {
Expand All @@ -151,8 +156,8 @@ protected void updateComponentsInternal(Settings s) {

workspaceDirectory.setText(settings.getWorkspaceDirectory());
JPanel panel = new JPanel();
panel.setLayout(new MigLayout("insets 0", "fill"));
panel.add(workspaceDirectory, "gapright 0");
panel.setLayout(new MigLayout("insets 0, fill"));
panel.add(workspaceDirectory, "grow");
panel.add(workspaceDirectoryBrowseButton);
workspaceDirectoryBrowseButton.setAction(createBrowseDirectoryAction());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class Settings {
private boolean showNightlyWarning = true;
private boolean showSerialPortWarning = true;
private boolean autoStartPendant = false;
private int pendantPort = 8080;
private boolean autoConnect = false;
private boolean autoReconnect = false;

Expand Down Expand Up @@ -523,6 +524,15 @@ public void setSafetyHeight(double safetyHeight) {
this.safetyHeight = safetyHeight;
}

public int getPendantPort() {
return pendantPort;
}

public void setPendantPort(int pendantPort) {
this.pendantPort = pendantPort;
changed();
}

public static class AutoLevelSettings {
// Setting window
public double autoLevelProbeZeroHeight = 0;
Expand Down
1 change: 1 addition & 0 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ settings.connectionDriver = Connection driver
settings.workspaceDirectory = Workspace directory
settings.help.disableAxis = Each disabled axis is removed from the UI when possible.
settings.disableAxis = Disable axis: %s
settings.pendantPort = Pendant web port
ArcExpander = Arc Expander
CommandLengthProcessor = Command Length Processor
CommandSplitter = Command Splitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.universalgcodesender.pendantui;

import com.willwinder.universalgcodesender.listeners.UGSEventListener;
import com.willwinder.universalgcodesender.model.BackendAPI;
import com.willwinder.universalgcodesender.model.UGSEvent;
import com.willwinder.universalgcodesender.model.events.SettingChangedEvent;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
import org.eclipse.jetty.server.Handler;
Expand Down Expand Up @@ -47,15 +50,16 @@ This file is part of Universal Gcode Sender (UGS).
*
* @author bobj
*/
public class PendantUI {
private BackendAPI mainWindow;
public class PendantUI implements UGSEventListener {
private BackendAPI backendAPI;
private Server server = null;
private int port = 8080;
private static final Logger LOG = Logger.getLogger(PendantUI.class.getSimpleName());

public PendantUI(BackendAPI mainWindow) {
this.mainWindow = mainWindow;
BackendAPIFactory.getInstance().register(mainWindow);
public PendantUI(BackendAPI backendAPI) {
this.backendAPI = backendAPI;
backendAPI.addUGSEventListener(this);
BackendAPIFactory.getInstance().register(backendAPI);
}

public Resource getBaseResource(String directory) {
Expand All @@ -74,6 +78,7 @@ public Resource getBaseResource(String directory) {
* @return the url for the pendant interface
*/
public List<PendantURLBean> start() {
int port = backendAPI.getSettings().getPendantPort();
server = new Server(port);

ResourceHandler staticResourceHandler = new ResourceHandler();
Expand Down Expand Up @@ -149,19 +154,25 @@ public void stop() {
}
}

public int getPort() {
return port;
public boolean isStarted() {
return server != null && server.isStarted();
}

public void setPort(int port) {
this.port = port;
public BackendAPI getBackendAPI() {
return backendAPI;
}

public BackendAPI getMainWindow() {
return mainWindow;
public void setBackendAPI(BackendAPI backendAPI) {
this.backendAPI = backendAPI;
}

public void setMainWindow(BackendAPI mainWindow) {
this.mainWindow = mainWindow;
@Override
public void UGSEvent(UGSEvent evt) {
if (evt instanceof SettingChangedEvent) {
if (backendAPI.getSettings().getPendantPort() != port && isStarted()) {
stop();
start();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void setup(){
}
@Test
public void testPendantUI() {
assertSame(mockBackend, pendantUI.getMainWindow());
assertSame(mockBackend, pendantUI.getBackendAPI());
}

@Test
Expand All @@ -32,16 +32,4 @@ public void testGetUrl() {
assertTrue(test.startsWith("http://"));
assertTrue(test.contains("8080"));
}

@Test
public void testGetPort() {
pendantUI.setPort(999);
assertEquals(999, pendantUI.getPort());
}

@Test
public void testSetPort() {
pendantUI.setPort(999);
assertEquals(999, pendantUI.getPort());
}
}