Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix changing the font size not working when importing preferences #2069

Merged
merged 9 commits into from
Oct 11, 2016
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed InvalidBackgroundColor flickering with Ctrl-s and File > Save database
- Fixed loop when pulling changes (shared database) when current selected field has changed
- Fixed [#1958](https://github.com/JabRef/jabref/issues/1958): Verbatim fields are no longer checked for HTML encoded characters by integrity checks
- Fixed [#1808](https://github.com/JabRef/jabref/issues/1808): Font preference dialog now keeps changes
- Fixed [#1937](https://github.com/JabRef/jabref/issues/1937): If no help page for the current chosen language exists, the english help page will be shown
- Fixed [#2060](https://github.com/JabRef/jabref/issues/2060): Medline fetcher now imports data in UTF-8 encoding
- Fixed file menu displays wrong hotkey in the German translation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public AppearancePrefsTab(JabRefPreferences prefs) {
overrideFonts.addActionListener(e -> fontSize.setEnabled(overrideFonts.isSelected()));

fontButton.addActionListener(
e -> new FontSelectorDialog(null, GUIGlobals.currentFont).getSelectedFont().ifPresent(x -> usedFont = x));
e -> new FontSelectorDialog(null, usedFont).getSelectedFont().ifPresent(x -> usedFont = x));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problematic part may be the ifPresent, as I am not sure if you can reassign a variable usedFont within a lambda x -> usedFont = x so that it x will be accessible from the outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to work, since when I open the font selector again, the new value is assigned for usedFont and gets selected in the list. This did not work before as @oscargus mentioned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


JPanel pan = builder.getPanel();
pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
Expand Down
85 changes: 50 additions & 35 deletions src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
* Preferences dialog. Contains a TabbedPane, and tabs will be defined in
* separate classes. Tabs MUST implement the PrefsTab interface, since this
Expand Down Expand Up @@ -153,21 +154,7 @@ public PreferencesDialog(JabRefFrame parent) {

// Import and export actions:
exportPreferences.setToolTipText(Localization.lang("Export preferences to file"));
exportPreferences.addActionListener(e -> {
FileDialog dialog = new FileDialog(frame).withExtension(FileExtensions.XML);
dialog.setDefaultExtension(FileExtensions.XML);
Optional<Path> path = dialog.saveNewFile();

path.ifPresent(exportFile -> {
try {
prefs.exportPreferences(exportFile.toString());
} catch (JabRefException ex) {
LOGGER.warn(ex.getMessage(), ex);
JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
Localization.lang("Export preferences"), JOptionPane.ERROR_MESSAGE);
}
});
});
exportPreferences.addActionListener(new ExportAction());

importPreferences.setToolTipText(Localization.lang("Import preferences from file"));
importPreferences.addActionListener(e -> {
Expand All @@ -182,6 +169,7 @@ public PreferencesDialog(JabRefFrame parent) {
JOptionPane.showMessageDialog(PreferencesDialog.this,
Localization.lang("You must restart JabRef for this to come into effect."),
Localization.lang("Import preferences"), JOptionPane.WARNING_MESSAGE);
this.dispose();
} catch (JabRefException ex) {
LOGGER.warn(ex.getMessage(), ex);
JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
Expand All @@ -191,7 +179,7 @@ public PreferencesDialog(JabRefFrame parent) {
});

showPreferences.addActionListener(
e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame).setVisible(true));
e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(prefs), frame).setVisible(true));
resetPreferences.addActionListener(e -> {
if (JOptionPane.showConfirmDialog(PreferencesDialog.this,
Localization.lang("Are you sure you want to reset all settings to default values?"),
Expand Down Expand Up @@ -229,6 +217,28 @@ private void updateAfterPreferenceChanges() {
Globals.prefs.updateEntryEditorTabList();
}

private void storeAllSettings(){
// First check that all tabs are ready to close:
Component[] preferenceTabs = main.getComponents();
for (Component tab: preferenceTabs) {
if (!((PrefsTab) tab).validateSettings()) {
return; // If not, break off.
}
}
// Then store settings and close:
for (Component tab: preferenceTabs) {
((PrefsTab) tab).storeSettings();
}
Globals.prefs.flush();

setVisible(false);
MainTable.updateRenderers();
GUIGlobals.updateEntryEditorColors();
frame.setupAllTables();
frame.getGroupSelector().revalidateGroups(); // icons may have changed
frame.output(Localization.lang("Preferences recorded."));
}


class OkAction extends AbstractAction {

Expand All @@ -238,27 +248,32 @@ public OkAction() {

@Override
public void actionPerformed(ActionEvent e) {
storeAllSettings();
}
}

// First check that all tabs are ready to close:
int count = main.getComponentCount();
Component[] comps = main.getComponents();
for (int i = 0; i < count; i++) {
if (!((PrefsTab) comps[i]).validateSettings()) {
return; // If not, break off.
}
}
// Then store settings and close:
for (int i = 0; i < count; i++) {
((PrefsTab) comps[i]).storeSettings();
}
Globals.prefs.flush();
class ExportAction extends AbstractAction {

setVisible(false);
MainTable.updateRenderers();
GUIGlobals.updateEntryEditorColors();
frame.setupAllTables();
frame.getGroupSelector().revalidateGroups(); // icons may have changed
frame.output(Localization.lang("Preferences recorded."));
public ExportAction() {
super("Export");
}

@Override
public void actionPerformed(ActionEvent e) {
FileDialog dialog = new FileDialog(frame).withExtension(FileExtensions.XML);
dialog.setDefaultExtension(FileExtensions.XML);
Optional<Path> path = dialog.saveNewFile();

path.ifPresent(exportFile -> {
try {
storeAllSettings();
Globals.prefs.exportPreferences(exportFile.toString());
} catch (JabRefException ex) {
LOGGER.warn(ex.getMessage(), ex);
JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
Localization.lang("Export preferences"), JOptionPane.WARNING_MESSAGE);
}
});
}
}

Expand Down