GP-4172 simplified theme switcher dialog. Also added in double click to pick and exit

This commit is contained in:
ghidragon
2024-01-10 11:55:34 -05:00
parent 6d7ac958d7
commit e98aac1e67
2 changed files with 10 additions and 21 deletions
@@ -32,10 +32,10 @@
<P align="center"><IMG alt="" src="images/ThemeChooserDialog.png"><BR>
&nbsp;</P>
<P>The Theme Chooser dialog displays a list of all the know themes, both built-in and custom.
As you pick different themes, the application will switch to that theme. Press the "OK" button
when the desired theme is selected. Pressing the "Cancel" button will restore the theme to
the what it was when the dialog was invoked.</P>
<P>The Theme Chooser dialog displays a list of all the known themes, both built-in and custom.
Select the desired theme and press the "OK" button to have the application switch to that
theme. Pressing the "Cancel" button will exit the dialog without changing the theme. You
can also double click on a theme to switch to that theme and exit the dialog.</P>
</BlOCKQUOTE>
@@ -35,22 +35,21 @@ public class ThemeChooserDialog extends DialogComponentProvider {
public ThemeChooserDialog(ThemeManager themeManager) {
super("Change Theme");
this.themeManager = themeManager;
addWorkPanel(buildMainPanel());
addOKButton();
addApplyButton();
addCancelButton();
setRememberSize(false);
setHelpLocation(new HelpLocation("Theming", "Switch_Theme"));
updateOkApplyButtons();
updateButtonEnablement();
}
private void updateOkApplyButtons() {
private void updateButtonEnablement() {
GTheme selectedValue = listPanel.getSelectedValue();
GTheme currentTheme = themeManager.getActiveTheme();
boolean canApplyTheme = selectedValue != null && !currentTheme.equals(selectedValue);
setOkEnabled(canApplyTheme);
setApplyEnabled(canApplyTheme);
}
@Override
@@ -59,22 +58,12 @@ public class ThemeChooserDialog extends DialogComponentProvider {
close();
}
@Override
protected void applyCallback() {
applyTheme();
}
private void applyTheme() {
GTheme selectedValue = listPanel.getSelectedValue();
if (selectedValue == null) {
return;
}
GTheme activeTheme = themeManager.getActiveTheme();
if (selectedValue != activeTheme) {
if (selectedValue != null && selectedValue != activeTheme) {
Swing.runLater(() -> themeManager.setTheme(selectedValue));
}
setOkEnabled(false);
setApplyEnabled(false);
}
protected void cancelCallback() {
@@ -93,12 +82,12 @@ public class ThemeChooserDialog extends DialogComponentProvider {
listPanel.setSelectedValue(activeTheme);
listPanel.addListSelectionListener(e -> selectionChanged());
panel.add(listPanel);
listPanel.setDoubleClickActionListener(e -> okCallback());
return panel;
}
private void selectionChanged() {
updateOkApplyButtons();
updateButtonEnablement();
}
private class ThemeListModel extends AbstractListModel<GTheme> {