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