diff --git a/src/main/java/com/sheepit/client/standalone/swing/activity/Settings.java b/src/main/java/com/sheepit/client/standalone/swing/activity/Settings.java index 3e181e7..1ad45d0 100644 --- a/src/main/java/com/sheepit/client/standalone/swing/activity/Settings.java +++ b/src/main/java/com/sheepit/client/standalone/swing/activity/Settings.java @@ -100,6 +100,7 @@ public class Settings implements Activity { private JCheckBox saveFile; private JCheckBox autoSignIn; + JButton cancelButton; JButton saveButton; private boolean haveAutoStarted; @@ -497,7 +498,8 @@ public class Settings implements Activity { // general settings JPanel general_panel = new JPanel(new GridLayout(1, 2)); - saveFile = new JCheckBox("Save settings", true); + saveFile = new JCheckBox("Write settings to file", true); + saveFile.addActionListener(new SaveSettingsFileAction()); general_panel.add(saveFile); autoSignIn = new JCheckBox("Auto sign in", config.isAutoSignIn()); @@ -511,24 +513,33 @@ public class Settings implements Activity { parent.getContentPanel().add(general_panel, constraints); currentRow++; + constraints.gridx = 0; constraints.gridy = currentRow; + constraints.gridwidth = 2; parent.getContentPanel().add(new JLabel(" "), constraints); // Add a separator between last checkboxes and button - currentRow++; - String buttonText = "Start"; - if (parent.getClient() != null) { - if (parent.getClient().isRunning()) { - buttonText = "Save"; - } + // Close buttons (Discard / Save) + // Only show Discard button if there is a client running to close back to + boolean isClientRunning = parent.getClient() != null && parent.getClient().isRunning(); + int savePanelCols = isClientRunning ? 2 : 1; + JPanel savePanel = new JPanel(new GridLayout(1, savePanelCols)); + + if (isClientRunning) { + cancelButton = new JButton("Discard & go back"); + cancelButton.addActionListener(new CancelAction()); + savePanel.add(cancelButton); } - saveButton = new JButton(buttonText); - checkDisplaySaveButton(); + + saveButton = new JButton("Save & go back"); + checkDisplaySaveButton(); // Sets the button text and enabled state saveButton.addActionListener(new SaveAction()); + savePanel.add(saveButton); + currentRow++; constraints.gridwidth = 2; constraints.gridx = 0; constraints.gridy = currentRow; - parent.getContentPanel().add(saveButton, constraints); + parent.getContentPanel().add(savePanel, constraints); // Increase the size of the app Window to ensure it shows all the information with the Advanced Options panel opened. parent.setSize(520,850); @@ -553,6 +564,20 @@ public class Settings implements Activity { selected = false; } + boolean isClientRunning = parent.getClient() != null && parent.getClient().isRunning(); + if (isClientRunning) { + if (saveFile.isSelected()) { + saveButton.setText("Save & go back"); + } else { + saveButton.setText("Apply & go back"); + } + } else { + if (saveFile.isSelected()) { + saveButton.setText("Save & start"); + } else { + saveButton.setText("Apply & start"); + } + } saveButton.setEnabled(selected); return selected; } @@ -641,6 +666,24 @@ public class Settings implements Activity { } } + class CancelAction implements ActionListener { + + @Override public void actionPerformed(ActionEvent e) { + if (parent == null) { + return; + } + + Configuration config = parent.getConfiguration(); + if (config == null) { + return; + } + + applyTheme(config.getTheme()); // apply the proper theme (light/dark) + + parent.showActivity(GuiSwing.ActivityType.WORKING); + } + } + class SaveAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { @@ -813,6 +856,13 @@ public class Settings implements Activity { } } + class SaveSettingsFileAction implements ActionListener { + + @Override public void actionPerformed(ActionEvent e) { + checkDisplaySaveButton(); + } + } + class JCheckBoxGPU extends JCheckBox { private GPUDevice gpu;