java.awt.datatransfer.DataFlavor Java Examples
The following examples show how to use
java.awt.datatransfer.DataFlavor.
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: MappingGenerationTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Verifies that Lists returned from getNativesForFlavor() and * getFlavorsForNative() are not modified with a subsequent call * to addUnencodedNativeForFlavor() and addFlavorForUnencodedNative() * respectively. */ public static void test1() { DataFlavor df = new DataFlavor("text/plain-test1", null); String nat = "native1"; List<String> natives = fm.getNativesForFlavor(df); fm.addUnencodedNativeForFlavor(df, nat); List<String> nativesNew = fm.getNativesForFlavor(df); if (natives.equals(nativesNew)) { System.err.println("orig=" + natives); System.err.println("new=" + nativesNew); throw new RuntimeException("Test failed"); } List<DataFlavor> flavors = fm.getFlavorsForNative(nat); fm.addFlavorForUnencodedNative(nat, df); List<DataFlavor> flavorsNew = fm.getFlavorsForNative(nat); if (flavors.equals(flavorsNew)) { System.err.println("orig=" + flavors); System.err.println("new=" + flavorsNew); throw new RuntimeException("Test failed"); } }
Example #2
Source File: ManyFlavorMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public void verifyListDataFlavorEntries() { // Enumerate through all natives for (Enumeration e = hashNatives.keys() ; e.hasMoreElements() ;) { String key = (String)e.nextElement(); // SystemFlavorMap preferred value DataFlavor value = (DataFlavor)hashNatives.get(key); java.util.List listFlavors = flavorMap.getFlavorsForNative(key); Vector vectorFlavors = new Vector(listFlavors); // First element should be preferred value DataFlavor prefFlavor = (DataFlavor)vectorFlavors.firstElement(); if ( value != prefFlavor ) { throw new RuntimeException("\n*** Error in verifyListDataFlavorEntries()" + "\nAPI Test: List getFlavorsForNative(String nat)" + "\native: " + key + "\nSystemFlavorMap preferred native: " + value.getMimeType() + "\nList first entry: " + prefFlavor.getMimeType() + "\nTest failed because List first entry does not match preferred"); } } System.out.println("*** native size = " + hashNatives.size()); }
Example #3
Source File: MissedHtmlAndRtfBug.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public MissedHtmlAndRtfBug(Point targetFrameLocation, Point dragSourcePoint, DataFlavor df) throws InterruptedException { final Frame targetFrame = new Frame("Target frame"); final TargetPanel targetPanel = new TargetPanel(targetFrame, df); targetFrame.add(targetPanel); targetFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { targetFrame.dispose(); } }); targetFrame.setLocation(targetFrameLocation); targetFrame.pack(); targetFrame.setVisible(true); doTest(dragSourcePoint, targetPanel); }
Example #4
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override public void drop(DropTargetDropEvent e) { Component c = e.getDropTargetContext().getComponent(); getGhostGlassPane(c).ifPresent(glassPane -> { DnDTabbedPane tabbedPane = glassPane.tabbedPane; Transferable t = e.getTransferable(); DataFlavor[] f = t.getTransferDataFlavors(); int prev = tabbedPane.dragTabIndex; int next = tabbedPane.getTargetTabIndex(e.getLocation()); if (t.isDataFlavorSupported(f[0]) && prev != next) { tabbedPane.convertTab(prev, next); e.dropComplete(true); } else { e.dropComplete(false); } glassPane.setVisible(false); // tabbedPane.dragTabIndex = -1; }); }
Example #5
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override public boolean importData(TransferSupport support) { try { JFileChooser fc = (JFileChooser) support.getComponent(); List<?> list = (List<?>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); File[] files = new File[list.size()]; for (int i = 0; i < list.size(); i++) { files[i] = (File) list.get(i); } if (fc.isMultiSelectionEnabled()) { fc.setSelectedFiles(files); } else { File f = files[0]; if (f.isDirectory()) { fc.setCurrentDirectory(f); } else { fc.setSelectedFile(f); } } return true; } catch (IOException | UnsupportedFlavorException ex) { // ex.printStackTrace(); return false; } }
Example #6
Source File: XDataTransferer.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
protected String getCharsetForTextFormat(Long lFormat) { long format = lFormat.longValue(); if (isMimeFormat(format, "text")) { String nat = getNativeForFormat(format); DataFlavor df = new DataFlavor(nat, null); // Ignore the charset parameter of the MIME type if the subtype // doesn't support charset. if (!DataTransferer.doesSubtypeSupportCharset(df)) { return null; } String charset = df.getParameter("charset"); if (charset != null) { return charset; } } return super.getCharsetForTextFormat(lFormat); }
Example #7
Source File: HtmlTransferable.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (isDataFlavorSupported(flavor)) { if (flavor.equals(DataFlavor.allHtmlFlavor)) { return ALL_HTML_AS_STRING; } else if (flavor.equals(DataFlavor.fragmentHtmlFlavor)) { return FRAGMENT_HTML_AS_STRING; } else if (flavor.equals(DataFlavor.selectionHtmlFlavor)) { return SELECTION_HTML_AS_STRING; } } throw new UnsupportedFlavorException(flavor); }
Example #8
Source File: LibraryTreePanel.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Determines if the clipboard can be pasted. * * @return true if the clipboard contains a LibraryTreeNode XMLControl string */ protected boolean isClipboardPastable() { pasteControl = null; Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable data = clipboard.getContents(null); String dataString = null; try { dataString = (String)data.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) {} if(dataString!=null) { XMLControlElement control = new XMLControlElement(); control.readXML(dataString); if (LibraryResource.class.isAssignableFrom(control.getObjectClass())) { pasteControl = control; return true; } } return false; }
Example #9
Source File: VersionNode.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Transferable clipboardCopy() throws IOException { Transferable deflt = super.clipboardCopy(); ExTransferable enriched = ExTransferable.create(deflt); ExTransferable.Single ex = new ExTransferable.Single(DataFlavor.stringFlavor) { @Override protected Object getData() { return "<dependency>\n" + //NOI18N " <groupId>" + record.getGroupId() + "</groupId>\n" + //NOI18N " <artifactId>" + record.getArtifactId() + "</artifactId>\n" + //NOI18N " <version>" + record.getVersion() + "</version>\n" + //NOI18N "</dependency>"; //NOI18N } }; enriched.put(ex); return enriched; }
Example #10
Source File: MissedHtmlAndRtfBug.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws InterruptedException { Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extractInt(args), InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extractInt(args)); Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extractInt(args), InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extractInt(args)); String[] names = InterprocessArguments.DATA_FLAVOR_NAMES.extractStringArray(args); DataFlavor df = DataFlavorSearcher.getByteDataFlavorForNative(names); try { new MissedHtmlAndRtfBug(targetFrameLocation, dragSourcePoint, df); } catch (InterruptedException e) { e.printStackTrace(); } sleep(5000); System.exit(InterprocessMessages.NO_DROP_HAPPENED); }
Example #11
Source File: FileDropDecorator.java From MtgDesktopCompanion with GNU General Public License v3.0 | 6 votes |
public DataFlavor[] getTransferDataFlavors() { if( customFlavor != null ) return new DataFlavor[] { customFlavor, DATA_FLAVOR, DataFlavor.imageFlavor }; else return new DataFlavor[] { DATA_FLAVOR, DataFlavor.imageFlavor }; }
Example #12
Source File: WDataTransferer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public SortedMap <Long, DataFlavor> getFormatsForFlavors( DataFlavor[] flavors, FlavorTable map) { SortedMap <Long, DataFlavor> retval = super.getFormatsForFlavors(flavors, map); // The Win32 native code does not support exporting LOCALE data, nor // should it. retval.remove(L_CF_LOCALE); return retval; }
Example #13
Source File: WDataTransferer.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static EHTMLReadMode getEHTMLReadMode (DataFlavor df) { EHTMLReadMode mode = HTML_READ_SELECTION; String parameter = df.getParameter("document"); if ("all".equals(parameter)) { mode = HTML_READ_ALL; } else if ("fragment".equals(parameter)) { mode = HTML_READ_FRAGMENT; } return mode; }
Example #14
Source File: bug8024061.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (isDataFlavorSupported(flavor)) { return this; } else { throw new UnsupportedFlavorException(flavor); } }
Example #15
Source File: DataHandler.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Return the DataFlavors for this <code>DataContentHandler</code>. * @return the DataFlavors */ public synchronized DataFlavor[] getTransferDataFlavors() { if (transferFlavors == null) { if (dch != null) { transferFlavors = dch.getTransferDataFlavors(); } else { transferFlavors = new DataFlavor[1]; transferFlavors[0] = new ActivationDataFlavor(obj.getClass(), mimeType, mimeType); } } return transferFlavors; }
Example #16
Source File: FileDrop.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
/** Determine if the dragged data is a file list. */ private boolean isDragOk( final java.io.PrintStream out, final java.awt.dnd.DropTargetDragEvent evt ) { boolean ok = false; // Get data flavors being dragged java.awt.datatransfer.DataFlavor[] flavors = evt.getCurrentDataFlavors(); // See if any of the flavors are a file list int i = 0; while( !ok && i < flavors.length ) { // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. // Is the flavor a file list? final DataFlavor curFlavor = flavors[i]; if( curFlavor.equals( java.awt.datatransfer.DataFlavor.javaFileListFlavor ) || curFlavor.isRepresentationClassReader()){ ok = true; } // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. i++; } // end while: through flavors // If logging is enabled, show data flavors if( out != null ) { if( flavors.length == 0 ) log( out, "FileDrop: no data flavors." ); for( i = 0; i < flavors.length; i++ ) log( out, flavors[i].toString() ); } // end if: logging enabled return ok; }
Example #17
Source File: ExTransferable.java From netbeans with Apache License 2.0 | 5 votes |
/** Get transfer data. * @param flavor the flavor ({@link #multiFlavor}) * @return {@link MultiTransferObject} that represents data in this object * @exception UnsupportedFlavorException when the flavor is not supported * @exception IOException when it is not possible to read data */ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (!isDataFlavorSupported(flavor)) { throw new UnsupportedFlavorException(flavor); } return transferObject; }
Example #18
Source File: GridTransferable.java From nextreports-designer with Apache License 2.0 | 5 votes |
public boolean isDataFlavorSupported(DataFlavor flavor) { for (DataFlavor tmp : flavors) { if (tmp.equals(flavor)) { return true; } } return false; }
Example #19
Source File: SunClipboard.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * @see java.awt.Clipboard#getAvailableDataFlavors * @since 1.5 */ public DataFlavor[] getAvailableDataFlavors() { Transferable cntnts = getContextContents(); if (cntnts != null) { return cntnts.getTransferDataFlavors(); } long[] formats = getClipboardFormatsOpenClose(); return DataTransferer.getInstance(). getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable()); }
Example #20
Source File: PasteImageActionTest.java From markdown-image-kit with MIT License | 5 votes |
@Test public void test() throws IOException, UnsupportedFlavorException { Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable cc = clipboard.getContents(null); if (cc != null && cc.isDataFlavorSupported(DataFlavor.imageFlavor)) { Image image = (Image) cc.getTransferData(DataFlavor.imageFlavor); // 保存图片 BufferedImage bufferedImage = ImageUtils.toBufferedImage(image); File imageFile = new File("/Users/dong4j/Develop/", "test.png"); ImageIO.write(bufferedImage, "png", imageFile); } }
Example #21
Source File: WDataTransferer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public byte[] translateTransferable(Transferable contents, DataFlavor flavor, long format) throws IOException { byte[] bytes = null; if (format == CF_HTML) { if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) { // if a user provides data represented by // DataFlavor.selectionHtmlFlavor format, we use this // type to store the data in the native clipboard bytes = super.translateTransferable(contents, DataFlavor.selectionHtmlFlavor, format); } else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) { // if we cannot get data represented by the // DataFlavor.selectionHtmlFlavor format // but the DataFlavor.allHtmlFlavor format is avialable // we belive that the user knows how to represent // the data and how to mark up selection in a // system specific manner. Therefor, we use this data bytes = super.translateTransferable(contents, DataFlavor.allHtmlFlavor, format); } else { // handle other html flavor types, including custom and // fragment ones bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format)); } } else { // we handle non-html types basing on their // flavors bytes = super.translateTransferable(contents, flavor, format); } return bytes; }
Example #22
Source File: SLDDataFlavour.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override public boolean equals(DataFlavor that) { if (!(that instanceof SLDDataFlavour)) { return false; } boolean isEqual = super.equals(that); if (isEqual) { isEqual = this.getHumanPresentableName().equals(that.getHumanPresentableName()); } return isEqual; }
Example #23
Source File: WDataTransferer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static EHTMLReadMode getEHTMLReadMode (DataFlavor df) { EHTMLReadMode mode = HTML_READ_SELECTION; String parameter = df.getParameter("document"); if ("all".equals(parameter)) { mode = HTML_READ_ALL; } else if ("fragment".equals(parameter)) { mode = HTML_READ_FRAGMENT; } return mode; }
Example #24
Source File: SunClipboard.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * @see java.awt.Clipboard#getAvailableDataFlavors * @since 1.5 */ public DataFlavor[] getAvailableDataFlavors() { Transferable cntnts = getContextContents(); if (cntnts != null) { return cntnts.getTransferDataFlavors(); } long[] formats = getClipboardFormatsOpenClose(); return DataTransferer.getInstance(). getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable()); }
Example #25
Source File: FileDrop.java From neembuu-uploader with GNU General Public License v3.0 | 5 votes |
/** * Returns the data encapsulated in this {@link TransferableObject}. * If the {@link Fetcher} constructor was used, then this is when * the {@link Fetcher#getObject getObject()} method will be called. * If the requested data flavor is not supported, then the * {@link Fetcher#getObject getObject()} method will not be called. * * @param flavor The data flavor for the data to return * @return The dropped data * @since 1.1 */ public Object getTransferData( java.awt.datatransfer.DataFlavor flavor ) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException { // Native object if( flavor.equals( DATA_FLAVOR ) ) return fetcher == null ? data : fetcher.getObject(); // String if( flavor.equals( java.awt.datatransfer.DataFlavor.stringFlavor ) ) return fetcher == null ? data.toString() : fetcher.getObject().toString(); // We can't do anything else throw new java.awt.datatransfer.UnsupportedFlavorException(flavor); }
Example #26
Source File: ImageDataContentHandler.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Returns an object which represents the data to be transferred. * The class of the object returned is defined by the representation class * of the flavor. * * @param df The DataFlavor representing the requested type. * @param ds The DataSource representing the data to be converted. * @return The constructed Object. */ public Object getTransferData(DataFlavor df, DataSource ds) throws IOException { for (int i=0; i < flavor.length; i++) { if (flavor[i].equals(df)) { return getContent(ds); } } return null; }
Example #27
Source File: TargetFileListFrame.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private java.util.List<File> extractListOfFiles(DropTargetDropEvent dtde) { java.util.List<File> fileList = null; try { fileList = (java.util.List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); } catch (UnsupportedFlavorException | IOException e) { e.printStackTrace(); } return fileList; }
Example #28
Source File: RefactoringPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean isDataFlavorSupported(DataFlavor flavor) { DataFlavor[] flavors = getTransferDataFlavors(); for (int i = 0; i < flavors.length; i++) { if (flavors[i].equals(flavor)) { return true; } } return false; }
Example #29
Source File: WDataTransferer.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public byte[] translateTransferable(Transferable contents, DataFlavor flavor, long format) throws IOException { byte[] bytes = null; if (format == CF_HTML) { if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) { // if a user provides data represented by // DataFlavor.selectionHtmlFlavor format, we use this // type to store the data in the native clipboard bytes = super.translateTransferable(contents, DataFlavor.selectionHtmlFlavor, format); } else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) { // if we cannot get data represented by the // DataFlavor.selectionHtmlFlavor format // but the DataFlavor.allHtmlFlavor format is avialable // we belive that the user knows how to represent // the data and how to mark up selection in a // system specific manner. Therefor, we use this data bytes = super.translateTransferable(contents, DataFlavor.allHtmlFlavor, format); } else { // handle other html flavor types, including custom and // fragment ones bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format)); } } else { // we handle non-html types basing on their // flavors bytes = super.translateTransferable(contents, flavor, format); } return bytes; }
Example #30
Source File: WDataTransferer.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public SortedMap <Long, DataFlavor> getFormatsForFlavors( DataFlavor[] flavors, FlavorTable map) { SortedMap <Long, DataFlavor> retval = super.getFormatsForFlavors(flavors, map); // The Win32 native code does not support exporting LOCALE data, nor // should it. retval.remove(L_CF_LOCALE); return retval; }