001package jmri.jmrit.operations.locations.tools;
002
003import java.awt.Frame;
004import java.awt.event.ActionEvent;
005
006import javax.swing.AbstractAction;
007
008import jmri.jmrit.operations.locations.Location;
009import jmri.jmrit.operations.locations.Track;
010
011/**
012 * Swing action to create and register a TrackCopyFrame object.
013 *
014 * @author Bob Jacobsen Copyright (C) 2001
015 * @author Daniel Boudreau Copyright (C) 2011
016 */
017public class TrackCopyAction extends AbstractAction {
018
019    public TrackCopyAction() {
020        super(Bundle.getMessage("MenuItemCopyTrack"));
021    }
022    
023    public TrackCopyAction(Track track, Location destination) {
024        this();
025        _track = track;
026        _destination = destination;
027    }
028    
029    // track to copy
030    Track _track;
031    // copy track to destination
032    Location _destination;
033
034    TrackCopyFrame f = null;
035
036    @Override
037    public void actionPerformed(ActionEvent e) {
038        // create a copy track frame
039        if (f == null || !f.isVisible()) {
040            f = new TrackCopyFrame(_track, _destination);
041        }
042        f.setExtendedState(Frame.NORMAL);
043        f.setVisible(true); // this also brings the frame into focus
044    }
045}
046
047