javax.swing.TransferHandler.TransferSupport#isDrop ( )源码实例Demo

下面列出了javax.swing.TransferHandler.TransferSupport#isDrop ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: audiveris   文件: FileDropHandler.java
@Override
public boolean canImport (TransferSupport support)
{
    /* For the time being, only support drops (not clipboard paste) */
    if (!support.isDrop()) {
        return false;
    }

    /* Check that the drop contains a list of files */
    if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        return false;
    }

    /* Check to see if the source actions contains the COPY action */
    boolean copySupported = (COPY & support.getSourceDropActions()) == COPY;

    /* If COPY is supported, choose COPY and accept the transfer */
    if (copySupported) {
        support.setDropAction(COPY);

        return true;
    }

    /* COPY isn't supported, so reject the transfer */
    return false;
}
 
@Override
public boolean importData(TransferSupport ts) {
    if (canImport(ts)) {
        ObjectRepDnD oDnd;
        try {
            oDnd = (ObjectRepDnD) ts.getTransferable().getTransferData(OBJECT_FLAVOR);
        } catch (UnsupportedFlavorException | IOException ex) {
            Logger.getLogger(ObjectDnD.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
        Object object = getDestinationObject(ts);
        Boolean shouldCut = ts.isDrop() ? ts.getDropAction() == MOVE : isCut;
        if (object instanceof ORPageInf) {
            if (oDnd.isGroup()) {
                copyObjectGroups((ORPageInf) object, oDnd, shouldCut);
                return true;
            } else if (oDnd.isObject()) {
                copyObjects((ORPageInf) object, oDnd, shouldCut);
                return true;
            }
        } else if (object instanceof ObjectGroup) {
            if (oDnd.isObject()) {
                copyObjects((ObjectGroup) object, oDnd, shouldCut);
                return true;
            }
        } else if (object instanceof ORObjectInf) {
            if (oDnd.isObject()) {
                if (copyObjects(((ORObjectInf) object).getParent(), oDnd, shouldCut)) {
                    if (((ORObjectInf) object).getParent().getChildCount() == 2) {
                        reload(((ORObjectInf) object).getParent().getParent());
                    }
                }
                return true;
            }
        }
    }
    return false;
}
 
private Object getDestinationObject(TransferSupport ts) {
    TreePath path;
    if (ts.isDrop()) {
        path = ((JTree.DropLocation) ts.getDropLocation()).getPath();
    } else {
        path = ((JTree) ts.getComponent()).getSelectionPath();
    }
    if (path != null) {
        return path.getLastPathComponent();
    }
    return null;
}
 
源代码4 项目: libreveris   文件: FileDropHandler.java
/**
 * {@inheritDoc}
 */
@Override
public boolean canImport (TransferSupport support)
{
    /* For the time being, only support drops (not clipboard paste) */
    if (!support.isDrop()) {
        return false;
    }

    /* Check that the drop contains a list of files */
    if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        return false;
    }

    /* Check to see if the source actions contains the COPY action */
    boolean copySupported = (COPY & support.getSourceDropActions()) == COPY;

    /* If COPY is supported, choose COPY and accept the transfer */
    if (copySupported) {
        support.setDropAction(COPY);

        return true;
    }

    /* COPY isn't supported, so reject the transfer */
    return false;
}
 
源代码5 项目: jeveassets   文件: ShowToolSettingsPanel.java
@Override
public boolean canImport(TransferSupport info) {
	return info.isDrop() && info.isDataFlavorSupported(localObjectFlavor);
}