001package jmri.jmrix.cmri.serial.sim;
002
003import javax.swing.BoxLayout;
004import javax.swing.JButton;
005import javax.swing.JPanel;
006import jmri.jmrix.cmri.CMRISystemConnectionMemo;
007import jmri.jmrix.cmri.serial.nodeconfigmanager.NodeConfigManagerAction;
008
009/**
010 * Definition of objects to handle configuring a layout connection via a C/MRI
011 * Simulator object.
012 *
013 * @author Bob Jacobsen Copyright (C) 2001, 2003, 2008
014 * @author Chuck Catania Copyright (C) 2017
015 */
016public class ConnectionConfig extends jmri.jmrix.AbstractSimulatorConnectionConfig {
017
018    /**
019     * Ctor for an object being created during load process; Swing init is
020     * deferred.
021     * @param p serial port adapter.
022     */
023    public ConnectionConfig(jmri.jmrix.SerialPortAdapter p) {
024        super(p);
025    }
026
027    /**
028     * Ctor for a connection configuration with no preexisting adapter.
029     * {@link #setInstance()} will fill the adapter member.
030     */
031    public ConnectionConfig() {
032        super();
033    }
034
035    /**
036     * {@inheritDoc}
037     */
038    @Override
039    public void loadDetails(JPanel details) {
040
041        setInstance();
042
043        // have to embed the usual one in a new JPanel
044
045        JPanel p = new JPanel();
046        super.loadDetails(p);
047
048        details.setLayout(new BoxLayout(details, BoxLayout.Y_AXIS));
049        details.add(p);
050
051        // add another button
052        JButton b = new JButton(Bundle.getMessage("ConfigureNodesTitle"));
053
054        details.add(b);
055
056        b.addActionListener(new NodeConfigManagerAction((CMRISystemConnectionMemo)adapter.getSystemConnectionMemo()));
057    }
058
059    @Override
060    public String name() {
061        return "C/MRI Simulator";
062    }
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    protected void setInstance() {
069        if(adapter == null ) {
070           adapter = new SimDriverAdapter();
071           adapter.configure(); // make sure the traffic controller 
072                                // loads so that node details can be 
073                                // saved.
074        }
075    }
076
077}