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