Search in sources :

Example 1 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class JabRefGUI method openWindow.

private void openWindow() {
    // This property is set to make the Mac OSX Java VM move the menu bar to the top of the screen
    if (OS.OS_X) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
    }
    // Set antialiasing on everywhere. This only works in JRE >= 1.5.
    // Or... it doesn't work, period.
    // TODO test and maybe remove this! I found this commented out with no additional info ( payload@lavabit.com )
    // Enabled since JabRef 2.11 beta 4
    System.setProperty("swing.aatext", "true");
    // Default is "on".
    // "lcd" instead of "on" because of http://wiki.netbeans.org/FaqFontRendering and http://docs.oracle.com/javase/6/docs/technotes/guides/2d/flags.html#aaFonts
    System.setProperty("awt.useSystemAAFontSettings", "lcd");
    // look and feel. This MUST be the first thing to do before loading any Swing-specific code!
    setLookAndFeel();
    // If the option is enabled, open the last edited libraries, if any.
    if (!isBlank && Globals.prefs.getBoolean(JabRefPreferences.OPEN_LAST_EDITED)) {
        openLastEditedDatabases();
    }
    GUIGlobals.init();
    LOGGER.debug("Initializing frame");
    JabRefGUI.mainFrame = new JabRefFrame();
    // Add all bibDatabases databases to the frame:
    boolean first = false;
    if (!bibDatabases.isEmpty()) {
        for (Iterator<ParserResult> parserResultIterator = bibDatabases.iterator(); parserResultIterator.hasNext(); ) {
            ParserResult pr = parserResultIterator.next();
            // Define focused tab
            if (pr.getFile().get().getAbsolutePath().equals(focusedFile)) {
                first = true;
            }
            if (pr.isInvalid()) {
                failed.add(pr);
                parserResultIterator.remove();
            } else if (pr.getDatabase().isShared()) {
                try {
                    new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr);
                } catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | NotASharedDatabaseException e) {
                    // do not open the original file
                    pr.getDatabaseContext().clearDatabaseFile();
                    pr.getDatabase().clearSharedDatabaseID();
                    LOGGER.error("Connection error", e);
                    JOptionPane.showMessageDialog(mainFrame, e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."), Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);
                }
                toOpenTab.add(pr);
            } else if (pr.toOpenTab()) {
                // things to be appended to an opened tab should be done after opening all tabs
                // add them to the list
                toOpenTab.add(pr);
            } else {
                JabRefGUI.getMainFrame().addParserResult(pr, first);
                first = false;
            }
        }
    }
    // finally add things to the currently opened tab
    for (ParserResult pr : toOpenTab) {
        JabRefGUI.getMainFrame().addParserResult(pr, first);
        first = false;
    }
    // do it here:
    if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
        JabRefGUI.getMainFrame().setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    JabRefGUI.getMainFrame().setVisible(true);
    for (ParserResult pr : failed) {
        String message = "<html>" + Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "<p>" + pr.getErrorMessage() + "</html>";
        JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), message, Localization.lang("Error opening file"), JOptionPane.ERROR_MESSAGE);
    }
    // Display warnings, if any
    int tabNumber = 0;
    for (ParserResult pr : bibDatabases) {
        ParserResultWarningDialog.showParserResultWarningDialog(pr, JabRefGUI.getMainFrame(), tabNumber++);
    }
    for (int i = 0; (i < bibDatabases.size()) && (i < JabRefGUI.getMainFrame().getBasePanelCount()); i++) {
        ParserResult pr = bibDatabases.get(i);
        BasePanel panel = JabRefGUI.getMainFrame().getBasePanelAt(i);
        OpenDatabaseAction.performPostOpenActions(panel, pr);
    }
    LOGGER.debug("Finished adding panels");
    if (!bibDatabases.isEmpty()) {
        JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus();
    }
}
Also used : JabRefFrame(org.jabref.gui.JabRefFrame) ParserResult(org.jabref.logic.importer.ParserResult) SharedDatabaseUIManager(org.jabref.gui.shared.SharedDatabaseUIManager) BasePanel(org.jabref.gui.BasePanel)

Example 2 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class SortTabsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // Make a sorted Map that compares case-insensitively:
    Map<String, BasePanel> map = new TreeMap<>(this);
    for (BasePanel panel : frame.getBasePanelList()) {
        map.put(panel.getTabTitle(), panel);
    }
    frame.getTabbedPane().removeAll();
    for (Map.Entry<String, BasePanel> entry : map.entrySet()) {
        frame.addTab(entry.getValue(), false);
    }
}
Also used : BasePanel(org.jabref.gui.BasePanel) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class MassSetFieldAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    BasePanel bp = frame.getCurrentBasePanel();
    if (bp == null) {
        return;
    }
    List<BibEntry> entries = bp.getSelectedEntries();
    // Lazy creation of the dialog:
    if (diag == null) {
        createDialog();
    }
    canceled = true;
    prepareDialog(!entries.isEmpty());
    if (diag != null) {
        diag.setLocationRelativeTo(frame);
        diag.setVisible(true);
    }
    if (canceled) {
        return;
    }
    Collection<BibEntry> entryList;
    // If all entries should be treated, change the entries array:
    if (all.isSelected()) {
        entryList = bp.getDatabase().getEntries();
    } else {
        entryList = entries;
    }
    String toSet = text.getText();
    if (toSet.isEmpty()) {
        toSet = null;
    }
    String[] fields = getFieldNames(((String) field.getSelectedItem()).trim().toLowerCase(Locale.ROOT));
    NamedCompound ce = new NamedCompound(Localization.lang("Set field"));
    if (rename.isSelected()) {
        if (fields.length > 1) {
            JOptionPane.showMessageDialog(diag, Localization.lang("You can only rename one field at a time"), "", JOptionPane.ERROR_MESSAGE);
            // Do not close the dialog.
            return;
        } else {
            ce.addEdit(MassSetFieldAction.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected()));
        }
    } else {
        for (String field1 : fields) {
            ce.addEdit(MassSetFieldAction.massSetField(entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected()));
        }
    }
    ce.end();
    bp.getUndoManager().addEdit(ce);
    bp.markBaseChanged();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) NamedCompound(org.jabref.gui.undo.NamedCompound)

Example 4 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class ManageKeywordsAction method fillKeyWordList.

private void fillKeyWordList() {
    BasePanel bp = frame.getCurrentBasePanel();
    List<BibEntry> entries = bp.getSelectedEntries();
    // fill dialog with values
    keywordListModel.clear();
    sortedKeywordsOfAllEntriesBeforeUpdateByUser.clear();
    if (mergeKeywords.isSelected()) {
        for (BibEntry entry : entries) {
            KeywordList separatedKeywords = entry.getKeywords(Globals.prefs.getKeywordDelimiter());
            sortedKeywordsOfAllEntriesBeforeUpdateByUser.addAll(separatedKeywords);
        }
    } else {
        assert intersectKeywords.isSelected();
        // all keywords from first entry have to be added
        BibEntry firstEntry = entries.get(0);
        KeywordList separatedKeywords = firstEntry.getKeywords(Globals.prefs.getKeywordDelimiter());
        sortedKeywordsOfAllEntriesBeforeUpdateByUser.addAll(separatedKeywords);
        // this approach ensures that one empty keyword list leads to an empty set of common keywords
        for (int i = 1; i < entries.size(); i++) {
            BibEntry entry = entries.get(i);
            separatedKeywords = entry.getKeywords(Globals.prefs.getKeywordDelimiter());
            sortedKeywordsOfAllEntriesBeforeUpdateByUser.retainAll(separatedKeywords);
        }
    }
    for (Keyword keyword : sortedKeywordsOfAllEntriesBeforeUpdateByUser) {
        keywordListModel.addElement(keyword);
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) Keyword(org.jabref.model.entry.Keyword) KeywordList(org.jabref.model.entry.KeywordList)

Example 5 with BasePanel

use of org.jabref.gui.BasePanel in project jabref by JabRef.

the class SaveAllAction method run.

@Override
public void run() {
    for (int i = 0; i < databases; i++) {
        if (i < frame.getBasePanelCount()) {
            BasePanel panel = frame.getBasePanelAt(i);
            if (!panel.getBibDatabaseContext().getDatabaseFile().isPresent()) {
                frame.showBasePanelAt(i);
            }
            panel.runCommand(Actions.SAVE);
        // TODO: can we find out whether the save was actually done or not?
        }
    }
}
Also used : BasePanel(org.jabref.gui.BasePanel)

Aggregations

BasePanel (org.jabref.gui.BasePanel)31 BibEntry (org.jabref.model.entry.BibEntry)14 Path (java.nio.file.Path)4 NamedCompound (org.jabref.gui.undo.NamedCompound)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 JabRefFrame (org.jabref.gui.JabRefFrame)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 BorderFactory (javax.swing.BorderFactory)2 JFrame (javax.swing.JFrame)2 JList (javax.swing.JList)2 JOptionPane (javax.swing.JOptionPane)2 ListSelectionModel (javax.swing.ListSelectionModel)2 ComponentFinder (org.assertj.swing.core.ComponentFinder)2 FailOnThreadViolationRepaintManager (org.assertj.swing.edt.FailOnThreadViolationRepaintManager)2 WindowFinder (org.assertj.swing.finder.WindowFinder)2