001package jmri.jmrit.operations.trains.tools;
002
003import java.awt.event.ActionEvent;
004import java.beans.PropertyChangeEvent;
005import java.beans.PropertyChangeListener;
006
007import javax.swing.AbstractAction;
008
009import org.slf4j.Logger;
010import org.slf4j.LoggerFactory;
011
012import jmri.jmrit.operations.trains.Train;
013
014/**
015 * Action to print the cars in the train.
016 * <p>
017 * This uses the older style printing, for compatibility with Java 1.1.8 in
018 * Macintosh MRJ
019 *
020 * @author Daniel Boudreau Copyright (C) 2025
021 */
022public class PrintShowCarsInTrainAction extends AbstractAction implements PropertyChangeListener {
023
024    public PrintShowCarsInTrainAction(Train train, boolean isPreview) {
025        super(isPreview ? Bundle.getMessage("MenuItemCarsInTrainPreview")
026                : Bundle.getMessage("MenuItemCarsInTrainPrint"));
027        _isPreview = isPreview;
028        _train = train;
029        train.addPropertyChangeListener(this);
030    }
031
032    boolean _isPreview;
033    Train _train;
034
035    @Override
036    public void actionPerformed(ActionEvent e) {
037        new PrintShowCarsInTrain(_train, _isPreview);
038    }
039
040    @Override
041    public void propertyChange(PropertyChangeEvent e) {
042        log.debug("Property change {} for: {} old: {} new: {}", e.getPropertyName(), e.getSource(), e.getOldValue(),
043                e.getNewValue()); // NOI18N
044        if (e.getPropertyName().equals(Train.BUILT_CHANGED_PROPERTY)) {
045            setEnabled(_train.isBuilt());
046        }
047    }
048
049    private final static Logger log = LoggerFactory.getLogger(PrintShowCarsInTrainAction.class);
050}