/** * Handle dropped files to editor. */ @FXThread private void dragDropped(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!canAccept(file)) return; handleFile(file); }
/** * Handle drag over. */ @FXThread private void dragOver(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!canAccept(file)) return; final Set<TransferMode> transferModes = dragboard.getTransferModes(); final boolean isCopy = transferModes.contains(TransferMode.COPY); dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE); dragEvent.consume(); }
/** * Handle dropped events. * * @param dragEvent the dropped event. */ @FXThread private void handleDragDroppedEvent(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!file.getName().endsWith(FileExtensions.JME_MATERIAL)) { return; } addMaterial(file.toPath()); }
/** * Handle drag over events. * * @param dragEvent the drag over event. */ @FXThread private void handleDragOverEvent(@NotNull final DragEvent dragEvent) { final Dragboard dragboard = dragEvent.getDragboard(); final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES)); if (files == null || files.size() != 1) { return; } final File file = files.get(0); if (!file.getName().endsWith(FileExtensions.JME_MATERIAL)) { return; } final Set<TransferMode> transferModes = dragboard.getTransferModes(); final boolean isCopy = transferModes.contains(TransferMode.COPY); dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE); dragEvent.consume(); }
@FXThread @Override protected void execute(@Nullable final ActionEvent event) { super.execute(event); final Clipboard clipboard = Clipboard.getSystemClipboard(); if (clipboard == null) return; final List<File> files = unsafeCast(clipboard.getContent(DataFormat.FILES)); if (files == null || files.isEmpty()) return; final Path currentFile = getElement().getFile(); final boolean isCut = "cut".equals(clipboard.getContent(EditorUtil.JAVA_PARAM)); if (isCut) { files.forEach(file -> moveFile(currentFile, file.toPath())); } else { files.forEach(file -> copyFile(currentFile, file.toPath())); } clipboard.clear(); }
protected void updateContent(CMap<DataFormat,CList<LineSegment>> content) { SegmentTextEditorModel m = new SegmentTextEditorModel(); if(content != null) { CList<DataFormat> formats = content.keys(); CSorter.sort(formats); for(DataFormat f: formats) { CList<LineSegment> lines = content.get(f); m.addSegments(lines); } } editor.setTextModel(m); D.print(m.getLineCount()); }
/** * 붙여넣기 핸들링 <br/> * * 10.26 이미지 붙여넣기 * * @작성자 : KYJ * @작성일 : 2017. 10. 26. * @param ev */ protected void pasteHandler(KeyEvent ev) { Clipboard systemClipboard = Clipboard.getSystemClipboard(); Set<DataFormat> contentTypes = systemClipboard.getContentTypes(); LOGGER.debug("{}", contentTypes); List<File> files = systemClipboard.getFiles(); if (systemClipboard.getImage() != null) { pasteImage(systemClipboard.getImage()); } else if (files != null) { for (File f : files) { try { String contentType = Files.probeContentType(f.toPath()); LOGGER.debug(contentType); if (contentType.startsWith("image/")) { pasteImage(contentType, FileUtil.getBytes(f)); } } catch (IOException e) { e.printStackTrace(); } } } }
@Override protected Scene getScene() { if (null == CONTENT_IMAGE) { CONTENT_IMAGE = new Image(DragDropWithControls.class.getResource("JavaFX.png").toExternalForm()); dataFormatToCheckBoxID.put(DataFormat.IMAGE, new Pair<String, Object>(ID_IMAGE, CONTENT_IMAGE)); } Parameters params = getParameters(); parameters = params == null ? Collections.<String>emptyList() : params.getRaw(); if (parameters.size() > 1 && parameters.get(1).equals(PARAMETER_ONLY_SOURCE_STAGE)) { leftScene = prepareSourceStage(stage); return leftScene; } else if (parameters.size() > 1 && parameters.get(1).equals(PARAMETER_ONLY_TARGET_STAGE)) { rightScene = prepareTargetStage(secondaryStage); return rightScene; } else { leftScene = prepareSourceStage(stage); secondaryStage = new Stage(); rightScene = prepareTargetStage(secondaryStage); return leftScene; } }
private Node createFormatSelect(final Set<DataFormat> dataFormats) { VBox box = new VBox(); for (final Map.Entry<DataFormat, Pair<String, Object>> df : dataFormatToCheckBoxID.entrySet()) { CheckBox cb = new CheckBox(df.getValue().getKey()); cb.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) { if (t1) { dataFormats.add(df.getKey()); } else { dataFormats.remove(df.getKey()); } } }); box.getChildren().add(cb); } ((CheckBox) box.getChildren().get(0)).selectedProperty().set(true); return box; }
private void doDragDetected(MouseEvent e) { ObservableList<TreeItem<File>> items = assetTree.getSelectionModel().getSelectedItems(); if (items.isEmpty()) { e.consume(); return; } List<File> files = new ArrayList<>(items.size()); items.filtered(t -> t.getValue() != null).forEach(t -> {files.add(t.getValue());}); if (files.size() <= 0) { e.consume(); return; } Dragboard db = assetTree.startDragAndDrop(TransferMode.COPY_OR_MOVE); ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.put(DataFormat.FILES, files); db.setContent(clipboardContent); e.consume(); }
@Override public boolean copy(Map<DataFormat, Object> content) { @SuppressWarnings("unchecked") List<File> files = (List<File>) content.get(DataFormat.FILES); if (files == null) { files = new ArrayList<>(); content.put(DataFormat.FILES, files); } files.add(group.getPath().toFile()); return true; }
@Override public boolean copy(Map<DataFormat, Object> content) { @SuppressWarnings("unchecked") List<File> files = (List<File>) content.get(DataFormat.FILES); if (files == null) { files = new ArrayList<>(); content.put(DataFormat.FILES, files); } files.add(entry.getFilePath().toFile()); return true; }
private void copy(ObservableList<TreeItem<Resource>> selectedItems) { Clipboard clipboard = Clipboard.getSystemClipboard(); Map<DataFormat, Object> content = new HashMap<>(); for (TreeItem<Resource> treeItem : selectedItems) { Resource resource = treeItem.getValue(); if (resource != null) { if (!resource.copy(content)) { FXUIUtils.showMessageDialog(null, "Clipboard operation failed", "Unhandled resource selection", AlertType.ERROR); } } } clipboard.setContent(content); clipboardOperation = Operation.COPY; }
@Override public boolean copy(Map<DataFormat, Object> content) { @SuppressWarnings("unchecked") List<File> files = (List<File>) content.get(DataFormat.FILES); if (files == null) { files = new ArrayList<>(); content.put(DataFormat.FILES, files); } files.add(path.toFile()); return true; }
private void initializeEngineEvents() { webView.addEventFilter(KeyEvent.KEY_PRESSED, e -> { if( e.isShortcutDown() && e.getCode() == KeyCode.V) { String content = (String) Clipboard.getSystemClipboard().getContent(DataFormat.PLAIN_TEXT); if (content != null) { webView.getEngine().executeScript("editor.onPaste('" + sanitizeForAce(content) + "');"); } } }); }
/** * Has file in clipboard boolean. * * @return true if you have a file in your system clipboard. */ @FXThread public static boolean hasFileInClipboard() { final Clipboard clipboard = Clipboard.getSystemClipboard(); if (clipboard == null) return false; final List<File> files = unsafeCast(clipboard.getContent(DataFormat.FILES)); return !(files == null || files.isEmpty()); }
/** * Initialize Layout with FXML and loads ace.js to the webView */ public SQLEditor() { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("SQLEditor.fxml")); fxmlLoader.setRoot(this); fxmlLoader.setController(this); try { fxmlLoader.load(); } catch (IOException exception) { throw new RuntimeException(exception); } engine = editor.getEngine(); engine.load(getClass().getResource("editor.html").toExternalForm()); //Add hook solution to add Ctrl+V to the Javafx webView editor.addEventHandler(KeyEvent.KEY_PRESSED, keyEvent -> { if (keyEvent.isControlDown() && keyEvent.getCode() == KeyCode.V){ final Clipboard clipboard = Clipboard.getSystemClipboard(); String content = (String) clipboard.getContent(DataFormat.PLAIN_TEXT); engine.executeScript(" pasteContent(\""+escapeNewLines(content)+"\") "); } }); }
protected void handleClipboard() { Clipboard c = Clipboard.getSystemClipboard(); CMap<DataFormat,CList<LineSegment>> content = getContent(c); if(CKit.notEquals(content, prevContent)) { prevContent = content; updateContent(content); } }
/** copies specified data formats to the clipboard. silently ignores unsupported data format. DataFormat.PLAIN_TEXT is always supported. */ public void copy(EditorSelection sel, Consumer<Throwable> errorHandler, DataFormat ... formats) { try { CMap<DataFormat,Object> m = new CMap(); for(DataFormat f: formats) { if(isFormatSupported(f)) { ClipboardHandlerBase handler = clipboardHandlers.get(f); if(handler != null) { Object v = handler.copy(this, sel); if(v != null) { m.put(f, v); } } } } Clipboard c = Clipboard.getSystemClipboard(); c.setContent(m); } catch(Throwable e) { if(errorHandler == null) { Log.ex(e); } else { errorHandler.accept(e); } } }
protected void defineContextMenu(final Text text) { final MenuItem copy = new MenuItem("Copy"); copy.setOnAction(event -> { Clipboard.getSystemClipboard().setContent(Collections.singletonMap(DataFormat.PLAIN_TEXT, text.getText())); }); final ContextMenu menu = new ContextMenu(copy); text.setOnContextMenuRequested(event -> { menu.show(text, event.getScreenX(), event.getScreenY()); }); }
private ClipboardContent prepareClipboardContent() { ClipboardContent content = new ClipboardContent(); if (sourceFormats.contains(DataFormat.PLAIN_TEXT)) { log("Source is putting string on dragboard"); content.putString(CONTENT_PLAIN_TEXT); } if (sourceFormats.contains(DataFormat.URL)) { log("Source is putting URL on dragboard"); content.putUrl(CONTENT_URL); } if (sourceFormats.contains(DataFormat.IMAGE)) { log("Source is putting image on dragboard"); content.putImage(CONTENT_IMAGE); } if (sourceFormats.contains(DataFormat.HTML)) { log("Source is putting HTML on dragboard"); content.putHtml(CONTENT_HTML); } if (sourceFormats.contains(DataFormat.RTF)) { log("Source is putting RTF on dragboard"); content.putRtf(CONTENT_RTF); } if (sourceFormats.contains(DF_CUSTOM_BYTES)) { log("Source is putting custom four bytes on dragboard"); content.put(DF_CUSTOM_BYTES, CONTENT_CUSTOM_BYTES); } if (sourceFormats.contains(DF_CUSTOM_STRING)) { log("Source is putting custom four bytes on dragboard"); content.put(DF_CUSTOM_STRING, CONTENT_CUSTOM_STRING); } if (sourceFormats.contains(DF_CUSTOM_CLASS)) { log("Source is putting custom class on dragboard"); content.put(DF_CUSTOM_CLASS, CONTENT_CUSTOM_CLASS); } if (sourceFormats.contains(DataFormat.FILES)) { log("Source is putting two files on dragboard"); content.putFiles(CONTENT_FILES); } return content; }
protected static void placeStringToClipboard(String str) { final Map<DataFormat, Object> data_map = new HashMap<DataFormat, Object>(); data_map.put(DataFormat.PLAIN_TEXT, str); new GetAction() { @Override public void run(Object... parameters) { Clipboard.getSystemClipboard().setContent(data_map); } }.dispatch(Root.ROOT.getEnvironment()); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_CLASSand * target format DataFormat.FILES */ @Test(timeout = 30000) public void sendDF_CUSTOM_CLASSReceiveFILESTest() throws InterruptedException { setSourceContent(DF_CUSTOM_CLASS); setTargetContent(DataFormat.FILES); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_CLASSand * target format DataFormat.URL */ @Test(timeout = 30000) public void sendDF_CUSTOM_CLASSReceiveURLTest() throws InterruptedException { setSourceContent(DF_CUSTOM_CLASS); setTargetContent(DataFormat.URL); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_CLASSand * target format DataFormat.RTF */ @Test(timeout = 30000) public void sendDF_CUSTOM_CLASSReceiveRTFTest() throws InterruptedException { setSourceContent(DF_CUSTOM_CLASS); setTargetContent(DataFormat.RTF); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_CLASSand * target format DataFormat.HTML */ @Test(timeout = 30000) public void sendDF_CUSTOM_CLASSReceiveHTMLTest() throws InterruptedException { setSourceContent(DF_CUSTOM_CLASS); setTargetContent(DataFormat.HTML); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_CLASSand * target format DataFormat.PLAIN_TEXT */ @Test(timeout = 30000) public void sendDF_CUSTOM_CLASSReceivePLAIN_TEXTTest() throws InterruptedException { setSourceContent(DF_CUSTOM_CLASS); setTargetContent(DataFormat.PLAIN_TEXT); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_CLASSand * target format DataFormat.IMAGE */ @Test(timeout = 30000) public void sendDF_CUSTOM_CLASSReceiveIMAGETest() throws InterruptedException { setSourceContent(DF_CUSTOM_CLASS); setTargetContent(DataFormat.IMAGE); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_BYTESand * target format DataFormat.URL */ @Test(timeout = 30000) public void sendDF_CUSTOM_BYTESReceiveURLTest() throws InterruptedException { setSourceContent(DF_CUSTOM_BYTES); setTargetContent(DataFormat.URL); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_BYTESand * target format DataFormat.RTF */ @Test(timeout = 30000) public void sendDF_CUSTOM_BYTESReceiveRTFTest() throws InterruptedException { setSourceContent(DF_CUSTOM_BYTES); setTargetContent(DataFormat.RTF); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_BYTESand * target format DataFormat.HTML */ @Test(timeout = 30000) public void sendDF_CUSTOM_BYTESReceiveHTMLTest() throws InterruptedException { setSourceContent(DF_CUSTOM_BYTES); setTargetContent(DataFormat.HTML); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_BYTESand * target format DataFormat.PLAIN_TEXT */ @Test(timeout = 30000) public void sendDF_CUSTOM_BYTESReceivePLAIN_TEXTTest() throws InterruptedException { setSourceContent(DF_CUSTOM_BYTES); setTargetContent(DataFormat.PLAIN_TEXT); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DF_CUSTOM_BYTESand * target format DataFormat.IMAGE */ @Test(timeout = 30000) public void sendDF_CUSTOM_BYTESReceiveIMAGETest() throws InterruptedException { setSourceContent(DF_CUSTOM_BYTES); setTargetContent(DataFormat.IMAGE); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DataFormat.FILESand * target format DF_CUSTOM_CLASS */ @Test(timeout = 30000) public void sendFILESReceiveDF_CUSTOM_CLASSTest() throws InterruptedException { setSourceContent(DataFormat.FILES); setTargetContent(DF_CUSTOM_CLASS); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DataFormat.FILESand * target format DF_CUSTOM_BYTES */ @Test(timeout = 30000) public void sendFILESReceiveDF_CUSTOM_BYTESTest() throws InterruptedException { setSourceContent(DataFormat.FILES); setTargetContent(DF_CUSTOM_BYTES); transfer(); verifyContentNotComing(); }
/** copies every data format the model contains to the clipboard */ public void copy(EditorSelection sel) { sel = sel.getNormalizedSelection(); CMap<DataFormat,Object> m = new CMap(); String s = copyPlainText(sel); if(s != null) { m.put(DataFormat.PLAIN_TEXT, s); } Clipboard c = Clipboard.getSystemClipboard(); c.setContent(m); }
/** * test drag and drop or clipboard with source format DataFormat.FILESand * target format DF_CUSTOM_STRING */ @Test(timeout = 30000) public void sendFILESReceiveDF_CUSTOM_STRINGTest() throws InterruptedException { setSourceContent(DataFormat.FILES); setTargetContent(DF_CUSTOM_STRING); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DataFormat.FILESand * target format DataFormat.HTML */ @Test(timeout = 30000) public void sendFILESReceiveHTMLTest() throws InterruptedException { setSourceContent(DataFormat.FILES); setTargetContent(DataFormat.HTML); transfer(); verifyContentNotComing(); }
/** * test drag and drop or clipboard with source format DataFormat.FILESand * target format DataFormat.PLAIN_TEXT */ @Test(timeout = 30000) public void sendFILESReceivePLAIN_TEXTTest() throws InterruptedException { setSourceContent(DataFormat.FILES); setTargetContent(DataFormat.PLAIN_TEXT); transfer(); verifyContentNotComing(); }