2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2009-2010 Christian M. Zmasek
6 // Copyright (C) 2009-2010 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.archaeopteryx;
28 import java.awt.print.PrinterException;
29 import java.awt.print.PrinterJob;
31 import org.forester.util.ForesterUtil;
36 // Hidden constructor.
40 * Returns null if printing has been aborted by the user,
41 * a String otherwise -- if a printer name was obtained this String is
42 * the printer name, an empty String otherwise.
47 * @throws PrinterException
49 static String print( final TreePanel tree_panel, final String job_name ) throws PrinterException {
50 if ( ( tree_panel == null ) || ( tree_panel.getPhylogeny() == null ) ) {
51 throw new IllegalArgumentException( "attempt to print null" );
53 if ( ForesterUtil.isEmpty( job_name ) ) {
54 throw new IllegalArgumentException( "attempt use null or empty print job name" );
56 final PrinterJob printer_job = PrinterJob.getPrinterJob();
57 if ( printer_job != null ) {
58 printer_job.setJobName( job_name );
59 printer_job.setPrintable( tree_panel );
60 final boolean ok = printer_job.printDialog();
63 final String print_service_name = printer_job.getPrintService().getName();
64 if ( !ForesterUtil.isEmpty( print_service_name ) ) {
65 return print_service_name;
74 throw new PrinterException( "failed to access printer job" );