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