类javax.swing.TransferHandler.TransferSupport源码实例Demo

下面列出了怎么用javax.swing.TransferHandler.TransferSupport的API类实例代码及写法,或者点击链接到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 void dragStarted(Transferable t) {
	TransferSupport support = new TransferSupport(this, t);
	boolean doesSupportFlavor = ((DataTableColumnDropTextFieldTransferHandler) getTransferHandler())
			.doesSupportFlavor(support);

	if (doesSupportFlavor) {
		switch (RapidMinerGUI.getDragHighlighteMode()) {
			case FULL:
				setBackground(ProcessDrawer.INNER_DRAG_COLOR);
			case BORDER:
				setBorder(ongoingDropBorder);
				break;
			default:
				break;

		}
	}
}
 
@Override
public boolean canImport(TransferSupport ts) {
    return ts.getComponent().equals(tree)
            && ts.isDataFlavorSupported(OBJECT_FLAVOR)
            && getDestinationObject(ts) != null
            && !(getDestinationObject(ts) instanceof ORRootInf);
}
 
@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;
}
 
@Override
public void dragStarted(Transferable t) {
	TransferSupport support = new TransferSupport(this, t);
	boolean doesSupportFlavor = ((PlotConfigurationTreeTransferHandler) plotConfigurationTree.getTransferHandler())
			.doesSupportFlavor(support);

	if (doesSupportFlavor) {
		if (SwingUtilities.isEventDispatchThread()) {
			switch (RapidMinerGUI.getDragHighlighteMode()) {
				case FULL:
					plotConfigurationTree.setBackground(ProcessDrawer.INNER_DRAG_COLOR);
				case BORDER:
					plotConfigurationTreeScrollPane.setBorder(ONGOING_DROP_BORDER);
					break;
				default:
					break;

			}
		} else {
			SwingUtilities.invokeLater(new Runnable() {

				@Override
				public void run() {
					switch (RapidMinerGUI.getDragHighlighteMode()) {
						case FULL:
							plotConfigurationTree.setBackground(ProcessDrawer.INNER_DRAG_COLOR);
						case BORDER:
							plotConfigurationTreeScrollPane.setBorder(ONGOING_DROP_BORDER);
							break;
						default:
							break;

					}
				}
			});
		}
	}
}
 
源代码7 项目: jeveassets   文件: ShowToolSettingsPanel.java
@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferSupport info) {
	TransferHandler.DropLocation tdl = info.getDropLocation();
	if (!canImport(info) || !(tdl instanceof JList.DropLocation)) {
		return false;
	}

	JList.DropLocation dl = (JList.DropLocation) tdl;
	JList<?> target = (JList) info.getComponent();
	DefaultListModel<Object> listModel = (DefaultListModel) target.getModel();
	int max = listModel.getSize();
	int index = dl.getIndex();
	index = index < 0 ? max : index; // If it is out of range, it is appended to the end
	index = Math.min(index, max);

	addIndex = index;

	try {
		Object[] values = (Object[]) info.getTransferable().getTransferData(localObjectFlavor);
		for (Object value : values) {
			int idx = index++;
			listModel.add(idx, value);
			target.addSelectionInterval(idx, idx);
		}
		addCount = values.length;
		return true;
	} catch (UnsupportedFlavorException | IOException ex) {
		LOG.error(ex.getMessage(), ex);
		return false;
	}
}
 
源代码8 项目: 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;
}
 
源代码9 项目: netbeans   文件: ClipboardHandler.java
@Override
public boolean canImport(TransferSupport support) {
    return delegate.canImport(support);
}
 
源代码10 项目: RobotBuilder   文件: TreeTransferHandler.java
@Override
public boolean canImport(TransferSupport support) {
    if (!support.isDrop()) {
        return false;
    }
    support.setShowDropLocation(true);
    JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
    TreePath path = dl.getPath();
    if (path == null) {
        return false;
    }
    RobotComponent target = (RobotComponent) path.getLastPathComponent();
    if (support.getTransferable().isDataFlavorSupported(DataFlavor.stringFlavor)) {
        String data;
        try {
            data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException | IOException e) {
            return false;
        }
        PaletteComponent base = Palette.getInstance().getItem(data);
        assert base != null; // TODO: Handle more gracefully
        return target.supports(base);
    } else if (support.getTransferable().isDataFlavorSupported(RobotTree.ROBOT_COMPONENT_FLAVOR)) {
        RobotComponent data;
        try {
            data = (RobotComponent) support.getTransferable().getTransferData(RobotTree.ROBOT_COMPONENT_FLAVOR);
        } catch (UnsupportedFlavorException e) {
            System.out.println("UnsupportedFlavor");
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("IOException");
            return false;
        }
        if (dl.getChildIndex() == -1
            && target.getChildren().contains(data)) {
            // Cannot drag something into its own parent
            // (This allows for reordering)
            return false;
        }
        Set<String> invalid = new HashSet();
        invalid.add("Robot");
        invalid.add("Subsystems");
        invalid.add("OI");
        invalid.add("Commands");
        if (data == null) {
            return false;
        }
        if (invalid.contains(data.getBase().getType())) {
            return false;
        }
        return target.supports(data);
    } else {
        System.out.println("Unsupported flavor. The flavor you have chosen is not sufficiently delicious.");
        return false;
    }
}
 
源代码11 项目: jeveassets   文件: ShowToolSettingsPanel.java
@Override
public boolean canImport(TransferSupport info) {
	return info.isDrop() && info.isDataFlavorSupported(localObjectFlavor);
}
 
源代码12 项目: binnavi   文件: DragAndDropSupportWrapper.java
/**
 * Sets the transfer support instance which contains all relevant information to handle the drag
 * and drop operation.
 *
 * @param support The transfer support for the drag and drop operation.
 */
public void setSupport(final TransferSupport support) {
  this.support = support;
}
 
 类所在包
 同包方法