@Override public boolean importData(JComponent comp, Transferable t) { DataFlavor htmlFlavor = DataFlavor.stringFlavor; if (canImport(comp, t.getTransferDataFlavors())) { try { String transferString = (String) t.getTransferData(htmlFlavor); EditorPane targetTextPane = (EditorPane) comp; for (Map.Entry<String, String> entry : _copiedImgs.entrySet()) { String imgName = entry.getKey(); String imgPath = entry.getValue(); File destFile = targetTextPane.copyFileToBundle(imgPath); String newName = destFile.getName(); if (!newName.equals(imgName)) { String ptnImgName = "\"" + imgName + "\""; newName = "\"" + newName + "\""; transferString = transferString.replaceAll(ptnImgName, newName); Debug.info(ptnImgName + " exists. Rename it to " + newName); } } targetTextPane.insertString(transferString); } catch (Exception e) { Debug.error(me + "importData: Problem pasting text\n%s", e.getMessage()); } return true; } return false; }
private void dumpFlavorsOld(Transferable t) { DataFlavor[] dfa = t.getTransferDataFlavors(); if (dfa != null) { if (dfa.length == 0) { JConfig.log().logVerboseDebug("Trying a second attack..."); try { Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable t2 = sysClip.getContents(null); StringBuffer stBuff; stBuff = getTransferData(t2); JConfig.log().logVerboseDebug("Check out: " + stBuff); } catch (Exception e) { JConfig.log().handleException("Caught: " + e, e); } JConfig.log().logVerboseDebug("Done trying a second attack..."); } } dumpDataFlavors(dfa); }
public void drop(DropTargetDropEvent dtde) { Transferable t = dtde.getTransferable(); StringBuffer dropData = null; DataFlavor dtf; JConfig.log().logVerboseDebug("Dropping!"); if (t.getTransferDataFlavors().length == 0) { Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable t2 = sysClip.getContents(null); DataFlavor[] dfa2; int j; JConfig.log().logDebug("Dropped 0 data flavors, trying clipboard."); dfa2 = null; if (t2 != null) { JConfig.log().logVerboseDebug("t2 is not null: " + t2); dfa2 = t2.getTransferDataFlavors(); JConfig.log().logVerboseDebug("Back from getTransferDataFlavors()!"); } else { JConfig.log().logVerboseDebug("t2 is null!"); } if (JConfig.queryConfiguration("debug.uber", "false").equals("true")) { if (dfa2 != null) { if (dfa2.length == 0) { JConfig.log().logVerboseDebug("Length is still zero!"); } for (j = 0; j < dfa2.length; j++) { JConfig.log() .logVerboseDebug("Flavah " + j + " == " + dfa2[j].getHumanPresentableName()); JConfig.log().logVerboseDebug("Flavah/mime " + j + " == " + dfa2[j].getMimeType()); } } else { JConfig.log().logVerboseDebug("Flavahs supported: none!\n"); } } } if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging) dumpFlavorsOld(t); dtf = testAllFlavors(t); if (dtf != null) { JConfig.log().logVerboseDebug("Accepting!"); acceptDrop(dtde); dropData = getTransferData(t); dtde.dropComplete(true); dtde.getDropTargetContext().dropComplete(true); if (dropData != null) { if (handler != null) { handler.receiveDropString(dropData); } } } else { JConfig.log().logVerboseDebug("Rejecting!"); dtde.rejectDrop(); handler.receiveDropString(dropData); } }