java类java.awt.datatransfer.UnsupportedFlavorException的实例源码

NbClipboardNativeTest.java 文件源码 项目:incubator-netbeans 阅读 24 收藏 0 点赞 0 评论 0
public void testClipboard() throws Exception {
    MockServices.setServices(Cnv.class);
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
    ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class);
    assertEquals("Clipboard == ExClipboard", c, ec);
    assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class));
    assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass());
    c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) {
        protected Object getData() throws IOException, UnsupportedFlavorException {
            return "17";
        }
    }, null);
    Transferable t = c.getContents(null);
    assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor));
    assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor));
    assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV));
    assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV));
}
DataTransferer.java 文件源码 项目:openjdk-jdk10 阅读 32 收藏 0 点赞 0 评论 0
protected String getBestCharsetForTextFormat(Long lFormat,
    Transferable localeTransferable) throws IOException
{
    String charset = null;
    if (localeTransferable != null &&
        isLocaleDependentTextFormat(lFormat) &&
        localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
        try {
            byte[] charsetNameBytes = (byte[])localeTransferable
                    .getTransferData(javaTextEncodingFlavor);
            charset = new String(charsetNameBytes, StandardCharsets.UTF_8);
        } catch (UnsupportedFlavorException cannotHappen) {
        }
    } else {
        charset = getCharsetForTextFormat(lFormat);
    }
    if (charset == null) {
        // Only happens when we have a custom text type.
        charset = Charset.defaultCharset().name();
    }
    return charset;
}
ExTransferable.java 文件源码 项目:incubator-netbeans 阅读 24 收藏 0 点赞 0 评论 0
/** Creates new support.
* @param t transferable to to copy values from
* @param o clipobard owner (or null)
*/
private ExTransferable(final Transferable t) {
    map = new LinkedHashMap<DataFlavor,Single>();

    final DataFlavor[] df = t.getTransferDataFlavors();

    if (df != null) {
        for (int i = 0; i < df.length; i++) {
            try {
                final int fi = i;
                map.put(
                    df[i],
                    new Single(df[i]) {
                        public Object getData() throws IOException, UnsupportedFlavorException {
                            return t.getTransferData(df[fi]);
                        }
                    }
                );
            } catch (Exception ex) {
                // ignore if the data cannot be retrived
            }
        }
    }
}
InjectScript.java 文件源码 项目:Cognizant-Intelligent-Test-Scripter 阅读 26 收藏 0 点赞 0 评论 0
private Boolean reorderProjects(TransferHandler.TransferSupport support) {
    JList list = (JList) support.getComponent();
    try {
        int[] selectedIndices = (int[]) support.getTransferable().getTransferData(INDICES);
        DefaultListModel model = (DefaultListModel) list.getModel();
        JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
        if (dl.getIndex() != -1) {
            for (int selectedIndex : selectedIndices) {
                Object value = model.get(selectedIndex);
                model.removeElement(value);
                model.add(dl.getIndex(), value);
            }
            return true;
        } else {
            LOG.warning("Invalid Drop Location");
        }
    } catch (UnsupportedFlavorException | IOException ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return false;
}
DnDSupport.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Remove a toolbar button represented by the given Transferable.
 */
private void removeButton( Transferable t ) {
    try {
        Object o = null;
        if( t.isDataFlavorSupported(buttonDataFlavor) ) {
            o = t.getTransferData(buttonDataFlavor);
        }
        if( null != o && o instanceof DataObject ) {
            ((DataObject) o).delete();
            sourceToolbar.repaint();
        }
    } catch( UnsupportedFlavorException e ) {
        log.log( Level.INFO, null, e );
    } catch( IOException ioE ) {
        log.log( Level.INFO, null, ioE );
    }
}
DnDSupport.java 文件源码 项目:incubator-netbeans 阅读 24 收藏 0 点赞 0 评论 0
private boolean handleDropImpl(Transferable t) {       
    try {
        Object o;
        if( t.isDataFlavorSupported( actionDataFlavor ) ) {
            o = t.getTransferData( actionDataFlavor );
            if( o instanceof Node ) {
                DataObject dobj = ((Node)o).getLookup().lookup( DataObject.class );
                return addButton( dobj, dropTargetButtonIndex, insertBefore );
            }
        } else {
            o = t.getTransferData( buttonDataFlavor );
            if( o instanceof DataObject ) {
                return moveButton( (DataObject)o, dropTargetButtonIndex, insertBefore );
            }
        }
    } catch( UnsupportedFlavorException e ) {
        log.log( Level.INFO, null, e );
    } catch( IOException ioE ) {
        log.log( Level.INFO, null, ioE );
    }
    return false;
}
ClipboardTransferable.java 文件源码 项目:jdk8u-jdk 阅读 25 收藏 0 点赞 0 评论 0
public Object getTransferData(DataFlavor flavor)
    throws UnsupportedFlavorException, IOException
{
    if (!isDataFlavorSupported(flavor)) {
        throw new UnsupportedFlavorException(flavor);
    }
    Object ret = flavorsToData.get(flavor);
    if (ret instanceof IOException) {
        // rethrow IOExceptions generated while fetching data
        throw (IOException)ret;
    } else if (ret instanceof DataFactory) {
        // Now we can render the data
        DataFactory factory = (DataFactory)ret;
        ret = factory.getTransferData(flavor);
    }
    return ret;
}
ClipboardHistory.java 文件源码 项目:incubator-netbeans 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void clipboardChanged(ClipboardEvent ev) {
    ExClipboard clipboard = ev.getClipboard();

    Transferable transferable = null;
    String clipboardContent = null;
    try {
        transferable = clipboard.getContents(null);
        if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            clipboardContent = (String) transferable.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (OutOfMemoryError oom) {            
        NotificationDisplayer.getDefault().notify( NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom"),NotificationDisplayer.Priority.NORMAL.getIcon(), NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom-details"), null);
        return;
    } catch (IOException ioe) {
        //ignored for bug #218255
    } catch (UnsupportedFlavorException ufe) {
    }

    if (clipboardContent != null) {
        addHistory(transferable, clipboardContent);
    }
}
TransferableOperator.java 文件源码 项目:rapidminer 阅读 21 收藏 0 点赞 0 评论 0
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {

    if (flavor.equals(LOCAL_TRANSFERRED_OPERATORS_FLAVOR)) {
        return this.clonedOperators;
    }
    if (flavor.equals(DataFlavor.stringFlavor)) {
        StringBuilder b = new StringBuilder();
        for (Operator op : clonedOperators) {
            b.append(op.getXML(false));
        }
        return b.toString();
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
}
PlotConfigurationTreeTransferHandler.java 文件源码 项目:rapidminer 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Is called if a {@link ValueSourceTreeNode} is dropped on the {@link PlotConfigurationTree}.
 */
private void valueSourceDrop(final ValueSourceTreeNode valueSourceTreeNode, TreePath path, final int childIndex,
        boolean importDataTableColumn) throws UnsupportedFlavorException, IOException, ChartConfigurationException {

    // fetch dropped value source and parent
    final ValueSource valueSource = valueSourceTreeNode.getUserObject();

    Object lastPathComponent = path.getLastPathComponent();
    if (lastPathComponent instanceof RangeAxisConfigTreeNode) {
        valueSourceDropOnRangeAxisConfig(valueSourceTreeNode, childIndex, valueSource, lastPathComponent);
    } else {
        valueSourceDropOnPlotConfiguration(valueSourceTreeNode, childIndex, valueSource, lastPathComponent,
                importDataTableColumn);
    }

}
TableTabClip.java 文件源码 项目:Logisim 阅读 22 收藏 0 点赞 0 评论 0
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (flavor == binaryFlavor) {
        return this;
    } else if (flavor == DataFlavor.stringFlavor) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < headers.length; i++) {
            buf.append(headers[i]);
            buf.append(i == headers.length - 1 ? '\n' : '\t');
        }
        for (int i = 0; i < contents.length; i++) {
            for (int j = 0; j < contents[i].length; j++) {
                buf.append(contents[i][j]);
                buf.append(j == contents[i].length - 1 ? '\n' : '\t');
            }
        }
        return buf.toString();
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
}
SubtitleDownloaderUI.java 文件源码 项目:SubtitleDownloader 阅读 29 收藏 0 点赞 0 评论 0
@Override
public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    try {
        Transferable t = dtde.getTransferable();
        DataFlavor[] dataFlavors = t.getTransferDataFlavors();
        for (DataFlavor df : dataFlavors) {
            if (df.isFlavorJavaFileListType()) {
                File[] filesArray = (File[]) ((List<File>) t.getTransferData(df)).toArray();
                pathNameTextField.setText(getFilesName(filesArray));
            }
        }
    } catch (UnsupportedFlavorException e2) {
    } catch (IOException ex) {
        Logger.getLogger(SubtitleDownloaderUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}
MoverTransferHandler.java 文件源码 项目:Open-DM 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Returns true if the drag came from the same component as we are testing for drop. Used to
 * prevent drops on the src file list.
 */
public boolean isSrcComponentSameAsTargetComponent(TransferHandler.TransferSupport info)
        throws UnsupportedFlavorException, IOException {
    boolean result = false;

    // First get where we are putting this file
    String myPanelDir = profilePanel.getCurrentDirectory().getPath();

    // Don't accept drags from current panel.
    if (info.isDataFlavorSupported(ArrayListTransferrable.flavor)) {
        // Get the Array of items being dropped.
        Transferable t = info.getTransferable();
        ArrayList arrayList = (ArrayList) t.getTransferData(ArrayListTransferrable.flavor);
        ArcMoverFile fileBeingMoved = (ArcMoverFile) arrayList.get(2);
        String fileBeingMovedDir = fileBeingMoved.getParent().getPath();
        if (myPanelDir.equals(fileBeingMovedDir)) {
            result = true;
        }
    }
    return result;
}
DataTransferer.java 文件源码 项目:jdk8u-jdk 阅读 31 收藏 0 点赞 0 评论 0
private String getBestCharsetForTextFormat(Long lFormat,
    Transferable localeTransferable) throws IOException
{
    String charset = null;
    if (localeTransferable != null &&
        isLocaleDependentTextFormat(lFormat) &&
        localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor))
    {
        try {
            charset = new String(
                (byte[])localeTransferable.getTransferData(javaTextEncodingFlavor),
                "UTF-8"
            );
        } catch (UnsupportedFlavorException cannotHappen) {
        }
    } else {
        charset = getCharsetForTextFormat(lFormat);
    }
    if (charset == null) {
        // Only happens when we have a custom text type.
        charset = getDefaultTextCharset();
    }
    return charset;
}
ClipboardTransferable.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
@Override
public Object getTransferData(DataFlavor flavor)
    throws UnsupportedFlavorException, IOException
{
    if (!isDataFlavorSupported(flavor)) {
        throw new UnsupportedFlavorException(flavor);
    }
    Object ret = flavorsToData.get(flavor);
    if (ret instanceof IOException) {
        // rethrow IOExceptions generated while fetching data
        throw new IOException("Exception fetching data: ", (IOException)ret);
    } else if (ret instanceof DataFactory) {
        // Now we can render the data
        DataFactory factory = (DataFactory)ret;
        ret = factory.getTransferData(flavor);
    }
    return ret;
}
TableDB.java 文件源码 项目:geomapapp 阅读 26 收藏 0 点赞 0 评论 0
void paste() throws IOException {
    Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clip.getContents(this);
    DataFlavor[] flavors = contents.getTransferDataFlavors();
    for( int k=0 ; k<flavors.length ; k++) {
        try {
            if( flavors[k].getHumanPresentableName().indexOf("html")>=0 )continue;
            BufferedReader in = new BufferedReader(
                flavors[k].getReaderForText(contents));
    System.out.println( flavors[k].getHumanPresentableName());
            read( in );
            break;
        } catch( UnsupportedFlavorException e) {
        }
    }
}
DataTransferer.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
private String getBestCharsetForTextFormat(Long lFormat,
    Transferable localeTransferable) throws IOException
{
    String charset = null;
    if (localeTransferable != null &&
        isLocaleDependentTextFormat(lFormat) &&
        localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor))
    {
        try {
            charset = new String(
                (byte[])localeTransferable.getTransferData(javaTextEncodingFlavor),
                "UTF-8"
            );
        } catch (UnsupportedFlavorException cannotHappen) {
        }
    } else {
        charset = getCharsetForTextFormat(lFormat);
    }
    if (charset == null) {
        // Only happens when we have a custom text type.
        charset = getDefaultTextCharset();
    }
    return charset;
}
ScreenCut.java 文件源码 项目:ScreenCut 阅读 19 收藏 0 点赞 0 评论 0
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
    if (flavor.equals(DataFlavor.imageFlavor)) {
        return theImage;
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
}
FileDropTargetListener.java 文件源码 项目:alevin-svn2 阅读 19 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
    try {
        Transferable t = dtde.getTransferable();
        List<File> files = null;
        if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
            files = (List<File>) t
                    .getTransferData(DataFlavor.javaFileListFlavor);
        } else if (uriFlavor != null && t.isDataFlavorSupported(uriFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
            files = textURIListToFileList((String) t
                    .getTransferData(uriFlavor));
        } else
            dtde.rejectDrop();

        if (files != null && files.size() == 1) {
            openFile(files.get(0));
            dtde.dropComplete(true);
        } else
            dtde.dropComplete(false);
    } catch (UnsupportedFlavorException ex) {
        dtde.rejectDrop();
    } catch (IOException e) {
        dtde.rejectDrop();
    }
}
Clipboard.java 文件源码 项目:VISNode 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Returns the value of the clipboard
 * 
 * @return Object
 */
private Object getValue() {
    try {
        return clipboard.getContents(this).getTransferData(DataFlavors.object());
    } catch (UnsupportedFlavorException | IOException e) {

    }
    return null;
}
ObjectTransferable.java 文件源码 项目:VISNode 阅读 25 收藏 0 点赞 0 评论 0
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
    if (flavor.equals(DataFlavors.object())) {
        return value;
    } else if (flavor.equals(DataFlavors.string())) {
        return value.toString();
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
}
YassStringTransferHandler.java 文件源码 项目:Yass 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Description of the Method
 *
 * @param c Description of the Parameter
 * @param t Description of the Parameter
 * @return Description of the Return Value
 */
public boolean importData(JComponent c, Transferable t) {
    if (canImport(c, t.getTransferDataFlavors())) {
        try {
            String str = (String) t.getTransferData(DataFlavor.stringFlavor);
            importString(c, str);
            return true;
        } catch (UnsupportedFlavorException | IOException ignored) {
        }
    }

    return false;
}
bug8024061.java 文件源码 项目:openjdk-jdk10 阅读 26 收藏 0 点赞 0 评论 0
@Override
public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
    if (isDataFlavorSupported(flavor)) {
        return this;
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
}
RectangularSelectionTransferHandler.java 文件源码 项目:incubator-netbeans 阅读 21 收藏 0 点赞 0 评论 0
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (RECTANGULAR_SELECTION_FLAVOR.equals(flavor)) {
        return rectangularSelectionData;
    }
    return delegate.getTransferData(flavor);
}
EditorCaretTransferHandler.java 文件源码 项目:incubator-netbeans 阅读 19 收藏 0 点赞 0 评论 0
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (RECTANGULAR_SELECTION_FLAVOR.equals(flavor)) {
        return rectangularSelectionData;
    }
    return delegate.getTransferData(flavor);
}
ExTransferable.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    Single o = map.get(flavor);

    if (o == null) {
        throw new UnsupportedFlavorException(flavor);
    }

    return o.getTransferData(flavor);
}
ExTransferable.java 文件源码 项目:incubator-netbeans 阅读 21 收藏 0 点赞 0 评论 0
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
    if (!this.flavor.equals(flavor)) {
        throw new UnsupportedFlavorException(flavor);
    }

    return getData();
}
ExTransferable.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
/** 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;
}
mxGraphTransferable.java 文件源码 项目:Tarski 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 
 * @param flavor
 * @return the richer data flavor of this and the specified
 * @throws UnsupportedFlavorException
 */
public Object getRicherData(DataFlavor flavor) throws UnsupportedFlavorException {
  if (flavor.equals(dataFlavor)) {
    return this;
  } else {
    throw new UnsupportedFlavorException(flavor);
  }
}
DragAndDropHandler.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
private boolean importTextIntoPalette( Lookup targetCategory, Transferable item, int dropIndex ) 
        throws IOException, UnsupportedFlavorException {

    DataFlavor flavor = DataFlavor.selectBestTextFlavor( item.getTransferDataFlavors() );
    if( null == flavor )
        return false;

    String textToImport = extractText( item, flavor );
    SwingUtilities.invokeLater( new TextImporter( textToImport, targetCategory, dropIndex ) );
    return true;
}


问题


面经


文章

微信
公众号

扫码关注公众号