001package jmri.jmrix.roco.z21.simulator;
002
003import javax.swing.JPanel;
004
005
006/**
007 * Handle configuring an z21 layout connection via a z21Simulator
008 * adapter.
009 * <p>
010 * This uses the {@link Z21SimulatorAdapter} class to do the actual connection.
011 *
012 * @author Bob Jacobsen Copyright (C) 2001, 2003
013 * @author Paul Bender Copyright (C) 2009
014 *
015 * @see Z21SimulatorAdapter
016 */
017public class Z21SimulatorConnectionConfig extends jmri.jmrix.roco.z21.ConnectionConfig {
018
019    /**
020     * Ctor for an object being created during load process; Swing init is
021     * deferred.
022     * @param p network port adapter.
023     */
024    public Z21SimulatorConnectionConfig(jmri.jmrix.NetworkPortAdapter p) {
025        super(p);
026    }
027
028    /**
029     * Ctor for a connection configuration with no preexisting adapter.
030     * {@link #setInstance()} will fill the adapter member.
031     */
032    public Z21SimulatorConnectionConfig() {
033        super();
034    }
035
036    @Override
037    public String name() {
038        return "Z21 Simulator";
039    }
040
041    /**
042     * {@inheritDoc}
043     */
044    @Override
045    public void loadDetails(JPanel details) {
046        super.loadDetails(details);
047        hostNameField.setText("localhost");
048        hostNameField.setEnabled(false); // always localhost.
049        portField.setEnabled(false); // we don't change this on the simulator.
050        portFieldLabel.setText(Bundle.getMessage("CommunicationPortLabel"));
051        portField.setText(String.valueOf(adapter.getPort()));
052        portField.setEnabled(false); // we can't change this now.
053    }
054
055    @Override
056    public boolean isHostNameAdvanced() {
057        return true;  // hostname is always localhost.
058    }
059
060    @Override
061    public boolean isAutoConfigPossible() {
062        return false;  // always fixed, no reason to search.
063    }
064
065    /**
066     * {@inheritDoc}
067     */
068    @Override
069    protected void setInstance() {
070        if (adapter == null) {
071            adapter = new Z21SimulatorAdapter();
072        }
073    }
074
075}