001package jmri.jmrit.operations.trains.tools; 002 003import java.awt.event.ActionEvent; 004import javax.swing.AbstractAction; 005 006import jmri.jmrit.operations.trains.Train; 007import jmri.util.swing.JmriJOptionPane; 008 009/** 010 * Action to print a train's build report 011 * 012 * @author Daniel Boudreau Copyright (C) 2010 013 */ 014public class PrintTrainBuildReportAction extends AbstractAction { 015 016 public PrintTrainBuildReportAction(boolean isPreview, Train train) { 017 super(isPreview ? Bundle.getMessage("MenuItemPreviewBuildReport") 018 : Bundle.getMessage("MenuItemPrintBuildReport")); 019 _isPreview = isPreview; 020 _train = train; 021 setEnabled(train != null); 022 } 023 024 /** 025 * Variable to set whether this is to be printed or previewed 026 */ 027 boolean _isPreview; 028 Train _train; 029 030 @Override 031 public void actionPerformed(ActionEvent e) { 032 if (_train == null) { 033 return; 034 } 035 if (!_train.isBuilt()) { 036 String printOrPreview = Bundle.getMessage("print"); 037 if (_isPreview) { 038 printOrPreview = Bundle.getMessage("preview"); 039 } 040 String string = Bundle.getMessage("DoYouWantToPrintPreviousBuildReport", printOrPreview, _train.getName()); 041 int results = JmriJOptionPane.showConfirmDialog(null, string, 042 Bundle.getMessage("PrintPreviousBuildReport", printOrPreview), JmriJOptionPane.YES_NO_OPTION); 043 if (results != JmriJOptionPane.YES_OPTION) { 044 return; 045 } 046 } 047 if (!_train.printBuildReport(_isPreview)) { 048 String string = Bundle.getMessage("NeedToBuildTrainBeforePrinting", _train.getName()); 049 JmriJOptionPane.showMessageDialog(null, string, Bundle.getMessage("CanNotPrintBuildReport"), 050 JmriJOptionPane.ERROR_MESSAGE); 051 return; 052 } 053 } 054}