下面列出了javax.swing.TransferHandler#DropLocation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferSupport info) {
TransferHandler.DropLocation dropLocation = info.getDropLocation();
if (!canImport(info) || !(dropLocation instanceof JList.DropLocation)) {
return false;
}
JList.DropLocation dl = (JList.DropLocation) dropLocation;
JList target = (JList) info.getComponent();
DefaultListModel listModel = (DefaultListModel) target.getModel();
int max = listModel.getSize();
int index = dl.getIndex();
index = index < 0 ? max : index;
// make sure to append at the end if index > size
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 e) {
// should never happen, log anyway to be safe
LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.tools.dnd.ExtendedJListTransferHandler.unexpected_error", e);
}
return false;
}
@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;
}
}
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Calculates a custom drop location for the text component,
* representing where a drop at the given point should insert data.
*/
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);
/**
* Called to set or clear the drop location during a DnD operation.
*/
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
Object state, boolean forDrop);