Skip to content

Commit

Permalink
Add Driver selector to Connection setup wizard (#2436)
Browse files Browse the repository at this point in the history
* Add Driver selector to Connection setup wizard
* Remove explicit preferred size.
* Fix spacing issue so Connect button is visible
  • Loading branch information
shampeon authored Jan 23, 2024
1 parent 5feaebe commit 494e985
Showing 1 changed file with 33 additions and 5 deletions.
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

0 comments on commit 494e985

Please sign in to comment.