javafx.scene.input.ClipboardContent Java Examples

The following examples show how to use javafx.scene.input.ClipboardContent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineView.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Copy content to clipboard */
private void copy()
{
    // Use selected lines
    String lines = list.getSelectionModel()
                       .getSelectedItems()
                       .stream()
                       .map(line -> line.text)
                       .collect(Collectors.joining("\n"));
    // If nothing selected, use all lines
    if (lines.isEmpty())
        lines = list.getItems()
                    .stream()
                    .map(line -> line.text)
                    .collect(Collectors.joining("\n"));

    final ClipboardContent content = new ClipboardContent();
    content.putString(lines);
    Clipboard.getSystemClipboard().setContent(content);
}
 
Example #2
Source File: CutFileAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void execute(@Nullable ActionEvent event) {
    super.execute(event);

    var files = getElements().stream()
            .map(ResourceElement::getFile)
            .map(Path::toFile)
            .collect(toList());

    var content = new ClipboardContent();
    content.putFiles(files);
    content.put(EditorUtil.JAVA_PARAM, "cut");

    var clipboard = Clipboard.getSystemClipboard();
    clipboard.setContent(content);
}
 
Example #3
Source File: ItemItemController.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * 艦隊分析
 */
@FXML
void kancolleFleetanalysis() {
    try {
        List<KancolleFleetanalysisItem> list = SlotItemCollection.get().getSlotitemMap().values().stream()
                .filter(item -> item.getLocked())
                .map(KancolleFleetanalysisItem::toItem)
                .sorted(Comparator.comparing(KancolleFleetanalysisItem::getId)
                        .thenComparing(Comparator.comparing(KancolleFleetanalysisItem::getLv)))
                .collect(Collectors.toList());
        ObjectMapper mapper = new ObjectMapper();
        String input = mapper.writeValueAsString(list);

        ClipboardContent content = new ClipboardContent();
        content.putString(input);
        Clipboard.getSystemClipboard().setContent(content);
    } catch (Exception e) {
        LoggerHolder.get().error("艦隊分析のロック装備をクリップボードにコピーに失敗しました", e);
    }
}
 
Example #4
Source File: ArtistsMainController.java    From MusicPlayer with MIT License 6 votes vote down vote up
AlbumCell() {
    super();
    setAlignment(Pos.CENTER);
    setPrefHeight(140);
    setPrefWidth(140);
    albumArtwork.setFitWidth(130);
    albumArtwork.setFitHeight(130);
    albumArtwork.setPreserveRatio(true);
    albumArtwork.setSmooth(true);
    albumArtwork.setCache(true);
    
    this.setOnMouseClicked(event -> albumList.getSelectionModel().select(album));
    
    this.setOnDragDetected(event -> {
    	Dragboard db = this.startDragAndDrop(TransferMode.ANY);
    	ClipboardContent content = new ClipboardContent();
        content.putString("Album");
        db.setContent(content);
    	MusicPlayer.setDraggedItem(album);
    	db.setDragView(this.snapshot(null, null), 75, 75);
        event.consume();
    });
}
 
Example #5
Source File: ArtistsMainController.java    From MusicPlayer with MIT License 6 votes vote down vote up
ArtistCell() {
    super();
    artistImage.setFitWidth(40);
    artistImage.setFitHeight(40);
    artistImage.setPreserveRatio(true);
    artistImage.setSmooth(true);
    artistImage.setCache(true);
    title.setTextOverrun(OverrunStyle.CLIP);
    cell.getChildren().addAll(artistImage, title);
    cell.setAlignment(Pos.CENTER_LEFT);
    HBox.setMargin(artistImage, new Insets(0, 10, 0, 0));
    this.setPrefWidth(248);
    
    this.setOnMouseClicked(event -> artistList.getSelectionModel().select(artist));
    
    this.setOnDragDetected(event -> {
    	Dragboard db = this.startDragAndDrop(TransferMode.ANY);
    	ClipboardContent content = new ClipboardContent();
        content.putString("Artist");
        db.setContent(content);
    	MusicPlayer.setDraggedItem(artist);
    	db.setDragView(this.snapshot(null, null), 125, 25);
    	event.consume();
    });
}
 
Example #6
Source File: DragAndDropUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Registers the given [source] javafx Node as a source for a drag
 * and drop even with {@link #NODE_RANGE_DATA_FORMAT} content.
 */
public static Subscription registerAsNodeDragSource(javafx.scene.Node source, Node data, DesignerRoot root) {
    source.setOnDragDetected(evt -> {
        // drag and drop
        Dragboard db = source.startDragAndDrop(TransferMode.LINK);
        ClipboardContent content = new ClipboardContent();
        content.put(NODE_RANGE_DATA_FORMAT, TextRange.fullLine(data.getBeginLine(), 10000));
        db.setContent(content);
        root.getService(DesignerRoot.IS_NODE_BEING_DRAGGED).setValue(true);
        evt.consume();
    });

    source.setOnDragDone(evt -> {
        if (evt.getDragboard().hasContent(NODE_RANGE_DATA_FORMAT)) {
            root.getService(DesignerRoot.IS_NODE_BEING_DRAGGED).setValue(false);
        }
    });

    return () -> source.setOnDragDetected(null);
}
 
Example #7
Source File: AlarmTreeView.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** For leaf nodes, drag PV name */
private void addDragSupport()
{
    tree_view.setOnDragDetected(event ->
    {
        final ObservableList<TreeItem<AlarmTreeItem<?>>> items = tree_view.getSelectionModel().getSelectedItems();
        if (items.size() != 1)
            return;
        final AlarmTreeItem<?> item = items.get(0).getValue();
        if (! (item instanceof AlarmClientLeaf))
            return;
        final Dragboard db = tree_view.startDragAndDrop(TransferMode.COPY);
        final ClipboardContent content = new ClipboardContent();
        content.putString(item.getName());
        db.setContent(content);
        event.consume();
    });
}
 
Example #8
Source File: AlarmTableUI.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Enable dragging the PV name from a table cell.
 *  @param cell Table cell
 */
static void enablePVDrag(TableCell<AlarmInfoRow, ?> cell)
{
    // Tried to use table.setOnDragDetected() to drag PV names
    // from all selected cells, but with drag enabled on the table
    // it is no longer possible to resize columns:
    // Moving a column divider starts a drag.
    // So now hooking drag to table cell.
    cell.setOnDragDetected(event ->
    {
        // Anything to drag?
        if (cell.getTableRow() == null  ||  cell.getTableRow().getItem() == null)
            return;

        final Dragboard db = cell.startDragAndDrop(TransferMode.COPY);
        final ClipboardContent content = new ClipboardContent();
        content.putString(cell.getTableRow().getItem().pv.get());
        db.setContent(content);
        event.consume();
    });
}
 
Example #9
Source File: SearchView.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Allow dragging {@link ChannelInfo} from search view (into plot) */
private void setupDrag()
{
    channel_table.setOnDragDetected(event ->
    {
        final List<ChannelInfo> selection = channel_table.getSelectionModel().getSelectedItems();
        if (selection.size() > 0)
        {
            final Dragboard db = channel_table.startDragAndDrop(TransferMode.COPY);
            final ClipboardContent content = new ClipboardContent();
            // Publish PV names as "PV1, PV2, ..."
            content.putString(selection.stream().map(ChannelInfo::getName).collect(Collectors.joining(", ")));
            // Copy into ArrayList which is for sure Serializable
            content.put(CHANNEL_INFOS, new ArrayList<>(selection));
            db.setContent(content);
        }
        event.consume();
    });
}
 
Example #10
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public void handleCopySpectra(Event event) {
  StringBuilder sb = new StringBuilder();
  for (MsSpectrumDataSet dataset : datasets) {
    MsSpectrum spectrum = dataset.getSpectrum();
    String spectrumString = TxtExportAlgorithm.spectrumToString(spectrum);
    String splash = SplashCalculationAlgorithm.calculateSplash(spectrum);
    sb.append("# ");
    sb.append(dataset.getName());
    sb.append("\n");
    sb.append("# SPLASH ID: ");
    sb.append(splash);
    sb.append("\n");
    sb.append(spectrumString);
    sb.append("\n");
  }
  final Clipboard clipboard = Clipboard.getSystemClipboard();
  final ClipboardContent content = new ClipboardContent();
  content.putString(sb.toString());
  clipboard.setContent(content);
}
 
Example #11
Source File: DockItem.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Allow dragging this item */
private void handleDragDetected(final MouseEvent event)
{
    // Disable dragging from a 'fixed' pane
    if (getDockPane().isFixed())
        return;

    final Dragboard db = name_tab.startDragAndDrop(TransferMode.MOVE);

    final ClipboardContent content = new ClipboardContent();
    content.put(DOCK_ITEM, getLabel());
    db.setContent(content);

    final DockItem previous = dragged_item.getAndSet(this);
    if (previous != null)
        logger.log(Level.WARNING, "Already dragging " + previous);

    event.consume();
}
 
Example #12
Source File: ClipboardActions.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Transfers the currently selected text to the clipboard,
 * leaving the current selection.
 */
default void copy() {
    IndexRange selection = getSelection();
    if(selection.getLength() > 0) {
        ClipboardContent content = new ClipboardContent();

        content.putString(getSelectedText());

        getStyleCodecs().ifPresent(codecs -> {
            Codec<StyledDocument<PS, SEG, S>> codec = ReadOnlyStyledDocument.codec(codecs._1, codecs._2, getSegOps());
            DataFormat format = dataFormat(codec.getName());
            StyledDocument<PS, SEG, S> doc = subDocument(selection.getStart(), selection.getEnd());
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(os);
            try {
                codec.encode(dos, doc);
                content.put(format, os.toByteArray());
            } catch (IOException e) {
                System.err.println("Codec error: Exception in encoding '" + codec.getName() + "':");
                e.printStackTrace();
            }
        });

        Clipboard.getSystemClipboard().setContent(content);
    }
}
 
Example #13
Source File: CutTextEventHandler.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public void addClipboardText(String text) {
  Platform.runLater(() -> {
    ClipboardContent content = new ClipboardContent();
    content.putString(text);
    clipboard.setContent(content);
  });
}
 
Example #14
Source File: CopyNodeAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final TreeNode<?> node = getNode();

    final ClipboardContent content = new ClipboardContent();
    content.put(DATA_FORMAT, node.getObjectId());

    final Clipboard clipboard = Clipboard.getSystemClipboard();
    clipboard.setContent(content);
}
 
Example #15
Source File: ExceptionController.java    From BetonQuest-Editor with GNU General Public License v3.0 5 votes vote down vote up
@FXML private void copy() {
	try {
		Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        String string = stackTrace.getText();
		// add 4 spaces before each line so when pasted on GitHub it's formatted as code
        content.putString("    " + string.replace("\n", "\n    ").trim());
        clipboard.setContent(content);
	} catch (Exception e) {
		ExceptionController.display(e);
	}
}
 
Example #16
Source File: TerminalView.java    From TerminalFX with MIT License 5 votes vote down vote up
@WebkitCall(from = "hterm")
public void copy(String text) {
	final Clipboard clipboard = Clipboard.getSystemClipboard();
	final ClipboardContent clipboardContent = new ClipboardContent();
	clipboardContent.putString(text);
	clipboard.setContent(clipboardContent);
}
 
Example #17
Source File: ClickableBitcoinAddress.java    From devcoretalk with GNU General Public License v2.0 5 votes vote down vote up
@FXML
protected void copyAddress(ActionEvent event) {
    // User clicked icon or menu item.
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.putString(addressStr.get());
    content.putHtml(String.format("<a href='%s'>%s</a>", uri(), addressStr.get()));
    clipboard.setContent(content);
}
 
Example #18
Source File: ProjectFileTreeView.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private TreeCell<File> createCell(TreeView<File> treeView) {
	FileTreeCell treeCell = new FileTreeCell();
	treeCell.setOnDragDetected(event -> {
		TreeItem<File> draggedItem = treeCell.getTreeItem();
		Dragboard db = treeCell.startDragAndDrop(TransferMode.COPY);

		ClipboardContent content = new ClipboardContent();
		content.putString(draggedItem.getValue().getAbsolutePath());
		content.put(DataFormat.FILES, Collections.singletonList(draggedItem.getValue()));
		db.setContent(content);

		event.consume();
	});
	return treeCell;
}
 
Example #19
Source File: WordStateHandler.java    From VocabHunter with Apache License 2.0 5 votes vote down vote up
public void copyCurrentWord() {
    ClipboardContent content = new ClipboardContent();
    String currentWord = sessionModel.getCurrentWord().getWordIdentifier();
    content.putString(currentWord);

    Clipboard.getSystemClipboard().setContent(content);
}
 
Example #20
Source File: Tools.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 選択行をヘッダ付きでクリップボードにコピーします
 *
 * @param table テーブル
 */
public static void selectionCopy(TableView<?> table) {
    ClipboardContent content = new ClipboardContent();
    content.putString(selectionToString(table));
    Clipboard.getSystemClipboard()
            .setContent(content);
}
 
Example #21
Source File: BrowsableDirectoryFieldUITest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void copyPasteInQuotes() {
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        content.putString("\"my path\"");
        clipboard.setContent(content);
    });

    BrowsableDirectoryField victim = lookup(".victim-blank").queryAs(BrowsableDirectoryField.class);
    clickOn(victim);
    press(KeyCode.CONTROL, KeyCode.V).release(KeyCode.V, KeyCode.CONTROL);
    FxAssert.verifyThat(victim, v -> v.getTextField().getText().equals("my path"));
}
 
Example #22
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void handleCopySplash(Event event) {
  StringBuilder sb = new StringBuilder();
  for (MsSpectrumDataSet dataset : datasets) {
    MsSpectrum spectrum = dataset.getSpectrum();
    String splash = SplashCalculationAlgorithm.calculateSplash(spectrum);
    sb.append(dataset.getName());
    sb.append(" SPLASH ID: ");
    sb.append(splash);
    sb.append("\n");
  }
  final Clipboard clipboard = Clipboard.getSystemClipboard();
  final ClipboardContent content = new ClipboardContent();
  content.putString(sb.toString());
  clipboard.setContent(content);
}
 
Example #23
Source File: UIUtils.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copy text to clipboard
 */
public static void copyToClipBoard(String text) {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.putString(text);
    clipboard.setContent(content);
}
 
Example #24
Source File: EditorUtil.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Added files like files to copy to clipboard content.
 *
 * @param paths   the list of files.
 * @param content the content to store.
 */
@FxThread
public static @NotNull ClipboardContent addCopiedFile(
        @NotNull Array<Path> paths,
        @NotNull ClipboardContent content
) {

    var files = paths.stream()
            .map(Path::toFile)
            .collect(toList());

    content.putFiles(files);
    content.put(EditorUtil.JAVA_PARAM, "copy");

    var platform = JmeSystem.getPlatform();

    if (platform == Platform.Linux64 || platform == Platform.Linux32) {

        var builder = new StringBuilder("copy\n");

        paths.forEach(builder, (path, b) ->
                b.append(path.toUri().toASCIIString()).append('\n'));

        builder.delete(builder.length() - 1, builder.length());

        var buffer = ByteBuffer.allocate(builder.length());

        for (int i = 0, length = builder.length(); i < length; i++) {
            buffer.put((byte) builder.charAt(i));
        }

        buffer.flip();

        content.put(GNOME_FILES, buffer);
    }

    return content;
}
 
Example #25
Source File: CopyFileAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void execute(@Nullable ActionEvent event) {
    super.execute(event);

    var files = getElements().stream()
            .map(ResourceElement::getFile)
            .collect(toArray(Path.class));

    var clipboard = Clipboard.getSystemClipboard();
    clipboard.setContent(EditorUtil.addCopiedFile(files, new ClipboardContent()));
}
 
Example #26
Source File: ShipTablePane.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 選択された艦のみをクリップボードにコピーする。
 *
 * @param table テーブル
 */
public static void selectionCopy(TableView<ShipItem> table) {
    ClipboardContent content = new ClipboardContent();
    content.putString(text(table.getSelectionModel()
            .getSelectedItems()
            .stream()
            .map(ShipItem::getShip)
            .collect(Collectors.toList())));
    Clipboard.getSystemClipboard().setContent(content);
}
 
Example #27
Source File: SearchBox.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
protected void startDrag(MouseEvent event) {
	TextField textBox = ((TextField)event.getSource());
	if(!"".equals(textBox.getSelectedText()) && textBox.getText().equals(textBox.getSelectedText())) {
        Dragboard db = textBox.startDragAndDrop(TransferMode.MOVE);
        snapshotter.setText(textBox.getText());
        db.setDragView(snapshotter.snapshot(null, null));
        ClipboardContent cc = new ClipboardContent();
        cc.put(DataFormat.PLAIN_TEXT, textBox.getSelectedText());
        db.setContent(cc);
        event.consume();
	}
}
 
Example #28
Source File: ContextMenuPvToClipboard.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void call(final Selection selection) throws Exception
{
    final List<ProcessVariable> pvs = selection.getSelections();

    final Clipboard clipboard = Clipboard.getSystemClipboard();
    final ClipboardContent content = new ClipboardContent();
    content.putString(pvs.stream().map(ProcessVariable::getName).collect(Collectors.joining(" ")));
    clipboard.setContent(content);
}
 
Example #29
Source File: CopyPath.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param items Items which paths to copy to clipboard */
public CopyPath(final List<TreeItem<FileInfo>> items)
{
    super(Messages.CopyPathClp, ImageCache.getImageView(ImageCache.class, "/icons/copy.png"));

    setOnAction(event ->
    {
        final Clipboard clipboard = Clipboard.getSystemClipboard();
        final ClipboardContent content = new ClipboardContent();
        content.putString(items.stream().map(item -> item.getValue().file.getAbsolutePath()).collect(Collectors.joining(", ")));
        content.putFiles(items.stream().map(item -> item.getValue().file).collect(Collectors.toList()));
        clipboard.setContent(content);
    });
}
 
Example #30
Source File: DeckBuilderWindow.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
private void startDragToActiveDeck(MouseEvent event, Pane pane, CardInfoMessage message) {
this.cardBeingDragged = message;
	Dragboard db = pane.startDragAndDrop(TransferMode.MOVE);
	ClipboardContent content = new ClipboardContent();
	content.putString(message.toString());
	db.setContent(content);
event.consume();
}