DropLocation dl = transferSupport.getDropLocation();
Point p = dl.getDropPoint();
Position release = new Position(p.getX(), p.getY());
Argument finishArgument = ketPanel.findDeepestArgument(release);
if (finishArgument==null) {
Equation finishEquation = finishArgument!=null ?
finishArgument.getEquation() :
ketPanel.pointToEquation(release);
if (finishEquation==null) {
Ket.out.println(" !!! No argument at mouse release location !!! ");
return false;
}
finishArgument = finishEquation.getRoot();
}
mathCollection.getSelection().setOnly(finishArgument);
if ( ! canImport(transferSupport) ) {
return false;
}
Transferable t = transferSupport.getTransferable();
String string = null;
try {
string = (String) t.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException e) {
Ket.out.println(" !!! A string-flavor transfer exception occurred while reading (drag and drop) transfer data !!! ");
return false;
} catch (IOException ioe) {
Ket.out.println(" !!! IO Exception while reading (drag and drop) transfer data !!! ");
return false;
}
String[] lines = string.split("\n");
// TODO: Re-join wrapped lines, 'text... \'?
if (lines.length==1) {
// Single line.
Argument arg = ArgumentParser.parseArgument(string, knownArguments, clipboard, mathCollection);
if (arg!=null) {
Selection selection = mathCollection.getSelection();
Equation appendedEquation = new Equation(arg);
selection.appendEquation(appendedEquation);
}