001package jmri.jmrix.nce.consist; 002 003import java.awt.Frame; 004import java.awt.event.ActionEvent; 005import java.util.List; 006import javax.swing.AbstractAction; 007import jmri.InstanceManager; 008import jmri.util.davidflanagan.HardcopyWriter; 009import org.slf4j.Logger; 010import org.slf4j.LoggerFactory; 011 012/** 013 * Action to print a summary of the Roster contents 014 * <p> 015 * This uses the older style printing, for compatibility with Java 1.1.8 in 016 * Macintosh MRJ 017 * 018 * @author Bob Jacobsen Copyright (C) 2003 019 * @author Dennis Miller Copyright (C) 2005 020 * @author Daniel Boudreau Copyright (C) 2008 021 */ 022public class PrintNceConsistRosterAction extends AbstractAction { 023 024 public PrintNceConsistRosterAction(String actionName, Frame frame, boolean preview) { 025 super(actionName); 026 mFrame = frame; 027 isPreview = preview; 028 } 029 030 /** 031 * Frame hosting the printing 032 */ 033 Frame mFrame; 034 /** 035 * Variable to set whether this is to be printed or previewed 036 */ 037 boolean isPreview; 038 039 @Override 040 public void actionPerformed(ActionEvent e) { 041 042 // obtain a HardcopyWriter to do this 043 HardcopyWriter writer = null; 044 try { 045 writer = new HardcopyWriter(mFrame, Bundle.getMessage("NcePrintRosterTitle"), null, null, 10, 046 .5 * 72, .5 * 72, .5 * 72, .5 * 72, isPreview, null, null, null, null, null); 047 } catch (HardcopyWriter.PrintCanceledException ex) { 048 log.debug("Print cancelled"); 049 return; 050 } 051 052 // add the icon 053 writer.writeDecoderProIcon(true); 054 055 // Loop through the Roster, printing as needed 056 NceConsistRoster r = InstanceManager.getDefault(NceConsistRoster.class); 057 List<NceConsistRosterEntry> list = r.matchingList(null, null, null, null, null, null, null, null, null, null); // take all 058 059 log.debug("Roster list size: {}", list.size()); 060 for (NceConsistRosterEntry entry : list) { 061 entry.printEntry(writer); 062 } 063 064 // and force completion of the printing 065 writer.close(); 066 } 067 068 private final static Logger log = LoggerFactory.getLogger(PrintNceConsistRosterAction.class); 069 070}