/** * Imports the data specified in TransferSupport into the component specified in TransferSupport * @param support * @return */ public boolean importData(STransferHandler.TransferSupport support) { return importData(support.getComponent(), support.getTransferable()); }
@Override public void actionPerformed(ActionEvent event) { SComponent component = (SComponent)event.getSource(); try { STransferHandler th = component.getTransferHandler(); Clipboard clipboard = component.getSession().getClipboard(); switch (this.name) { case "cut": // cut (MOVE) from component to clipboard th.exportToClipboard(component, clipboard, MOVE); break; case "copy": // copy (COPY) from component to clipboard th.exportToClipboard(component, clipboard, COPY); break; case "paste": // import the data from the clipboard Transferable transferable = clipboard.getContents(null); TransferSupport support = new TransferSupport(component, transferable); th.importData(support); break; } } catch(Exception e) { throw new RuntimeException(e); } } }
@Override public boolean importData(TransferSupport support) { if(support.isDrop()) { int index = ((STextComponent.DropLocation)support.getDropLocation()).getIndex(); ((STextComponent)support.getComponent()).setCaretPosition(index); ((STextComponent)support.getComponent()).setSelectionStart(index); ((STextComponent)support.getComponent()).setSelectionEnd(index); } return super.importData(support); }
private void drop(SComponent source, STransferHandler sourceTH, SComponent target, STransferHandler targetTH, int action, SMouseEvent mouseEvent) { // check for the custom drop-handler if (targetTH instanceof CustomDropHandler) { if (((CustomDropHandler) targetTH).drop(source, target, action, mouseEvent)) { return; } } transferSupport.setIsDrop(target, source, mouseEvent, action); if ((transferSupport.getSourceDropActions() & action) == 0) { // if dropping isn't allowed with the requested action resetDndStatus(); return; } // Import the data and call exportDone on the source-TH if (targetTH != null && targetTH.canImport(transferSupport)) { targetTH.importData(transferSupport); sourceTH.exportDone(source, transferSupport.getTransferable(), action); } resetDndStatus(); }