001package jmri.jmrit.operations.trains.tools;
002
003import java.awt.Frame;
004import java.awt.event.ActionEvent;
005
006import javax.swing.AbstractAction;
007
008import jmri.jmrit.operations.trains.Train;
009
010/**
011 * Swing action to create and register a ShowCarsInTrainFrame.
012 *
013 * @author Bob Jacobsen Copyright (C) 2001
014 * @author Daniel Boudreau Copyright (C) 2012
015 */
016public class ShowCarsInTrainAction extends AbstractAction {
017
018    Train _train;
019
020    public ShowCarsInTrainAction(Train train) {
021        super(Bundle.getMessage("MenuItemShowCarsInTrain"));
022        _train = train;
023    }
024
025    ShowCarsInTrainFrame f = null;
026
027    @Override
028    public void actionPerformed(ActionEvent e) {
029        if (f == null || !f.isVisible()) {
030            f = new ShowCarsInTrainFrame();
031            f.initComponents(_train);
032        } else {
033            f.setExtendedState(Frame.NORMAL);
034            f.setVisible(true); // this also brings the frame into focus
035        }
036    }
037}
038
039