this.image = fixedImg;
}
public void paste(Transferable t, NodeModel target, boolean asSibling, boolean isLeft, int dropAction) {
final ModeController modeController = Controller.getCurrentModeController();
final MMapController mapController = (MMapController) modeController.getMapController();
File mindmapFile = target.getMap().getFile();
if(mindmapFile == null) {
UITools.errorMessage(TextUtils.getRawText("map_not_saved"));
return;
}
final String mmFileName = mindmapFile.getName();
String fileNameTemplate = mmFileName.substring(0, mmFileName.lastIndexOf('.')) + "_";
while (fileNameTemplate.length() < 3)
fileNameTemplate = fileNameTemplate + '_';
//file that we'll save to disk.
File file;
try {
final File dir = mindmapFile.getParentFile();
file = File.createTempFile(fileNameTemplate, "."+IMAGE_FORMAT, dir);
String imgfilepath=file.getAbsolutePath();
File tempFile = file = new File(imgfilepath);
final JFileChooser fileChooser = new JFileChooser(file);
final ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension(IMAGE_FORMAT);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setFileFilter(filter);
fileChooser.setSelectedFile(file);
int returnVal = fileChooser.showSaveDialog(UITools.getFrame());
if (returnVal != JFileChooser.APPROVE_OPTION) {
tempFile.delete();
return;
}
file = fileChooser.getSelectedFile();
if(tempFile.exists() && ! file.getAbsoluteFile().equals(tempFile)){
tempFile.delete();
}
if(file.isDirectory())
return;
if(! FileUtils.getExtension(file.getName()).equals(IMAGE_FORMAT))
file = new File(file.getPath() + '.' + IMAGE_FORMAT);
final URI uri = LinkController.toLinkTypeDependantURI(mindmapFile, file);
ImageIO.write(image, IMAGE_FORMAT, file);
final NodeModel node = mapController.newNode(file.getName(), target.getMap());
final ExternalResource extension = new ExternalResource(uri);
node.addExtension(extension);
mapController.insertNode(node, target, asSibling, isLeft, isLeft);
}
catch (IOException e) {
e.printStackTrace();
}
}