001package jmri.jmrit.operations.trains.tools;
002
003import java.awt.event.ActionEvent;
004
005import javax.swing.AbstractAction;
006
007import jmri.jmrit.operations.trains.Train;
008import jmri.util.swing.JmriJOptionPane;
009
010/**
011 * Action to print a train's manifest
012 *
013 * @author Daniel Boudreau Copyright (C) 2010
014 */
015public class PrintTrainManifestAction extends AbstractAction {
016
017    public PrintTrainManifestAction(boolean isPreview, Train train) {
018        super(isPreview ? Bundle.getMessage("MenuItemPreviewManifest") : Bundle.getMessage("MenuItemPrintManifest"));
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("DoYouWantToPrintPreviousManifest",
041                    printOrPreview, _train.getName());
042            int results = JmriJOptionPane.showConfirmDialog(null, string, 
043                    Bundle.getMessage("PrintPreviousManifest", printOrPreview),
044                    JmriJOptionPane.YES_NO_OPTION);
045            if (results != JmriJOptionPane.YES_OPTION) {
046                return;
047            }
048        }
049        try {
050            if (!_train.printManifest(_isPreview)) {
051                String string = Bundle.getMessage("NeedToBuildTrainBeforePrinting",
052                        _train.getName());
053                JmriJOptionPane.showMessageDialog(null, string,
054                        Bundle.getMessage("CanNotPrintManifest", Bundle.getMessage("print")),
055                        JmriJOptionPane.ERROR_MESSAGE);
056            }
057        } catch (jmri.jmrit.operations.trains.BuildFailedException e1) {
058        }
059    }
060
061
062//    private final static Logger log = LoggerFactory.getLogger(PrintTrainManifestAction.class);
063}