Merge branch 'feat/settings_cancel' into 'master'
Feature: Add a "Cancel" option to the settings activity See merge request sheepitrenderfarm/client!178
This commit is contained in:
@@ -100,6 +100,7 @@ public class Settings implements Activity {
|
|||||||
|
|
||||||
private JCheckBox saveFile;
|
private JCheckBox saveFile;
|
||||||
private JCheckBox autoSignIn;
|
private JCheckBox autoSignIn;
|
||||||
|
JButton cancelButton;
|
||||||
JButton saveButton;
|
JButton saveButton;
|
||||||
|
|
||||||
private boolean haveAutoStarted;
|
private boolean haveAutoStarted;
|
||||||
@@ -497,7 +498,8 @@ public class Settings implements Activity {
|
|||||||
// general settings
|
// general settings
|
||||||
JPanel general_panel = new JPanel(new GridLayout(1, 2));
|
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);
|
general_panel.add(saveFile);
|
||||||
|
|
||||||
autoSignIn = new JCheckBox("Auto sign in", config.isAutoSignIn());
|
autoSignIn = new JCheckBox("Auto sign in", config.isAutoSignIn());
|
||||||
@@ -511,24 +513,33 @@ public class Settings implements Activity {
|
|||||||
parent.getContentPanel().add(general_panel, constraints);
|
parent.getContentPanel().add(general_panel, constraints);
|
||||||
|
|
||||||
currentRow++;
|
currentRow++;
|
||||||
|
constraints.gridx = 0;
|
||||||
constraints.gridy = currentRow;
|
constraints.gridy = currentRow;
|
||||||
|
constraints.gridwidth = 2;
|
||||||
parent.getContentPanel().add(new JLabel(" "), constraints); // Add a separator between last checkboxes and button
|
parent.getContentPanel().add(new JLabel(" "), constraints); // Add a separator between last checkboxes and button
|
||||||
|
|
||||||
currentRow++;
|
// Close buttons (Discard / Save)
|
||||||
String buttonText = "Start";
|
// Only show Discard button if there is a client running to close back to
|
||||||
if (parent.getClient() != null) {
|
boolean isClientRunning = parent.getClient() != null && parent.getClient().isRunning();
|
||||||
if (parent.getClient().isRunning()) {
|
int savePanelCols = isClientRunning ? 2 : 1;
|
||||||
buttonText = "Save";
|
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);
|
saveButton = new JButton("Save & go back");
|
||||||
checkDisplaySaveButton();
|
checkDisplaySaveButton(); // Sets the button text and enabled state
|
||||||
saveButton.addActionListener(new SaveAction());
|
saveButton.addActionListener(new SaveAction());
|
||||||
|
savePanel.add(saveButton);
|
||||||
|
|
||||||
currentRow++;
|
currentRow++;
|
||||||
constraints.gridwidth = 2;
|
constraints.gridwidth = 2;
|
||||||
constraints.gridx = 0;
|
constraints.gridx = 0;
|
||||||
constraints.gridy = currentRow;
|
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.
|
// Increase the size of the app Window to ensure it shows all the information with the Advanced Options panel opened.
|
||||||
parent.setSize(520,850);
|
parent.setSize(520,850);
|
||||||
@@ -553,6 +564,20 @@ public class Settings implements Activity {
|
|||||||
selected = false;
|
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);
|
saveButton.setEnabled(selected);
|
||||||
return 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 {
|
class SaveAction implements ActionListener {
|
||||||
|
|
||||||
@Override public void actionPerformed(ActionEvent e) {
|
@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 {
|
class JCheckBoxGPU extends JCheckBox {
|
||||||
private GPUDevice gpu;
|
private GPUDevice gpu;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user