001package jmri.jmrit.operations.rollingstock.engines;
002
003import java.awt.Dimension;
004import java.util.List;
005import java.util.ResourceBundle;
006
007import javax.swing.JOptionPane;
008
009import jmri.InstanceManager;
010import jmri.jmrit.operations.OperationsXml;
011import jmri.jmrit.operations.rollingstock.RollingStockSetFrame;
012import jmri.jmrit.operations.setup.Control;
013
014/**
015 * Frame for user to place engine on the layout
016 *
017 * @author Dan Boudreau Copyright (C) 2008, 2010
018 */
019public class EngineSetFrame extends RollingStockSetFrame<Engine> {
020
021    protected static final ResourceBundle rb = ResourceBundle
022            .getBundle("jmri.jmrit.operations.rollingstock.engines.JmritOperationsEnginesBundle");
023
024    EngineManager manager = InstanceManager.getDefault(EngineManager.class);
025    EngineManagerXml managerXml = InstanceManager.getDefault(EngineManagerXml.class);
026
027    Engine _engine;
028
029    public EngineSetFrame() {
030        super(Bundle.getMessage("TitleEngineSet"));
031    }
032
033    @Override
034    public void initComponents() {
035        super.initComponents();
036
037        // build menu
038        addHelpMenu("package.jmri.jmrit.operations.Operations_LocomotivesSet", true); // NOI18N
039
040        // disable location unknown, final destination fields
041        locationUnknownCheckBox.setVisible(false);
042        paneOptional.setVisible(false);
043        pFinalDestination.setVisible(false);
044        autoTrainCheckBox.setVisible(false);
045
046        // tool tips
047        outOfServiceCheckBox.setToolTipText(getRb().getString("TipLocoOutOfService"));
048
049        initMinimumSize(new Dimension(Control.panelWidth500, Control.panelHeight300));
050    }
051
052    public void load(Engine engine) {
053        _engine = engine;
054        super.load(engine);
055    }
056
057    @Override
058    protected ResourceBundle getRb() {
059        return rb;
060    }
061
062    @Override
063    protected boolean save() {
064        if (!super.save()) {
065            return false;
066        }
067        // check for train change
068        checkTrain(_engine);
069        // is this engine part of a consist?
070        if (_engine.getConsist() != null) {
071            if (JOptionPane.showConfirmDialog(this, Bundle.getMessage("engineInConsist"),
072                    Bundle.getMessage("enginePartConsist"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
073                // convert cars list to rolling stock list
074                List<Engine> list = _engine.getConsist().getEngines();
075                if (!updateGroup(list)) {
076                    return false;
077                }
078            }
079        }
080        OperationsXml.save();
081        return true;
082    }
083
084//    private final static Logger log = LoggerFactory.getLogger(EngineSetFrame.class);
085}