use of qupath.lib.gui.commands.Commands in project qupath by qupath.
the class QuPathGUI method showSetupDialog.
/**
* Show a dialog requesting setup parameters
*
* @return
*/
public boolean showSetupDialog() {
// Show a setup message
Dialog<ButtonType> dialog = new Dialog<>();
dialog.setTitle("QuPath setup");
dialog.initOwner(getStage());
// Try to get an image to display
Image img = loadIcon(128);
BorderPane pane = new BorderPane();
if (img != null) {
StackPane imagePane = new StackPane(new ImageView(img));
imagePane.setPadding(new Insets(10, 10, 10, 10));
pane.setLeft(imagePane);
}
Map<String, Locale> localeMap = Arrays.stream(Locale.getAvailableLocales()).collect(Collectors.toMap(l -> l.getDisplayName(Locale.US), l -> l));
localeMap.remove("");
List<String> localeList = new ArrayList<>(localeMap.keySet());
Collections.sort(localeList);
long maxMemoryMB = Runtime.getRuntime().maxMemory() / 1024 / 1024;
String maxMemoryString = String.format("Current maximum memory is %.2f GB.", maxMemoryMB / 1024.0);
boolean canSetMemory = PathPrefs.hasJavaPreferences();
ParameterList paramsSetup = new ParameterList().addTitleParameter("Memory");
double originalMaxMemory = Math.ceil(maxMemoryMB / 1024.0);
if (canSetMemory) {
paramsSetup.addEmptyParameter("Set the maximum memory used by QuPath.");
// .addEmptyParameter(maxMemoryString);
boolean lowMemory = maxMemoryMB < 1024 * 6;
if (lowMemory) {
paramsSetup.addEmptyParameter("It is suggested to increase the memory limit to approximately\nhalf of the RAM available on your computer.");
}
paramsSetup.addDoubleParameter("maxMemoryGB", "Maximum memory", originalMaxMemory, "GB", "Set the maximum memory for Java.\n" + "Note that some commands (e.g. pixel classification) may still use more memory when needed,\n" + "so this value should generally not exceed half the total memory available on the system.");
} else {
paramsSetup.addEmptyParameter(maxMemoryString).addEmptyParameter("Sorry, I can't access the config file needed to change the max memory.\n" + "See the QuPath installation instructions for more details.");
}
paramsSetup.addTitleParameter("Region").addEmptyParameter("Set the region for QuPath to use for displaying numbers and messages.\n" + "Note: It is *highly recommended* to keep the default (English, US) region settings.\n" + "Support for regions that use different number formatting (e.g. commas as decimal marks)\n" + "is still experimental, and may give unexpected results.").addChoiceParameter("localeFormatting", "Numbers & dates", Locale.getDefault(Category.FORMAT).getDisplayName(), localeList, "Choose region settings used to format numbers and dates").addTitleParameter("Updates").addBooleanParameter("checkForUpdates", "Check for updates on startup (recommended)", PathPrefs.doAutoUpdateCheckProperty().get(), "Specify whether to automatically prompt to download the latest QuPath on startup (required internet connection)");
ParameterPanelFX parameterPanel = new ParameterPanelFX(paramsSetup);
pane.setCenter(parameterPanel.getPane());
Label labelMemory;
if (canSetMemory) {
labelMemory = new Label("You will need to restart QuPath for memory changes to take effect");
labelMemory.setStyle("-fx-font-weight: bold;");
labelMemory.setMaxWidth(Double.MAX_VALUE);
labelMemory.setAlignment(Pos.CENTER);
labelMemory.setFont(Font.font("Arial"));
labelMemory.setPadding(new Insets(10, 10, 10, 10));
pane.setBottom(labelMemory);
}
// dialog.initStyle(StageStyle.UNDECORATED);
dialog.getDialogPane().setContent(pane);
dialog.getDialogPane().getButtonTypes().setAll(ButtonType.APPLY, ButtonType.CANCEL);
Optional<ButtonType> result = dialog.showAndWait();
if (!result.isPresent() || !ButtonType.APPLY.equals(result.get()))
return false;
Locale localeFormatting = localeMap.get(paramsSetup.getChoiceParameterValue("localeFormatting"));
// Locale localeDisplay = localeMap.get(paramsSetup.getChoiceParameterValue("localeDisplay"));
PathPrefs.defaultLocaleFormatProperty().set(localeFormatting);
// PathPrefs.defaultLocaleDisplayProperty().set(localeDisplay);
PathPrefs.doAutoUpdateCheckProperty().set(paramsSetup.getBooleanParameterValue("checkForUpdates"));
if (canSetMemory && paramsSetup.containsKey("maxMemoryGB")) {
int maxMemorySpecifiedMB = (int) (Math.round(paramsSetup.getDoubleParameterValue("maxMemoryGB") * 1024));
if (maxMemorySpecifiedMB >= 1024) {
PathPrefs.maxMemoryMBProperty().set(maxMemorySpecifiedMB);
} else {
if (maxMemorySpecifiedMB >= 0)
Dialogs.showErrorNotification("Max memory setting", "Specified maximum memory setting too low - it must be at least 1 GB");
else
logger.warn("Requested max memory must be at least 1 GB - specified value {} will be ignored", paramsSetup.getDoubleParameterValue("maxMemoryGB"));
// PathPrefs.maxMemoryMBProperty().set(-1);
}
}
// Try to update display
if (getStage() != null && getStage().isShowing())
updateListsAndTables(getStage().getScene().getRoot());
return true;
}
Aggregations