Search in sources :

Example 1 with CitationStyle

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();
}
Also used : CitationStyle(org.jabref.logic.citationstyle.CitationStyle) PreviewPreferences(org.jabref.preferences.PreviewPreferences)

Example 2 with CitationStyle

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();
    }
}
Also used : CitationStyle(org.jabref.logic.citationstyle.CitationStyle) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) PreviewPreferences(org.jabref.preferences.PreviewPreferences)

Example 3 with CitationStyle

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"));
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel) TestEntry(org.jabref.logic.util.TestEntry) PreviewPanel(org.jabref.gui.PreviewPanel) Enumeration(java.util.Enumeration) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) SwingWorker(javax.swing.SwingWorker) Localization(org.jabref.logic.l10n.Localization) BorderLayout(java.awt.BorderLayout) BoxLayout(javax.swing.BoxLayout) CitationStyle(org.jabref.logic.citationstyle.CitationStyle) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) Paddings(com.jgoodies.forms.factories.Paddings) JList(javax.swing.JList) JabRefGUI(org.jabref.JabRefGUI) JOptionPane(javax.swing.JOptionPane) Globals(org.jabref.Globals) ExecutionException(java.util.concurrent.ExecutionException) JScrollPane(javax.swing.JScrollPane) Dimension(java.awt.Dimension) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) Log(org.apache.commons.logging.Log) JTextArea(javax.swing.JTextArea) LogFactory(org.apache.commons.logging.LogFactory) JPanel(javax.swing.JPanel) PreviewPreferences(org.jabref.preferences.PreviewPreferences) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) PreviewPreferences(org.jabref.preferences.PreviewPreferences) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CitationStyle (org.jabref.logic.citationstyle.CitationStyle)3 PreviewPreferences (org.jabref.preferences.PreviewPreferences)3 ArrayList (java.util.ArrayList)2 BasePanel (org.jabref.gui.BasePanel)2 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 Paddings (com.jgoodies.forms.factories.Paddings)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 BoxLayout (javax.swing.BoxLayout)1 DefaultListModel (javax.swing.DefaultListModel)1 JButton (javax.swing.JButton)1 JList (javax.swing.JList)1 JOptionPane (javax.swing.JOptionPane)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextArea (javax.swing.JTextArea)1 ListSelectionModel (javax.swing.ListSelectionModel)1