TransferSupport Class

TransferSupport类具有两个功能。顾名思义,其第一个功能是支持传输过程,为此,它提供了几种用于访问数据传输详细信息的实用方法。以下列表显示了可用于从TransferHandler获取信息的方法。这些方法中有几种与放置动作有关,将在设置放置 Pattern中讨论。

samples 导入方法

现在您已熟悉TransferSupportUtil 方法,让我们看一下示例canImportimportData方法:

public boolean canImport(TransferSupport supp) {
    // Check for String flavor
    if (!supp.isDataFlavorSupported(stringFlavor)) {
        return false;
    }

    // Fetch the drop location
    DropLocation loc = supp.getDropLocation();

    // Return whether we accept the location
    return shouldAcceptDropLocation(loc);
}

public boolean importData(TransferSupport supp) {
    if (!canImport(sup)) {
        return false;
    }

    // Fetch the Transferable and its data
    Transferable t = supp.getTransferable();
    String data = t.getTransferData(stringFlavor);

    // Fetch the drop location
    DropLocation loc = supp.getDropLocation();

    // Insert the data at this location
    insertAt(loc, data);

    return true;
}

接下来,我们看一下如何为所选组件设置放置 Pattern。

首页