@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); } } }
/** * Exports component's data for a drag-operation - it is required for this method to call * the setTransferSupport Method in the SDragAndDropManager to set a TransferSupport, to be used for this * drag-operation * @param component * @param event * @param action */ public void exportAsDrag(SComponent component, SMouseEvent event, int action) { // (Swing) InputEvent -> (wingS) SMouseEvent int sourceActions = this.getSourceActions(component); // invalid action or requested action != actions allowed by source if((action != MOVE && action != COPY && action != LINK) || (sourceActions & action) == 0) { action = NONE; } if(action != NONE) { Transferable transferable = createTransferable(component, event); component.getSession().getSDragAndDropManager().setTransferSupport(new TransferSupport(component, transferable)); } else { exportDone(component, null, NONE); } }