Java Code Examples for javax.swing.TransferHandler.TransferSupport#isDrop()

The following examples show how to use javax.swing.TransferHandler.TransferSupport#isDrop() . 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: FileDropHandler.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ObjectDnD.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: ObjectDnD.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: FileDropHandler.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@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;
}
 
Example 5
Source File: ShowToolSettingsPanel.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean canImport(TransferSupport info) {
	return info.isDrop() && info.isDataFlavorSupported(localObjectFlavor);
}