Java Code Examples for java.awt.datatransfer.Clipboard#isDataFlavorAvailable()
The following examples show how to use
java.awt.datatransfer.Clipboard#isDataFlavorAvailable() .
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: PasteFromClipboardPlugin.java From constellation with Apache License 2.0 | 6 votes |
@Override protected void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException { try { final Clipboard cb = ConstellationClipboardOwner.getConstellationClipboard(); if (cb.isDataFlavorAvailable(RecordStoreTransferable.RECORDSTORE_FLAVOR)) { final RecordStoreTransferable rt = (RecordStoreTransferable) cb.getContents(null); final RecordStore cbRecordStore = (RecordStore) rt.getTransferData(RecordStoreTransferable.RECORDSTORE_FLAVOR); if (cbRecordStore != null) { // There is a graph on the local clipboard. PluginExecution.withPlugin(InteractiveGraphPluginRegistry.PASTE_GRAPH) .withParameter(PasteGraphPlugin.RECORDSTORE_PARAMETER_ID, cbRecordStore) .executeNow(wg); } } } catch (UnsupportedFlavorException | IOException ex) { Exceptions.printStackTrace(ex); } }
Example 2
Source File: PasteAction.java From ganttproject with GNU General Public License v3.0 | 6 votes |
@Override public void actionPerformed(ActionEvent evt) { if (calledFromAppleScreenMenu(evt)) { return; } ChartSelection selection = myViewmanager.getSelectedArtefacts(); if (!selection.isEmpty()) { pasteInternalFlavor(selection); return; } Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); if (clipboard.isDataFlavorAvailable(GPTransferable.EXTERNAL_DOCUMENT_FLAVOR)) { try { Object data = clipboard.getData(GPTransferable.EXTERNAL_DOCUMENT_FLAVOR); if (data instanceof InputStream == false) { return; } pasteExternalDocument((InputStream) data); } catch (Exception e) { e.printStackTrace(); } } }
Example 3
Source File: ImageUtilsTest.java From markdown-image-kit with MIT License | 5 votes |
/** * Test 2. */ @Test public void test2() { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); if (clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor)) { try { System.out.println(clipboard.getData(DataFlavor.imageFlavor)); BufferedImage im = getImage((Image) clipboard.getData(DataFlavor.imageFlavor)); System.out.println(im); } catch (UnsupportedFlavorException | IOException e) { e.printStackTrace(); } } }
Example 4
Source File: ImageUtilsTest.java From markdown-image-kit with MIT License | 5 votes |
@Test public void test4() { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); if (clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor)) { try { System.out.println(clipboard.getData(DataFlavor.imageFlavor)); setImageClipboard((Image) clipboard.getData(DataFlavor.imageFlavor)); } catch (UnsupportedFlavorException | IOException e) { e.printStackTrace(); } } setImageClipboard(ImageUtils.loadImageFromFile(new File("/Users/dong4j/Downloads/我可要开始皮了.png"))); }
Example 5
Source File: CropUIController.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
Image getScreenfromClipB() { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); if (clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor)) { try { return (Image) clipboard.getData(DataFlavor.imageFlavor); } catch (UnsupportedFlavorException | IOException ex) { Logger.getLogger(CropUIController.class.getName()).log(Level.SEVERE, null, ex); } } return null; }
Example 6
Source File: BaseProcessor.java From ClipIt with MIT License | 5 votes |
public void process() { this.tipsFrame.initJLabelTitle(getTitle()); Clipboard clipboard = ClipboardUtils.getClipboard(); try { if (this.tipsFrame.needTips()) { this.tipsFrame.setVisible(true); } if (clipboard.isDataFlavorAvailable(DataFlavor.javaFileListFlavor)) { fileListProcess((List<File>) clipboard.getData(DataFlavor.javaFileListFlavor)); } else if (clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor)) { imageProcess((Image) clipboard.getData(DataFlavor.imageFlavor)); } else if (clipboard.isDataFlavorAvailable(DataFlavor.allHtmlFlavor)) { htmlProcess((String) clipboard.getData(DataFlavor.allHtmlFlavor)); } else { this.action.actionCompleted(); return; } if (this.action.getTotalSum() == 0) { this.action.actionCompleted(); } } catch (Exception ignore) { // e.printStackTrace(); } }
Example 7
Source File: ClipboardUtils.java From ClipIt with MIT License | 5 votes |
public static Clipboard getClipboard() { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); while (true) { Throwable throwable = null; try { clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor); } catch (IllegalStateException e) { throwable = e; } if (throwable == null) { break; } } return clipboard; }
Example 8
Source File: Utils.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
public static boolean isDataFlavorAvailable(@Nonnull final Clipboard clipboard, @Nonnull final DataFlavor flavor) { boolean result = false; try { result = clipboard.isDataFlavorAvailable(flavor); } catch (final IllegalStateException ex) { LOGGER.warn("Can't get access to clipboard : " + ex.getMessage()); } return result; }