001package jmri.jmrit.operations.trains.gui;
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 TrainConductor frame.
012 *
013 * @author Bob Jacobsen Copyright (C) 2001
014 * @author Daniel Boudreau Copyright (C) 2011
015 */
016public class TrainConductorAction extends AbstractAction {
017
018    Train _train;
019    TrainConductorFrame f = null;
020
021    public TrainConductorAction(Train train) {
022        super(Bundle.getMessage("TitleTrainConductor"));
023        _train = train;
024        setEnabled(train != null);
025    }
026
027    @Override
028    public void actionPerformed(ActionEvent e) {
029        // create a copy train frame
030        if (f == null || !f.isVisible()) {
031            f = new TrainConductorFrame(_train);
032        } else {
033            f.setExtendedState(Frame.NORMAL);
034        }
035        f.setVisible(true); // this also brings the frame into focus
036    }
037}
038
039