我正在开发一个包含 JFreeChart 的 Eclipse RCP 应用程序。它的功能之一是将图形复制到剪贴板以便将它们粘贴到其他应用程序中,但它不适用于 Linux,
有一个SWT 示例,您可以在其中找到在 Linux 中不起作用的片段。
另一方面,JFreeChart 在 AWT 上实现了这一点:
Clipboard systemClipboard
= Toolkit.getDefaultToolkit().getSystemClipboard();
Insets insets = getInsets();
int w = getWidth() - insets.left - insets.right;
int h = getHeight() - insets.top - insets.bottom;
ChartTransferable selection = new ChartTransferable(this.chart, w, h,
getMinimumDrawWidth(), getMinimumDrawHeight(),
getMaximumDrawWidth(), getMaximumDrawHeight(), true);
systemClipboard.setContents(selection, null);
但是,这两个示例在 Linux 64 位上都失败了。有没有办法实现它??
提前致谢!
编辑:
将 JFreeChart 图形复制到文件但不复制到剪贴板的代码
final org.eclipse.swt.dnd.Clipboard clipboard = new org.eclipse.swt.dnd.Clipboard(menu.getDisplay());
Insets insets = source.getInsets();
int w = source.getWidth() - insets.left - insets.right;
int h = source.getHeight() - insets.top - insets.bottom;
ChartTransferable selection = new ChartTransferable(source
.getChart(), w, h, source.getMinimumDrawWidth(), source.getMinimumDrawHeight(), source
.getMaximumDrawWidth(), source.getMaximumDrawHeight(), true);
Image image = new Image(menu.getDisplay(),ImageUtils.convertToSWT(selection.getBufferedImage()));
if (image != null) {
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
imageLoader.save("/tmp/graph.jpg", SWT.IMAGE_JPEG); // fails
ImageTransfer imageTransfer = ImageTransfer.getInstance();
clipboard.setContents(new Object[]{image.getImageData()},
new Transfer[]{imageTransfer}, DND.CLIPBOARD | DND.SELECTION_CLIPBOARD);
}