0
头像

使用 Java Plugin API 导出质粒图谱

哪些 Geneious API 类用于从 Geneious 导出质粒图?从 Geneious 中,我选择一个质粒文件,然后转到 File-> Save As Image File 并提示输入要保存的图像的格式和尺寸。我想将此功能添加到现有的 Geneious Java 插件中。这是怎么做的?

桑德拉·彼得斯

1条评论

0
头像

Here's a method which you can hopefully adapt to your needs:

/**
* Export the sequence view of each document as a PNG image.注意:The sequence view will adopt whatever setting the user
* has most recently used.
*
* @param documents documents to export
* @param outputFolder folder to save PNGs in, each file will be named after the document:'document.getName() + ".png"'
* @param imageSize the resolution (in pixels) of the png file to export to, imageSize x imageSize (square)
*/
static void batchExportSequenceViewAsPng(AnnotatedPluginDocument[] documents, File outputFolder, int imageSize) throws DocumentOperationException {
outputFolder.mkdirs();
for (AnnotatedPluginDocument doc : documents) {
List<DocumentViewerFactory> documentViewerFactories = PluginUtilities.getDocumentViewerFactories(doc);
for(DocumentViewerFactory factory : documentViewerFactories) {
AtomicReference<DocumentOperationException> exception = new AtomicReference<>();
String className = factory.getClass().getCanonicalName();
if(className != null && className.equals("com.biomatters.plugins.sequenceviewer.SequenceViewerPlugin.SequenceViewerFactory")
&& !factory.getName().contains("Annotation")) {
ThreadUtilities.invokeNowOrWait(() -> {
final DocumentViewer documentViewer = factory.createViewer(new AnnotatedPluginDocument[] {doc});
if (documentViewer == null) {
return;
}
JFrame dummyFrame = new JFrame();
dummyFrame.getContentPane().add(documentViewer.getComponent());
dummyFrame.pack();
ExtendedPrintable extendedPrintable = documentViewer.getExtendedPrintable();
if (extendedPrintable == null) {
return;
}
final BufferedImage image = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB);
try {
Graphics2D g = image.createGraphics();
g.setClip(0,0, imageSize, imageSize);
Options options = extendedPrintable.getOptions(true);
options.setStringValue("printVisibleRegionOnly", "false");
extendedPrintable.print(g, new Dimension(imageSize, imageSize), 0, options);
g.dispose();
} catch (PrinterException e) {
exception.set(new DocumentOperationException(e));
}
try {
String fileName = FileUtilities.getLegalFileName(doc.getName(), " ");
ImageIO.write(image, "png", new File(outputFolder, fileName + ".png"));
} catch (IOException e) {
exception.set(new DocumentOperationException(e));
}
NoLongerViewedListener listener = documentViewer.getNoLongerViewedListener();
if(listener != null) {
listener.noLongerViewed(false);
}
});
}
if (exception.get() != null) {
throw exception.get();
}
}
}
}
理查德·摩尔 0 votes
评论动作 永久链接