Search in sources :

Example 31 with StringSelection

use of java.awt.datatransfer.StringSelection in project jabref by JabRef.

the class BasePanel method copyKey.

private void copyKey() {
    List<BibEntry> bes = mainTable.getSelectedEntries();
    if (!bes.isEmpty()) {
        storeCurrentEdit();
        List<String> keys = new ArrayList<>(bes.size());
        // Collect all non-null keys.
        for (BibEntry be : bes) {
            be.getCiteKeyOptional().ifPresent(keys::add);
        }
        if (keys.isEmpty()) {
            output(Localization.lang("None of the selected entries have BibTeX keys."));
            return;
        }
        StringSelection ss = new StringSelection(String.join(",", keys));
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
        if (keys.size() == bes.size()) {
            // All entries had keys.
            output((bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key")) + '.');
        } else {
            output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size())));
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) StringSelection(java.awt.datatransfer.StringSelection)

Example 32 with StringSelection

use of java.awt.datatransfer.StringSelection in project jabref by JabRef.

the class BasePanel method copyTitle.

private void copyTitle() {
    List<BibEntry> selectedBibEntries = mainTable.getSelectedEntries();
    if (!selectedBibEntries.isEmpty()) {
        storeCurrentEdit();
        // Collect all non-null titles.
        List<String> titles = selectedBibEntries.stream().filter(bibEntry -> bibEntry.getTitle().isPresent()).map(bibEntry -> bibEntry.getTitle().get()).collect(Collectors.toList());
        if (titles.isEmpty()) {
            output(Localization.lang("None of the selected entries have titles."));
            return;
        }
        StringSelection ss = new StringSelection(String.join("\n", titles));
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
        if (titles.size() == selectedBibEntries.size()) {
            // All entries had titles.
            output((selectedBibEntries.size() > 1 ? Localization.lang("Copied titles") : Localization.lang("Copied title")) + '.');
        } else {
            output(Localization.lang("Warning: %0 out of %1 entries have undefined title.", Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size())));
        }
    }
}
Also used : CitationStyleToClipboardWorker(org.jabref.gui.worker.CitationStyleToClipboardWorker) BibDatabase(org.jabref.model.database.BibDatabase) CheckBoxMessage(org.jabref.gui.util.component.CheckBoxMessage) TextInputDialog(org.jabref.gui.plaintextimport.TextInputDialog) Map(java.util.Map) EntryChangedEvent(org.jabref.model.entry.event.EntryChangedEvent) Path(java.nio.file.Path) ExternalFileType(org.jabref.gui.externalfiletype.ExternalFileType) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) FieldEditor(org.jabref.gui.fieldeditors.FieldEditor) SaveDatabaseAction(org.jabref.gui.exporter.SaveDatabaseAction) DBMSSynchronizer(org.jabref.shared.DBMSSynchronizer) Set(java.util.Set) KeyEvent(java.awt.event.KeyEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException) Platform(javafx.application.Platform) AbstractAction(javax.swing.AbstractAction) BibtexKeyPatternUtil(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil) FormLayout(com.jgoodies.forms.layout.FormLayout) CallBack(org.jabref.gui.worker.CallBack) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) LogFactory(org.apache.commons.logging.LogFactory) UndoableKeyChange(org.jabref.gui.undo.UndoableKeyChange) ExternalFileMenuItem(org.jabref.gui.externalfiletype.ExternalFileMenuItem) JPanel(javax.swing.JPanel) Actions(org.jabref.gui.actions.Actions) PreviewPreferences(org.jabref.preferences.PreviewPreferences) JSplitPane(javax.swing.JSplitPane) NamedCompound(org.jabref.gui.undo.NamedCompound) AutoCompleter(org.jabref.logic.autocompleter.AutoCompleter) MergeEntriesDialog(org.jabref.gui.mergeentries.MergeEntriesDialog) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop) SpecialFieldDatabaseChangeListener(org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener) MainTableDataModel(org.jabref.gui.maintable.MainTableDataModel) KeyCollisionException(org.jabref.model.database.KeyCollisionException) KeyAdapter(java.awt.event.KeyAdapter) SpecialField(org.jabref.model.entry.specialfields.SpecialField) AbbreviateAction(org.jabref.gui.journals.AbbreviateAction) SpecialFieldValue(org.jabref.model.entry.specialfields.SpecialFieldValue) ArrayList(java.util.ArrayList) CitationStyleCache(org.jabref.logic.citationstyle.CitationStyleCache) Layout(org.jabref.logic.layout.Layout) SpecialFieldValueViewModel(org.jabref.gui.specialfields.SpecialFieldValueViewModel) StringSelection(java.awt.datatransfer.StringSelection) ContentAutoCompleters(org.jabref.logic.autocompleter.ContentAutoCompleters) SaveException(org.jabref.logic.exporter.SaveException) ContentSelectorDialog(org.jabref.gui.contentselector.ContentSelectorDialog) MarkEntriesAction(org.jabref.gui.worker.MarkEntriesAction) FindFullTextAction(org.jabref.gui.externalfiles.FindFullTextAction) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry) AbstractBibtexKeyPattern(org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern) IOException(java.io.IOException) EntryEditor(org.jabref.gui.entryeditor.EntryEditor) MainTable(org.jabref.gui.maintable.MainTable) File(java.io.File) Globals(org.jabref.Globals) FileListEntry(org.jabref.gui.filelist.FileListEntry) StringReader(java.io.StringReader) UndoableChangeType(org.jabref.gui.undo.UndoableChangeType) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) WriteXMPAction(org.jabref.gui.externalfiles.WriteXMPAction) GroupAddRemoveDialog(org.jabref.gui.groups.GroupAddRemoveDialog) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) JTextArea(javax.swing.JTextArea) CopyBibTeXKeyAndLinkAction(org.jabref.gui.actions.CopyBibTeXKeyAndLinkAction) EntryRemovedEvent(org.jabref.model.database.event.EntryRemovedEvent) ChangeScanner(org.jabref.collab.ChangeScanner) UnabbreviateAction(org.jabref.gui.journals.UnabbreviateAction) CannotUndoException(javax.swing.undo.CannotUndoException) AbstractWorker(org.jabref.gui.worker.AbstractWorker) SearchQuery(org.jabref.logic.search.SearchQuery) JabRefPreferences(org.jabref.preferences.JabRefPreferences) AppendDatabaseAction(org.jabref.gui.importer.actions.AppendDatabaseAction) AutoCompletePreferences(org.jabref.logic.autocompleter.AutoCompletePreferences) EntryAddedEvent(org.jabref.model.database.event.EntryAddedEvent) FileAnnotationCache(org.jabref.logic.pdf.FileAnnotationCache) CannotRedoException(javax.swing.undo.CannotRedoException) Encodings(org.jabref.logic.l10n.Encodings) Locale(java.util.Locale) CountingUndoManager(org.jabref.gui.undo.CountingUndoManager) AutoCompleterFactory(org.jabref.logic.autocompleter.AutoCompleterFactory) UpdateField(org.jabref.logic.util.UpdateField) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry) BorderLayout(java.awt.BorderLayout) SearchFixDuplicateLabels(org.jabref.gui.bibtexkeypattern.SearchFixDuplicateLabels) Clipboard(java.awt.datatransfer.Clipboard) FileFinders(org.jabref.logic.util.io.FileFinders) Collection(java.util.Collection) BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) BorderFactory(javax.swing.BorderFactory) Collectors(java.util.stream.Collectors) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) FileFinder(org.jabref.logic.util.io.FileFinder) Objects(java.util.Objects) FieldChange(org.jabref.model.FieldChange) List(java.util.List) FileUpdateListener(org.jabref.collab.FileUpdateListener) ExportToClipboardAction(org.jabref.gui.exporter.ExportToClipboardAction) LayoutHelper(org.jabref.logic.layout.LayoutHelper) Optional(java.util.Optional) JabRefExecutorService(org.jabref.JabRefExecutorService) KeyBinding(org.jabref.gui.keyboard.KeyBinding) Toolkit(java.awt.Toolkit) SavePreferences(org.jabref.logic.exporter.SavePreferences) BibtexDatabaseWriter(org.jabref.logic.exporter.BibtexDatabaseWriter) FieldName(org.jabref.model.entry.FieldName) Transferable(java.awt.datatransfer.Transferable) HashMap(java.util.HashMap) CitationStyleOutputFormat(org.jabref.logic.citationstyle.CitationStyleOutputFormat) CleanupAction(org.jabref.gui.actions.CleanupAction) SwingUtilities(javax.swing.SwingUtilities) FileExtensions(org.jabref.logic.util.FileExtensions) SpecialFieldViewModel(org.jabref.gui.specialfields.SpecialFieldViewModel) Charset(java.nio.charset.Charset) BaseAction(org.jabref.gui.actions.BaseAction) FileUpdatePanel(org.jabref.collab.FileUpdatePanel) MainTableFormat(org.jabref.gui.maintable.MainTableFormat) Localization(org.jabref.logic.l10n.Localization) Subscribe(com.google.common.eventbus.Subscribe) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) MainTableSelectionListener(org.jabref.gui.maintable.MainTableSelectionListener) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileBasedLock(org.jabref.logic.util.io.FileBasedLock) FileUtil(org.jabref.logic.util.io.FileUtil) SaveSession(org.jabref.logic.exporter.SaveSession) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) EntryEventSource(org.jabref.model.entry.event.EntryEventSource) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) SynchronizeFileField(org.jabref.gui.externalfiles.SynchronizeFileField) SendAsEMailAction(org.jabref.gui.worker.SendAsEMailAction) AttachFileAction(org.jabref.gui.filelist.AttachFileAction) DatabaseLocation(org.jabref.model.database.DatabaseLocation) MergeWithFetchedEntryAction(org.jabref.gui.mergeentries.MergeWithFetchedEntryAction) Log(org.apache.commons.logging.Log) ExternalFileTypes(org.jabref.gui.externalfiletype.ExternalFileTypes) EntryType(org.jabref.model.entry.EntryType) Collections(java.util.Collections) BibEntry(org.jabref.model.entry.BibEntry) StringSelection(java.awt.datatransfer.StringSelection)

Example 33 with StringSelection

use of java.awt.datatransfer.StringSelection in project jabref by JabRef.

the class BasePanel method copy.

private void copy() {
    List<BibEntry> bes = mainTable.getSelectedEntries();
    if (bes.isEmpty()) {
        // The user maybe selected a single cell.
        // TODO: Check if this can actually happen
        int[] rows = mainTable.getSelectedRows();
        int[] cols = mainTable.getSelectedColumns();
        if ((cols.length == 1) && (rows.length == 1)) {
            // Copy single value.
            Object o = mainTable.getValueAt(rows[0], cols[0]);
            if (o != null) {
                StringSelection ss = new StringSelection(o.toString());
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
                output(Localization.lang("Copied cell contents") + '.');
            }
        }
    } else {
        TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
        // ! look at ClipBoardManager
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, BasePanel.this);
        output(formatOutputMessage(Localization.lang("Copied"), bes.size()));
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) StringSelection(java.awt.datatransfer.StringSelection)

Example 34 with StringSelection

use of java.awt.datatransfer.StringSelection in project JMRI by JMRI.

the class DnDTableExportHandler method createTransferable.

@Override
public Transferable createTransferable(JComponent c) {
    JTable table = (JTable) c;
    int col = table.getSelectedColumn();
    int row = table.getSelectedRow();
    if (col < 0 || row < 0) {
        return null;
    }
    row = table.convertRowIndexToModel(row);
    col = table.convertColumnIndexToModel(col);
    if (log.isDebugEnabled()) {
        log.debug("TransferHandler.createTransferable: from (" + row + ", " + col + ") for \"" + table.getModel().getValueAt(row, col) + "\"");
    }
    Object obj = table.getModel().getValueAt(row, col);
    if (obj instanceof String) {
        return new StringSelection((String) obj);
    } else if (obj != null) {
        return new StringSelection(obj.getClass().getName());
    } else {
        return null;
    }
}
Also used : JTable(javax.swing.JTable) StringSelection(java.awt.datatransfer.StringSelection)

Example 35 with StringSelection

use of java.awt.datatransfer.StringSelection in project beast-mcmc by beast-dev.

the class MapperFrame method doCopy.

@Override
public void doCopy() {
    StringWriter writer = new StringWriter();
    PrintWriter pwriter = new PrintWriter(writer);
    //        for (String tip : treesPanel.getSelectedTips()) {
    //            pwriter.println(tip);
    //        }
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection selection = new StringSelection(writer.toString());
    clipboard.setContents(selection, selection);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

StringSelection (java.awt.datatransfer.StringSelection)99 Clipboard (java.awt.datatransfer.Clipboard)28 ActionEvent (java.awt.event.ActionEvent)11 Transferable (java.awt.datatransfer.Transferable)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 JTextArea (javax.swing.JTextArea)7 Test (org.junit.Test)7 JPanel (javax.swing.JPanel)6 ActionListener (java.awt.event.ActionListener)5 JScrollPane (javax.swing.JScrollPane)5 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 JMenuItem (javax.swing.JMenuItem)4 BibEntry (org.jabref.model.entry.BibEntry)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 BorderLayout (java.awt.BorderLayout)3