use of org.jabref.logic.citationstyle.CitationStyle in project jabref by JabRef.
the class PreviewPanel method updateLayout.
public void updateLayout() {
if (fixedLayout) {
LOGGER.debug("cannot change the layout because the layout is fixed");
return;
}
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
String style = previewPreferences.getPreviewCycle().get(previewPreferences.getPreviewCyclePosition());
if (CitationStyle.isCitationStyleFile(style)) {
if (basePanel.isPresent()) {
layout = Optional.empty();
CitationStyle citationStyle = CitationStyle.createCitationStyleFromFile(style);
if (citationStyle != null) {
basePanel.get().getCitationStyleCache().setCitationStyle(citationStyle);
basePanel.get().output(Localization.lang("Preview style changed to: %0", citationStyle.getTitle()));
}
}
} else {
updatePreviewLayout(previewPreferences.getPreviewStyle());
if (basePanel.isPresent()) {
basePanel.get().output(Localization.lang("Preview style changed to: %0", Localization.lang("Preview")));
}
}
update();
}
use of org.jabref.logic.citationstyle.CitationStyle in project jabref by JabRef.
the class PreviewPrefsTab method storeSettings.
@Override
public void storeSettings() {
List<String> styles = new ArrayList<>();
Enumeration<Object> elements = chosenModel.elements();
while (elements.hasMoreElements()) {
Object obj = elements.nextElement();
if (obj instanceof CitationStyle) {
styles.add(((CitationStyle) obj).getFilepath());
} else if (obj instanceof String) {
styles.add("Preview");
}
}
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences().getBuilder().withPreviewCycle(styles).withPreviewStyle(layout.getText().replace("\n", "__NEWLINE__")).build();
Globals.prefs.storePreviewPreferences(previewPreferences);
// update preview
for (BasePanel basePanel : JabRefGUI.getMainFrame().getBasePanelList()) {
basePanel.getPreviewPanel().updateLayout();
}
}
use of org.jabref.logic.citationstyle.CitationStyle in project jabref by JabRef.
the class PreviewPrefsTab method setValues.
@Override
public void setValues() {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
chosenModel.clear();
boolean isPreviewChosen = false;
for (String style : previewPreferences.getPreviewCycle()) {
if (CitationStyle.isCitationStyleFile(style)) {
chosenModel.addElement(CitationStyle.createCitationStyleFromFile(style));
} else {
if (isPreviewChosen) {
LOGGER.error("Preview is already in the list, something went wrong");
continue;
}
isPreviewChosen = true;
chosenModel.addElement(Localization.lang("Preview"));
}
}
availableModel.clear();
if (!isPreviewChosen) {
availableModel.addElement(Localization.lang("Preview"));
}
btnLeft.setEnabled(!chosen.isSelectionEmpty());
btnRight.setEnabled(!available.isSelectionEmpty());
btnUp.setEnabled(!chosen.isSelectionEmpty());
btnDown.setEnabled(!chosen.isSelectionEmpty());
if (discoverCitationStyleWorker != null) {
discoverCitationStyleWorker.cancel(true);
}
discoverCitationStyleWorker = new SwingWorker<List<CitationStyle>, Void>() {
@Override
protected List<CitationStyle> doInBackground() throws Exception {
return CitationStyle.discoverCitationStyles();
}
@Override
public void done() {
if (this.isCancelled()) {
return;
}
try {
get().stream().filter(style -> !previewPreferences.getPreviewCycle().contains(style.getFilepath())).sorted((style0, style1) -> style0.getTitle().compareTo(style1.getTitle())).forEach(availableModel::addElement);
btnRight.setEnabled(!availableModel.isEmpty());
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("something went wrong while adding the discovered CitationStyles to the list ");
}
}
};
discoverCitationStyleWorker.execute();
layout.setText(Globals.prefs.getPreviewPreferences().getPreviewStyle().replace("__NEWLINE__", "\n"));
}
Aggregations