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 for every location in the train's
016 * route.
017 * <p>
018 * This uses the older style printing, for compatibility with Java 1.1.8 in
019 * Macintosh MRJ
020 *
021 * @author Daniel Boudreau Copyright (C) 2025
022 */
023public class PrintShowCarsInTrainRouteAction extends AbstractAction implements PropertyChangeListener {
024
025    public PrintShowCarsInTrainRouteAction(boolean isPreview, Train train) {
026        super(isPreview ? Bundle.getMessage("MenuItemCarsInTrainPreview")
027                : Bundle.getMessage("MenuItemCarsInTrainPrint"));
028        _isPreview = isPreview;
029        _train = train;
030        if (train != null) {
031            setEnabled(train.isBuilt());
032            train.addPropertyChangeListener(this);
033        }
034    }
035
036    boolean _isPreview;
037    Train _train;
038
039    @Override
040    public void actionPerformed(ActionEvent e) {
041        new PrintShowCarsInTrain().printCarsInTrainRoute(_train, _isPreview);
042    }
043
044    @Override
045    public void propertyChange(PropertyChangeEvent e) {
046        log.debug("Property change {} for: {} old: {} new: {}", e.getPropertyName(), e.getSource(), e.getOldValue(),
047                e.getNewValue()); // NOI18N
048        if (e.getPropertyName().equals(Train.BUILT_CHANGED_PROPERTY)) {
049            setEnabled(_train.isBuilt());
050        }
051    }
052
053    private final static Logger log = LoggerFactory.getLogger(PrintShowCarsInTrainRouteAction.class);
054}