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"), 10, .5, .5, .5, .5, isPreview); 046 } catch (HardcopyWriter.PrintCanceledException ex) { 047 log.debug("Print cancelled"); 048 return; 049 } 050 051 // add the icon 052 writer.writeDecoderProIcon(true); 053 054 // Loop through the Roster, printing as needed 055 NceConsistRoster r = InstanceManager.getDefault(NceConsistRoster.class); 056 List<NceConsistRosterEntry> list = r.matchingList(null, null, null, null, null, null, null, null, null, null); // take all 057 058 log.debug("Roster list size: {}", list.size()); 059 for (NceConsistRosterEntry entry : list) { 060 entry.printEntry(writer); 061 } 062 063 // and force completion of the printing 064 writer.close(); 065 } 066 067 private final static Logger log = LoggerFactory.getLogger(PrintNceConsistRosterAction.class); 068 069}