Skip to content

Commit

Permalink
Settings in the starting window were not reflected in preferences dia…
Browse files Browse the repository at this point in the history
…log.
  • Loading branch information
nwaldispuehl committed Jul 11, 2021
1 parent b8b2c63 commit 53eed45
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ IMP #59 Inactivates process button if no compilation is possible.
FIX #61 Fixes encoding tests in some environment by explicitly states encoding.
FIX #58 Fixes crash with wrong Java version by bundling Java with the application.
FIX #60 Fixes that in advanced pattern too long breaks with break track were swallowed.
FIX Settings in the starting window were not reflected in preferences dialog.


2019-03-05 2.9.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private void startMainProgramIn(Stage primaryStage) throws Exception {
primaryStage.setTitle(applicationData.getProgramName());
primaryStage.setScene(new Scene(root));
primaryStage.show();
primaryStage.toFront();
addProgramIconsTo(primaryStage);

mainScreenController = fxmlLoader.getController();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ch.retorte.intervalmusiccompositor.ui.firststart;

import ch.retorte.intervalmusiccompositor.commons.bundle.MessageFormatBundle;
import ch.retorte.intervalmusiccompositor.commons.preferences.UserPreferences;
import ch.retorte.intervalmusiccompositor.spi.ApplicationData;
import ch.retorte.intervalmusiccompositor.ui.preferences.UiUserPreferences;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
Expand All @@ -15,7 +15,6 @@
import javafx.stage.Stage;
import org.apache.commons.lang3.StringUtils;

import java.awt.*;
import java.io.IOException;
import java.util.Arrays;

Expand All @@ -27,122 +26,105 @@
*/
public class BlockingFirstStartWindow {

//---- Static
//---- Static

private static final String LAYOUT_FILE = "/layouts/FirstStartWindow.fxml";
private static final String LAYOUT_FILE = "/layouts/FirstStartWindow.fxml";

//---- Fields
//---- Fields

@FXML
private CheckBox checkForUpgradesOnStartupPreference;
@FXML
private CheckBox checkForUpgradesOnStartupPreference;

@FXML
private Label recentChanges;

@FXML
private VBox updateSettingsContainer;

@FXML
private Button dismissButton;
@FXML
private Label recentChanges;

private Parent parent;
private Stage stage;
private final MessageFormatBundle bundle;
private final UserPreferences userPreferences;
private final ApplicationData applicationData;
@FXML
private VBox updateSettingsContainer;

@FXML
private Button dismissButton;

//---- Constructor
private Parent parent;
private Stage stage;
private final MessageFormatBundle bundle;
private final UiUserPreferences userPreferences;
private final ApplicationData applicationData;

public BlockingFirstStartWindow(MessageFormatBundle bundle, UserPreferences userPreferences, ApplicationData applicationData) {
this.bundle = bundle;
this.userPreferences = userPreferences;
this.applicationData = applicationData;

loadFXML();
initializeControls();
}
//---- Constructor

public BlockingFirstStartWindow(MessageFormatBundle bundle, UiUserPreferences userPreferences, ApplicationData applicationData) {
this.bundle = bundle;
this.userPreferences = userPreferences;
this.applicationData = applicationData;

//---- Methods
loadFXML();
initializeControls();
}

private void loadFXML() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(LAYOUT_FILE), bundle.getBundle());
fxmlLoader.setController(this);

try {
parent = fxmlLoader.load();
parent.getStylesheets().addAll("/styles/fonts.css", "/styles/MainScreen.css");
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}

private void initializeControls() {
recentChanges.setText(removeFirstNLinesOf(3, applicationData.getChangeLog()));

/* For the node to be completely removed from the layout if hidden, we need to adapt its managed property accordingly. */
updateSettingsContainer.managedProperty().bind(updateSettingsContainer.visibleProperty());
updateSettingsContainer.setVisible(hasUnrevisedPreferences());

checkForUpgradesOnStartupPreference.selectedProperty().setValue(userPreferences.loadSearchUpdateAtStartup());
checkForUpgradesOnStartupPreference.selectedProperty().addListener((observable, oldValue, newValue) -> userPreferences.saveSearchUpdateAtStartup(newValue));

dismissButton.setOnAction(e -> {
userPreferences.setDidReviseUpdateAtStartup();
stage.close();
releaseStage();
});
}

/**
* The first lines of the change log are taken by the title. We thus cut them away.
*/
private String removeFirstNLinesOf(int n, String changeLog) {
if (StringUtils.isBlank(changeLog)) {
return "?";
}
String[] lines = changeLog.split(System.lineSeparator());
//---- Methods

if (3 < lines.length) {
private void loadFXML() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(LAYOUT_FILE), bundle.getBundle());
fxmlLoader.setController(this);

return stream(Arrays.copyOfRange(lines, n, lines.length - 1)).collect(joining(System.lineSeparator()));
try {
parent = fxmlLoader.load();
parent.getStylesheets().addAll("/styles/fonts.css", "/styles/MainScreen.css");
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
else {
return changeLog;
}
}

private boolean hasUnrevisedPreferences() {
return !userPreferences.didReviseUpdateAtStartup();
}
private void initializeControls() {
recentChanges.setText(removeFirstNLinesOf(3, applicationData.getChangeLog()));

public void show() {
stage = new Stage();
stage.setTitle(bundle.getString("ui.firstStartWindow.title"));
stage.setScene(new Scene(parent));
stage.setResizable(true);
stage.initModality(Modality.APPLICATION_MODAL);
/* For the node to be completely removed from the layout if hidden, we need to adapt its managed property accordingly. */
updateSettingsContainer.managedProperty().bind(updateSettingsContainer.visibleProperty());
updateSettingsContainer.setVisible(hasUnrevisedPreferences());

stage.show();
checkForUpgradesOnStartupPreference.selectedProperty().bindBidirectional(userPreferences.searchUpdateAtStartupProperty());

parent.layout();
dismissButton.setOnAction(e -> {
userPreferences.setDidReviseUpdateAtStartup();
stage.close();
});
}

stage.setMinWidth(stage.getWidth());
stage.setMinHeight(stage.getHeight());
/**
* The first lines of the change log are taken by the title. We thus cut them away.
*/
private String removeFirstNLinesOf(int n, String changeLog) {
if (StringUtils.isBlank(changeLog)) {
return "?";
}
String[] lines = changeLog.split(System.lineSeparator());

if (3 < lines.length) {

return stream(Arrays.copyOfRange(lines, n, lines.length - 1)).collect(joining(System.lineSeparator()));
} else {
return changeLog;
}
}

private boolean hasUnrevisedPreferences() {
return !userPreferences.didReviseUpdateAtStartup();
}

stage.setOnCloseRequest(event -> releaseStage());
blockStage();
}
public void show() {
stage = new Stage();
stage.setTitle(bundle.getString("ui.firstStartWindow.title"));
stage.setScene(new Scene(parent));
stage.setResizable(true);
stage.initModality(Modality.APPLICATION_MODAL);

private void blockStage() {
// TODO: Implement
// Toolkit.getToolkit().enterNestedEventLoop(stage);
}
stage.showAndWait();

private void releaseStage() {
// TODO: Implement
// Toolkit.getToolkit().exitNestedEventLoop(stage, null);
}
parent.layout();

stage.setMinWidth(stage.getWidth());
stage.setMinHeight(stage.getHeight());
}
}
Loading

0 comments on commit 53eed45

Please sign in to comment.