I'm using JFreeChart
inside of a ChartPanel
with SWT_AWT
bridging. What I want to do is use the SWT to handle the printing of the chart. Is there a way to take the chartpanel
and draw it onto the printer GC from SWT?
JFreeChart chart = createXYChart(createDataset(v2, v1));
Composite comp = new Composite(parent, SWT.NONE | SWT.EMBEDDED);
chart.removeLegend();
//ChartComposite c = new ChartComposite(parent, SWT.NONE | SWT.EMBEDDED, chart, true);
Frame frame = SWT_AWT.new_Frame(comp);
ChartPanel panel = new ChartPanel(chart);
panel.setMaximumDrawHeight(10000);
panel.setMinimumDrawHeight(0);
panel.setMaximumDrawWidth(10000);
panel.setMinimumDrawWidth(0);
panel.setPopupMenu(null);
frame.add(panel);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
PrintDialog dialog = new PrintDialog(shell);
try {
//PrinterData printerData = Printer.getDefaultPrinterData();
PrinterData printerData = dialog.open();
if (printerData != null) {
Printer printer = new Printer(printerData);
if (printer.startJob("Text")) {
GC gc = new GC(printer);
if (printer.startPage()) {
gc.drawString("HDSDFSDFSDFSDFDS", 0, 0);
//WANT TO PRINT CHART SOMEHOW HERE
printer.endPage();
}
gc.dispose();
printer.endJob();
}
printer.dispose();
System.out.println("Print job done.");
}
} catch (Exception exception) {
exception.printStackTrace();
}