Search in sources :

Example 61 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.

the class SunDropTargetContextPeer method getTransferData.

/**
     * @return the data
     */
public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException, InvalidDnDOperationException {
    SecurityManager sm = System.getSecurityManager();
    try {
        if (!dropInProcess && sm != null) {
            sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
        }
    } catch (Exception e) {
        Thread currentThread = Thread.currentThread();
        currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, e);
        return null;
    }
    Long lFormat = null;
    Transferable localTransferable = local;
    if (localTransferable != null) {
        return localTransferable.getTransferData(df);
    }
    if (dropStatus != STATUS_ACCEPT || dropComplete) {
        throw new InvalidDnDOperationException("No drop current");
    }
    Map flavorMap = DataTransferer.getInstance().getFlavorsForFormats(currentT, DataTransferer.adaptFlavorMap(currentDT.getFlavorMap()));
    lFormat = (Long) flavorMap.get(df);
    if (lFormat == null) {
        throw new UnsupportedFlavorException(df);
    }
    if (df.isRepresentationClassRemote() && currentDA != DnDConstants.ACTION_LINK) {
        throw new InvalidDnDOperationException("only ACTION_LINK is permissable for transfer of java.rmi.Remote objects");
    }
    final long format = lFormat.longValue();
    Object ret = getNativeData(format);
    if (ret instanceof byte[]) {
        try {
            return DataTransferer.getInstance().translateBytes((byte[]) ret, df, format, this);
        } catch (IOException e) {
            throw new InvalidDnDOperationException(e.getMessage());
        }
    } else if (ret instanceof InputStream) {
        try {
            return DataTransferer.getInstance().translateStream((InputStream) ret, df, format, this);
        } catch (IOException e) {
            throw new InvalidDnDOperationException(e.getMessage());
        }
    } else {
        throw new IOException("no native data was transfered");
    }
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) InputStream(java.io.InputStream) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) Map(java.util.Map) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException)

Example 62 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jdk8u_jdk by JetBrains.

the class SunClipboard method getData.

/**
     * @see java.awt.Clipboard#getData
     * @since 1.5
     */
public Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (flavor == null) {
        throw new NullPointerException("flavor");
    }
    Transferable cntnts = getContextContents();
    if (cntnts != null) {
        return cntnts.getTransferData(flavor);
    }
    long format = 0;
    byte[] data = null;
    Transferable localeTransferable = null;
    try {
        openClipboard(null);
        long[] formats = getClipboardFormats();
        Long lFormat = (Long) DataTransferer.getInstance().getFlavorsForFormats(formats, getDefaultFlavorTable()).get(flavor);
        if (lFormat == null) {
            throw new UnsupportedFlavorException(flavor);
        }
        format = lFormat.longValue();
        data = getClipboardData(format);
        if (DataTransferer.getInstance().isLocaleDependentTextFormat(format)) {
            localeTransferable = createLocaleTransferable(formats);
        }
    } finally {
        closeClipboard();
    }
    return DataTransferer.getInstance().translateBytes(data, flavor, format, localeTransferable);
}
Also used : Transferable(java.awt.datatransfer.Transferable) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 63 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project megameklab by MegaMek.

the class CriticalTransferHandler method exportDone.

@Override
public void exportDone(JComponent source, Transferable data, int action) {
    if (data == null) {
        return;
    }
    Mounted mounted = null;
    try {
        mounted = getUnit().getEquipment(Integer.parseInt((String) data.getTransferData(DataFlavor.stringFlavor)));
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (UnsupportedFlavorException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if ((source instanceof DropTargetCriticalList) && (mounted.getLocation() != Entity.LOC_NONE)) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) source;
        int loc;
        if (getUnit() instanceof BattleArmor) {
            String[] split = list.getName().split(":");
            loc = Integer.parseInt(split[0]);
        } else {
            loc = Integer.parseInt(list.getName());
            if (loc == mounted.getLocation()) {
                return;
            }
        }
        int slot = list.getSelectedIndex();
        int startSlot = slot;
        mounted = list.getMounted();
        if (mounted == null) {
            return;
        }
        if (UnitUtil.isFixedLocationSpreadEquipment(mounted.getType())) {
            return;
        }
        while (slot > 0) {
            slot--;
            CriticalSlot cs = getUnit().getCritical(loc, slot);
            if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) && cs.getMount().equals(mounted)) {
                startSlot = slot;
            }
        }
        if (!(getUnit() instanceof BattleArmor)) {
            for (int i = startSlot; i < (startSlot + UnitUtil.getCritsUsed(getUnit(), mounted.getType())); i++) {
                getUnit().setCritical(loc, i, null);
            }
        }
        Mounted linkedBy = mounted.getLinkedBy();
        if (linkedBy != null && !(getUnit() instanceof BattleArmor)) {
            UnitUtil.removeCriticals(getUnit(), linkedBy);
            try {
                UnitUtil.addMounted(getUnit(), linkedBy, mounted.getLocation(), linkedBy.isRearMounted());
            } catch (LocationFullException e) {
                UnitUtil.changeMountStatus(getUnit(), linkedBy, Entity.LOC_NONE, Entity.LOC_NONE, false);
                linkedBy.setLinked(null);
                mounted.setLinkedBy(null);
            }
        }
        // UnitUtil.compactCriticals(unit);
        refresh.refreshBuild();
    }
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) CriticalSlot(megamek.common.CriticalSlot) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 64 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project suite by stupidsing.

the class ClipboardUtil method getClipboardText.

public String getClipboardText() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clipboard.getContents(null);
    String text;
    if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor))
        try {
            text = contents.getTransferData(DataFlavor.stringFlavor).toString();
        } catch (UnsupportedFlavorException ex) {
            LogUtil.error(ex);
            text = "";
        } catch (IOException ex) {
            LogUtil.error(ex);
            text = "";
        }
    else
        text = "";
    return text;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 65 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project sldeditor by robward-scisys.

the class TreeTransferHandler method exportDone.

/*
     * (non-Javadoc)
     * 
     * @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
     */
@Override
protected void exportDone(JComponent source, Transferable data, int action) {
    if (!(source instanceof JTree) || (data == null)) {
        return;
    }
    JTree tree = (JTree) source;
    NodeInterface destinationTreeNode = (NodeInterface) tree.getLastSelectedPathComponent();
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    DataFlavor destDataFlavour = destinationTreeNode.getDataFlavour();
    TransferredData transferredData = null;
    try {
        transferredData = (TransferredData) data.getTransferData(destDataFlavour);
    } catch (UnsupportedFlavorException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    if (action == MOVE) {
        DataFlavourManager.deleteNodes(model, transferredData);
    }
    if (action != NONE) {
        DataFlavourManager.displayMessages(destinationTreeNode, transferredData, action);
    }
    setDragging(false);
}
Also used : JTree(javax.swing.JTree) TransferredData(com.sldeditor.datasource.extension.filesystem.dataflavour.TransferredData) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) NodeInterface(com.sldeditor.common.NodeInterface) DataFlavor(java.awt.datatransfer.DataFlavor)

Aggregations

UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)106 IOException (java.io.IOException)92 Transferable (java.awt.datatransfer.Transferable)55 List (java.util.List)32 DataFlavor (java.awt.datatransfer.DataFlavor)26 File (java.io.File)25 Point (java.awt.Point)18 ArrayList (java.util.ArrayList)15 Clipboard (java.awt.datatransfer.Clipboard)14 JTree (javax.swing.JTree)9 TreePath (javax.swing.tree.TreePath)9 JComponent (javax.swing.JComponent)7 TransferHandler (javax.swing.TransferHandler)7 DropTargetContext (java.awt.dnd.DropTargetContext)6 URL (java.net.URL)5 DefaultTableModel (javax.swing.table.DefaultTableModel)5 Image (java.awt.Image)4 ActionEvent (java.awt.event.ActionEvent)4 MouseEvent (java.awt.event.MouseEvent)4 NodeInterface (com.sldeditor.common.NodeInterface)3