// If all is true, loop through all selections in chart, asking it to // grab the data and print each one. public void print(boolean all) { Toolkit tk = getToolkit(); PrintJob pj = tk.getPrintJob(chart, all ? "All charts" : chart.current_tradable(), print_properties); if (pj != null) { if (all) { Vector selections = chart.tradable_selections().selections(); for (int i = 0; i < selections.size(); ++i) { chart.request_data((String) selections.elementAt(i)); if (chart.request_result_id() == Ok) { print_current_chart(pj); } } } else { print_current_chart(pj); } pj.end(); } }
private void print_current_chart(PrintJob pj) { Graphics page = pj.getGraphics(); Dimension size = graph_panel.getSize(); Dimension pagesize = pj.getPageDimension(); main_graph.set_symbol(chart.current_tradable().toUpperCase()); if (size.width <= pagesize.width) { // Center the output on the page. page.translate((pagesize.width - size.width) / 2, (pagesize.height - size.height) / 2); } else { // The graph size is wider than a page, so print first // the left side, then the right side. Assumption - it is // not larger than two pages. page.translate(15, (pagesize.height - size.height) / 2); graph_panel.printAll(page); page.dispose(); page = pj.getGraphics(); page.translate(pagesize.width - size.width - 13, (pagesize.height - size.height) / 2); } graph_panel.printAll(page); page.dispose(); main_graph.set_symbol(null); }