Java 类javafx.scene.input.DataFormat 实例源码

项目:jmonkeybuilder    文件:ResourcePropertyEditorControl.java   
/**
 * 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);
}
项目:jmonkeybuilder    文件:ResourcePropertyEditorControl.java   
/**
 * 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();
}
项目:jmonkeybuilder    文件:MaterialPropertyControl.java   
/**
 * 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());
}
项目:jmonkeybuilder    文件:MaterialPropertyControl.java   
/**
 * 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();
}
项目:jmonkeybuilder    文件:PasteFileAction.java   
@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();
}
项目:FxEditor    文件:ClipboardDemoPane.java   
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());
}
项目:Gargoyle    文件:TinymceDeligator.java   
/**
 * 붙여넣기 핸들링 <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();
            }
        }
    }
}
项目:openjfx-8u-dev-tests    文件:DragDropWithControls.java   
@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;
    }
}
项目:openjfx-8u-dev-tests    文件:DragDropWithControls.java   
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;
}
项目:LuoYing    文件:AssetsForm.java   
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();
}
项目:marathonv5    文件:GroupResource.java   
@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;
}
项目:marathonv5    文件:GroupEntryResource.java   
@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;
}
项目:marathonv5    文件:ResourceView.java   
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;
}
项目:marathonv5    文件:FileResource.java   
@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;
}
项目:marathonv5    文件:FolderResource.java   
@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;
}
项目:WebPLP    文件:CodeEditor.java   
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) + "');");
            }
           }
    });
}
项目:jmonkeybuilder    文件:EditorUtil.java   
/**
 * 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());
}
项目:sqlibri    文件:SQLEditor.java   
/**
 * 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)+"\") ");
        }
    });

}
项目:FxEditor    文件:ClipboardDemoPane.java   
protected void handleClipboard()
{
    Clipboard c = Clipboard.getSystemClipboard();
    CMap<DataFormat,CList<LineSegment>> content = getContent(c);
    if(CKit.notEquals(content, prevContent))
    {
        prevContent = content;
        updateContent(content);
    }
}
项目:FxEditor    文件:FxEditorModel.java   
/** 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);
        }
    }
}
项目:jstackfx    文件:ThreadElement.java   
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());
    });
}
项目:openjfx-8u-dev-tests    文件:DragDropWithControls.java   
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;
}
项目:openjfx-8u-dev-tests    文件:TextInputChanger.java   
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());
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:ReqTraq    文件:FxEditorModel.java   
/** 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);
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}
项目:openjfx-8u-dev-tests    文件:CommonContentNotReceivingTests.java   
/**
* 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();
}