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

Add Driver selector to Connection setup wizard #2436

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.universalgcodesender.utils.FirmwareUtils;
import net.miginfocom.swing.MigLayout;

import java.awt.Dimension;
import javax.swing.*;

public class ConnectionPanel extends JPanel implements UGSEventListener {
private final transient BackendAPI backend;
private final JComboBox<String> driverCombo;
private final JComboBox<String> firmwareCombo;
private final JComboBox<String> baudCombo;
private final PortComboBox portCombo;
Expand All @@ -46,10 +48,17 @@ public ConnectionPanel(BackendAPI backend, Runnable onConnect) {

JLabel labelDescription = new JLabel("<html><body><p>" + Localization.getString("platform.plugin.setupwizard.connection.intro") + "</p></body></html>");

// Driver options
driverCombo = new JComboBox<>(ConnectionDriver.getPrettyNames());
driverCombo.addActionListener(d -> this.setDriver());
JLabel labelDriver = new JLabel(Localization.getString("settings.connectionDriver"));
labelDriver.setToolTipText("Select the driver to use to connect to your controller firmware. Serial connections should use JSerialComm. Network connections should use TCP.");

// Firmware options
firmwareCombo = new JComboBox<>();
firmwareCombo.addActionListener(a -> setFirmware());
JLabel labelFirmware = new JLabel("Firmware:");
JLabel labelFirmware = new JLabel(Localization.getString("mainWindow.swing.firmwareLabel"));
labelFirmware.setToolTipText("Select the controller firmware to which you want to connect.");

// Baud rate options
baudCombo = new BaudComboBox(backend);
Expand All @@ -63,18 +72,26 @@ public ConnectionPanel(BackendAPI backend, Runnable onConnect) {
JButton connectButton = new JButton(Localization.getString("platform.plugin.setupwizard.connect"));
connectButton.addActionListener(e -> onConnect.run());

add(labelDescription, "growx, wrap, gapbottom 10");
add(labelDescription, "growx, wrap, gapbottom 5");
add(labelDriver, "wrap");
add(driverCombo, "wmin 250, wmax 250, hmax 24, wrap, gapbottom 5");
add(labelFirmware, "wrap");
add(firmwareCombo, "wmin 250, wmax 250, hmax 24, wrap, gapbottom 10");
add(firmwareCombo, "wmin 250, wmax 250, hmax 24, wrap, gapbottom 5");
add(labelPort, "wrap");
add(portCombo, "wmin 250, wmax 250, hmax 24, wrap, gapbottom 10");
add(portCombo, "wmin 250, wmax 250, hmax 24, wrap, gapbottom 5");
add(labelBaud, "wrap");
add(baudCombo, "wmin 250, wmax 250, hmax 24, wrap, gapbottom 20");
add(baudCombo, "wmin 250, wmax 250, hmax 24, wrap, gapbottom 10");
add(connectButton, "wmin 250, wmax 250, hmin 36, wrap");

updateLabels();
}

private void setDriver() {
if (backend.getSettings() != null && driverCombo.getSelectedItem() != null) {
backend.getSettings().setConnectionDriver(ConnectionDriver.prettyNameToEnum(driverCombo.getSelectedItem().toString()));
}
}

private void setPort() {
if (backend.getSettings() != null && portCombo.getSelectedItem() != null) {
backend.getSettings().setPort(portCombo.getSelectedItem().toString());
Expand Down Expand Up @@ -106,11 +123,22 @@ private void refreshFirmwares() {
firmwareCombo.setSelectedItem(selectedFirmware);
}

private void refreshDrivers() {
String selectedDriver = backend.getSettings().getConnectionDriver().getPrettyName();
driverCombo.removeAllItems();
String[] drivers = ConnectionDriver.getPrettyNames();
for (String s: drivers) {
driverCombo.addItem(s);
}
driverCombo.setSelectedItem(selectedDriver);
}

@Override
public void setVisible(boolean visible) {
super.setVisible(visible);

if (visible) {
refreshDrivers();
refreshFirmwares();
firmwareUpdated();
portCombo.startRefreshing();
Expand Down