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