Search in sources :

Example 1 with SearchPreferences

use of org.jabref.preferences.SearchPreferences in project jabref by JabRef.

the class SearchResultFrame method init.

private void init(String title) {
    searchResultFrame = new JFrame();
    searchResultFrame.setTitle(title);
    searchResultFrame.setIconImages(IconTheme.getLogoSet());
    preview = new PreviewPanel(null, null);
    sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR));
    model = (DefaultEventTableModel<BibEntry>) GlazedListsSwing.eventTableModelWithThreadProxyList(sortedEntries, new EntryTableFormat());
    entryTable = new JTable(model);
    GeneralRenderer renderer = new GeneralRenderer(Color.white);
    entryTable.setDefaultRenderer(JLabel.class, renderer);
    entryTable.setDefaultRenderer(String.class, renderer);
    setWidths();
    TableComparatorChooser<BibEntry> tableSorter = TableComparatorChooser.install(entryTable, sortedEntries, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
    setupComparatorChooser(tableSorter);
    JScrollPane sp = new JScrollPane(entryTable);
    final DefaultEventSelectionModel<BibEntry> selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing.eventSelectionModelWithThreadProxyList(sortedEntries);
    entryTable.setSelectionModel(selectionModel);
    selectionModel.getSelected().addListEventListener(new EntrySelectionListener());
    entryTable.addMouseListener(new TableClickListener());
    contentPane.setTopComponent(sp);
    contentPane.setBottomComponent(preview);
    // Key bindings:
    AbstractAction closeAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    ActionMap actionMap = contentPane.getActionMap();
    InputMap inputMap = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE), "close");
    actionMap.put("close", closeAction);
    actionMap = entryTable.getActionMap();
    inputMap = entryTable.getInputMap();
    //Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB
    actionMap.put("selectNextColumnCell", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectNextEntry();
        }
    });
    actionMap.put("selectPreviousColumnCell", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectPreviousEntry();
        }
    });
    actionMap.put("selectNextRow", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectNextEntry();
        }
    });
    actionMap.put("selectPreviousRow", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectPreviousEntry();
        }
    });
    String selectFirst = "selectFirst";
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_FIRST_ENTRY), selectFirst);
    actionMap.put(selectFirst, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            selectFirstEntry();
        }
    });
    String selectLast = "selectLast";
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_LAST_ENTRY), selectLast);
    actionMap.put(selectLast, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            selectLastEntry();
        }
    });
    actionMap.put("copy", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!selectionModel.getSelected().isEmpty()) {
                List<BibEntry> bes = selectionModel.getSelected();
                TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
                // ! look at ClipBoardManager
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, frame.getCurrentBasePanel());
                frame.output(Localization.lang("Copied") + ' ' + (bes.size() > 1 ? bes.size() + " " + Localization.lang("entries") : "1 " + Localization.lang("entry") + '.'));
            }
        }
    });
    // override standard enter-action; enter opens the selected entry
    entryTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
    actionMap.put("Enter", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            BibEntry entry = sortedEntries.get(entryTable.getSelectedRow());
            selectEntryInBasePanel(entry);
        }
    });
    searchResultFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            contentPane.setDividerLocation(0.5f);
        }

        @Override
        public void windowClosing(WindowEvent event) {
            dispose();
        }
    });
    searchResultFrame.getContentPane().add(contentPane, BorderLayout.CENTER);
    // Remember and default to last size:
    SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
    searchResultFrame.setSize(searchPreferences.getSeachDialogWidth(), searchPreferences.getSeachDialogHeight());
    searchResultFrame.setLocation(searchPreferences.getSearchDialogPosX(), searchPreferences.getSearchDialogPosY());
    searchResultFrame.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            new SearchPreferences(Globals.prefs).setSearchDialogWidth(searchResultFrame.getSize().width).setSearchDialogHeight(searchResultFrame.getSize().height);
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            new SearchPreferences(Globals.prefs).setSearchDialogPosX(searchResultFrame.getLocation().x).setSearchDialogPosY(searchResultFrame.getLocation().y);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) GeneralRenderer(org.jabref.gui.renderer.GeneralRenderer) WindowAdapter(java.awt.event.WindowAdapter) PreviewPanel(org.jabref.gui.PreviewPanel) JFrame(javax.swing.JFrame) SortedList(ca.odell.glazedlists.SortedList) List(java.util.List) BasicEventList(ca.odell.glazedlists.BasicEventList) EventList(ca.odell.glazedlists.EventList) AbstractAction(javax.swing.AbstractAction) ComponentAdapter(java.awt.event.ComponentAdapter) JScrollPane(javax.swing.JScrollPane) BibEntry(org.jabref.model.entry.BibEntry) ActionMap(javax.swing.ActionMap) TransferableBibtexEntry(org.jabref.gui.TransferableBibtexEntry) DefaultEventSelectionModel(ca.odell.glazedlists.swing.DefaultEventSelectionModel) SearchPreferences(org.jabref.preferences.SearchPreferences) EntryComparator(org.jabref.logic.bibtex.comparator.EntryComparator) JTable(javax.swing.JTable) WindowEvent(java.awt.event.WindowEvent) InputMap(javax.swing.InputMap) ComponentEvent(java.awt.event.ComponentEvent)

Example 2 with SearchPreferences

use of org.jabref.preferences.SearchPreferences in project jabref by JabRef.

the class GlobalSearchBar method toggleSearchModeAndSearch.

private void toggleSearchModeAndSearch() {
    int nextSearchMode = (searchDisplayMode.ordinal() + 1) % SearchDisplayMode.values().length;
    searchDisplayMode = SearchDisplayMode.values()[nextSearchMode];
    new SearchPreferences(Globals.prefs).setSearchMode(searchDisplayMode);
    updateSearchModeButtonText();
    performSearch();
}
Also used : SearchPreferences(org.jabref.preferences.SearchPreferences)

Example 3 with SearchPreferences

use of org.jabref.preferences.SearchPreferences in project jabref by JabRef.

the class ArgumentProcessor method exportMatches.

private boolean exportMatches(List<ParserResult> loaded) {
    String[] data = cli.getExportMatches().split(",");
    //enables blanks within the search term:
    String searchTerm = data[0].replace("\\$", " ");
    //$ stands for a blank
    ParserResult pr = loaded.get(loaded.size() - 1);
    BibDatabaseContext databaseContext = pr.getDatabaseContext();
    BibDatabase dataBase = pr.getDatabase();
    SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
    SearchQuery query = new SearchQuery(searchTerm, searchPreferences.isCaseSensitive(), searchPreferences.isRegularExpression());
    List<BibEntry> matches = new DatabaseSearcher(query, dataBase).getMatches();
    //export matches
    if (!matches.isEmpty()) {
        String formatName;
        //read in the export format, take default format if no format entered
        switch(data.length) {
            case 3:
                formatName = data[2];
                break;
            case 2:
                //default ExportFormat: HTML table (with Abstract & BibTeX)
                formatName = "tablerefsabsbib";
                break;
            default:
                System.err.println(Localization.lang("Output file missing").concat(". \n \t ").concat(Localization.lang("Usage")).concat(": ") + JabRefCLI.getExportMatchesSyntax());
                noGUINeeded = true;
                return false;
        }
        //export new database
        IExportFormat format = ExportFormats.getExportFormat(formatName);
        if (format == null) {
            System.err.println(Localization.lang("Unknown export format") + ": " + formatName);
        } else {
            // We have an ExportFormat instance:
            try {
                System.out.println(Localization.lang("Exporting") + ": " + data[1]);
                format.performExport(databaseContext, data[1], databaseContext.getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()), matches);
            } catch (Exception ex) {
                System.err.println(Localization.lang("Could not export file") + " '" + data[1] + "': " + ExceptionUtils.getStackTrace(ex));
            }
        }
    } else {
        System.err.println(Localization.lang("No search matches."));
    }
    return true;
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery) ParserResult(org.jabref.logic.importer.ParserResult) SearchPreferences(org.jabref.preferences.SearchPreferences) BibEntry(org.jabref.model.entry.BibEntry) IExportFormat(org.jabref.logic.exporter.IExportFormat) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) JabRefException(org.jabref.JabRefException) BackingStoreException(java.util.prefs.BackingStoreException) SaveException(org.jabref.logic.exporter.SaveException) IOException(java.io.IOException) ImportException(org.jabref.logic.importer.ImportException) DatabaseSearcher(org.jabref.logic.search.DatabaseSearcher)

Example 4 with SearchPreferences

use of org.jabref.preferences.SearchPreferences in project jabref by JabRef.

the class JabRefFrame method init.

private void init() {
    tabbedPane = new DragDropPopupPane(tabPopupMenu());
    MyGlassPane glassPane = new MyGlassPane();
    setGlassPane(glassPane);
    setTitle(FRAME_TITLE);
    setIconImages(IconTheme.getLogoSet());
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            if (OS.OS_X) {
                JabRefFrame.this.setVisible(false);
            } else {
                new CloseAction().actionPerformed(null);
            }
        }
    });
    initSidePane();
    initLayout();
    initActions();
    // Show the toolbar if it was visible at last shutdown:
    tlb.setVisible(Globals.prefs.getBoolean(JabRefPreferences.TOOLBAR_VISIBLE));
    setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
    WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X, JabRefPreferences.SIZE_Y);
    pw.displayWindowAtStoredLocation();
    tabbedPane.setBorder(null);
    tabbedPane.setForeground(GUIGlobals.INACTIVE_TABBED_COLOR);
    /*
         * The following state listener makes sure focus is registered with the
         * correct database when the user switches tabs. Without this,
         * cut/paste/copy operations would some times occur in the wrong tab.
         */
    tabbedPane.addChangeListener(e -> {
        markActiveBasePanel();
        BasePanel currentBasePanel = getCurrentBasePanel();
        if (currentBasePanel == null) {
            return;
        }
        Platform.runLater(() -> Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext())));
        if (new SearchPreferences(Globals.prefs).isGlobalSearch()) {
            globalSearchBar.performSearch();
        } else {
            String content = "";
            Optional<SearchQuery> currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
            if (currentSearchQuery.isPresent()) {
                content = currentSearchQuery.get().getQuery();
            }
            globalSearchBar.setSearchTerm(content, true);
        }
        currentBasePanel.getPreviewPanel().updateLayout();
        groupSidePane.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class));
        previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
        generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class));
        openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));
        Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());
        setWindowTitle();
        editModeAction.initName();
        currentBasePanel.updateSearchManager();
        currentBasePanel.setBackAndForwardEnabledState();
        currentBasePanel.getUndoManager().postUndoRedoEvent();
        currentBasePanel.getMainTable().requestFocus();
    });
    //opened (double-clicked) documents are not displayed.
    if (OS.OS_X) {
        try {
            new MacAdapter().registerMacEvents(this);
        } catch (Exception e) {
            LOGGER.fatal("Could not interface with Mac OS X methods.", e);
        }
    }
    initShowTrackingNotification();
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery) WindowAdapter(java.awt.event.WindowAdapter) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) SearchPreferences(org.jabref.preferences.SearchPreferences) OpenOfficeSidePanel(org.jabref.gui.openoffice.OpenOfficeSidePanel) WindowEvent(java.awt.event.WindowEvent) GroupSidePane(org.jabref.gui.groups.GroupSidePane) GeneralFetcher(org.jabref.gui.importer.fetcher.GeneralFetcher) WindowLocation(org.jabref.gui.util.WindowLocation) MacAdapter(osx.macadapter.MacAdapter)

Aggregations

SearchPreferences (org.jabref.preferences.SearchPreferences)4 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 IOException (java.io.IOException)2 SearchQuery (org.jabref.logic.search.SearchQuery)2 BibEntry (org.jabref.model.entry.BibEntry)2 BasicEventList (ca.odell.glazedlists.BasicEventList)1 EventList (ca.odell.glazedlists.EventList)1 SortedList (ca.odell.glazedlists.SortedList)1 DefaultEventSelectionModel (ca.odell.glazedlists.swing.DefaultEventSelectionModel)1 ActionEvent (java.awt.event.ActionEvent)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 BackingStoreException (java.util.prefs.BackingStoreException)1 AbstractAction (javax.swing.AbstractAction)1 ActionMap (javax.swing.ActionMap)1 InputMap (javax.swing.InputMap)1 JFrame (javax.swing.JFrame)1