001package jmri.jmrix.anyma;
002
003import java.util.List;
004
005import javax.annotation.Nonnull;
006
007import jmri.jmrix.AbstractUsbConnectionConfig;
008
009/**
010 * Definition of objects to handle configuring an Anyma DMX layout connection
011 * via a AnymaDMX_UsbPortAdapter object.
012 * <p>
013 * This uses the {@link AnymaDMX_UsbPortAdapter} class to do the actual
014 * connection.
015 *
016 * @author George Warner Copyright (c) 2017-2018
017 * @since 4.9.6
018 * @see AnymaDMX_UsbPortAdapter
019 */
020public class AnymaDMX_ConnectionConfig extends AbstractUsbConnectionConfig {
021
022    /**
023     * Ctor for an object being created during load process; Swing init is
024     * deferred.
025     *
026     * @param p the pre-existing adapter
027     */
028    public AnymaDMX_ConnectionConfig(AnymaDMX_UsbPortAdapter p) {
029        super(p);
030        log.debug("*    constructor('{}').", p);
031    }
032
033    /**
034     * Ctor for a connection configuration with no preexisting adapter.
035     * {@link #setInstance()} will fill the adapter member.
036     */
037    public AnymaDMX_ConnectionConfig() {
038        this(new AnymaDMX_UsbPortAdapter());
039    }
040
041    /**
042     * {@inheritDoc}
043     */
044    @Override
045    public void updateAdapter() {
046        log.debug("*    updateAdapter()");
047        if ((adapter.getSystemConnectionMemo() != null)
048                && !adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
049            systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
050            connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
051        }
052    }
053
054    /**
055     * {@inheritDoc}
056     */
057    @Override
058    protected void setInstance() {
059        if (adapter == null) {
060            adapter = new AnymaDMX_UsbPortAdapter();
061        }
062        //if (adapter.getDMXController() == null) {
063        //    // don't show more than once every 30 seconds
064        //    if (!GraphicsEnvironment.isHeadless()
065        //            && (this.DMXMessageShown == null || ((new Date().getTime() - this.DMXMessageShown.getTime()) / 1000 % 60) > 30)) {
066        //        JmriJOptionPane.showMessageDialog(this._details,
067        //                Bundle.getMessage("NoDMXControllerMessage"),
068        //                Bundle.getMessage("NoDMXControllerTitle"),
069        //                JmriJOptionPane.ERROR_MESSAGE);
070        //        this.DMXMessageShown = new Date();
071        //    }
072        //}
073    }
074
075    @Override
076    public String name() {
077        log.debug("*    name()");
078        return getConnectionName();
079    }
080
081    @Override
082    @Nonnull
083    protected List<String> getPortNames() {
084        log.debug("*   getPortNames()");
085        return getAdapter().getPortNames();
086    }
087
088    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(AnymaDMX_ConnectionConfig.class);
089}