Search in sources :

Example 6 with ConnectionConfig

use of jmri.jmrix.ConnectionConfig in project JMRI by JMRI.

the class AboutDialog method infoPane.

protected JPanel infoPane() {
    JPanel pane1 = new JPanel();
    pane1.setLayout(new BoxLayout(pane1, BoxLayout.Y_AXIS));
    log.debug("start labels");
    // add listener for Com port updates
    for (ConnectionConfig conn : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!conn.getDisabled()) {
            pane1.add(new ConnectionLabel(conn));
        }
    }
    pane1.add(Box.createRigidArea(new Dimension(0, 15)));
    pane1.add(new JLabel(Bundle.getMessage("DefaultVersionCredit", Version.name())));
    pane1.add(new JLabel(Version.getCopyright()));
    pane1.add(new JLabel(Bundle.getMessage("JavaVersionCredit", System.getProperty("java.version", "<unknown>"), Locale.getDefault().toString())));
    pane1.setAlignmentX(Component.CENTER_ALIGNMENT);
    return pane1;
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Example 7 with ConnectionConfig

use of jmri.jmrix.ConnectionConfig in project JMRI by JMRI.

the class JsonUtilHttpService method getSystemConnections.

/**
     *
     * @param locale the client's Locale.
     * @return the JSON systemConnections message.
     */
public ArrayNode getSystemConnections(Locale locale) {
    ArrayNode root = mapper.createArrayNode();
    ArrayList<String> prefixes = new ArrayList<>();
    for (ConnectionConfig config : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!config.getDisabled()) {
            ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
            ObjectNode data = connection.putObject(JSON.DATA);
            data.put(JSON.NAME, config.getConnectionName());
            data.put(JSON.MFG, config.getManufacturer());
            data.put(JSON.PREFIX, config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            data.put(JSON.DESCRIPTION, Bundle.getMessage(locale, "ConnectionSucceeded", config.getConnectionName(), config.name(), config.getInfo()));
            prefixes.add(config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            root.add(connection);
        }
    }
    InstanceManager.getList(SystemConnectionMemo.class).stream().map((instance) -> instance).filter((memo) -> (!memo.getDisabled() && !prefixes.contains(memo.getSystemPrefix()))).forEach((memo) -> {
        ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(JSON.DATA);
        data.put(JSON.NAME, memo.getUserName());
        data.put(JSON.PREFIX, memo.getSystemPrefix());
        data.putNull(JSON.MFG);
        data.putNull(JSON.DESCRIPTION);
        prefixes.add(memo.getSystemPrefix());
        root.add(connection);
    });
    // Following is required because despite there being a SystemConnectionMemo
    // for the default internal connection, it is not used for the default internal
    // connection. This allows a client to map the server's internal objects.
    String prefix = "I";
    if (!prefixes.contains(prefix)) {
        ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(JSON.DATA);
        data.put(JSON.NAME, ConnectionNameFromSystemName.getConnectionName(prefix));
        data.put(JSON.PREFIX, prefix);
        data.putNull(JSON.MFG);
        data.putNull(JSON.DESCRIPTION);
        root.add(connection);
    }
    return root;
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) ConnectionConfig(jmri.jmrix.ConnectionConfig) URL(jmri.server.json.JSON.URL) ProfileManager(jmri.profile.ProfileManager) DccLocoAddress(jmri.DccLocoAddress) JmriJFrame(jmri.util.JmriJFrame) PANEL(jmri.server.json.JSON.PANEL) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Editor(jmri.jmrit.display.Editor) JsonException(jmri.server.json.JsonException) SWITCHBOARD_PANEL(jmri.server.json.JSON.SWITCHBOARD_PANEL) ArrayList(java.util.ArrayList) TYPE(jmri.server.json.JSON.TYPE) JsonServerPreferences(jmri.jmris.json.JsonServerPreferences) ConnectionConfigManager(jmri.jmrix.ConnectionConfigManager) Locale(java.util.Locale) Profile(jmri.profile.Profile) SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) JsonNode(com.fasterxml.jackson.databind.JsonNode) NAME(jmri.server.json.JSON.NAME) InstanceManager(jmri.InstanceManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonHttpService(jmri.server.json.JsonHttpService) Metadata(jmri.Metadata) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) WebServerPreferences(jmri.web.server.WebServerPreferences) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) CONTROL_PANEL(jmri.server.json.JSON.CONTROL_PANEL) ConnectionNameFromSystemName(jmri.util.ConnectionNameFromSystemName) DATA(jmri.server.json.JSON.DATA) USERNAME(jmri.server.json.JSON.USERNAME) JSON(jmri.server.json.JSON) NodeIdentity(jmri.util.node.NodeIdentity) ZeroConfService(jmri.util.zeroconf.ZeroConfService) LAYOUT_PANEL(jmri.server.json.JSON.LAYOUT_PANEL) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Example 8 with ConnectionConfig

use of jmri.jmrix.ConnectionConfig in project JMRI by JMRI.

the class JsonUtil method getSystemConnections.

/**
     *
     * @param locale the client's Locale.
     * @return the JSON networkServices message.
     * @deprecated since 4.5.2; use
     * {@link jmri.server.json.util.JsonUtilHttpService#getSystemConnections(java.util.Locale)}.
     */
@Deprecated
public static JsonNode getSystemConnections(Locale locale) {
    ArrayNode root = mapper.createArrayNode();
    ArrayList<String> prefixes = new ArrayList<String>();
    for (ConnectionConfig config : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!config.getDisabled()) {
            ObjectNode connection = mapper.createObjectNode().put(TYPE, SYSTEM_CONNECTION);
            ObjectNode data = connection.putObject(DATA);
            data.put(NAME, config.getConnectionName());
            data.put(MFG, config.getManufacturer());
            data.put(PREFIX, config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            prefixes.add(config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            root.add(connection);
        }
    }
    for (Object instance : InstanceManager.getList(SystemConnectionMemo.class)) {
        SystemConnectionMemo memo = (SystemConnectionMemo) instance;
        if (!memo.getDisabled() && !prefixes.contains(memo.getSystemPrefix())) {
            ObjectNode connection = mapper.createObjectNode().put(TYPE, SYSTEM_CONNECTION);
            ObjectNode data = connection.putObject(DATA);
            data.put(NAME, memo.getUserName());
            data.put(PREFIX, memo.getSystemPrefix());
            data.putNull(MFG);
            prefixes.add(memo.getSystemPrefix());
            root.add(connection);
        }
    }
    // Following is required because despite there being a SystemConnectionMemo
    // for the default internal connection, it is not used for the default internal
    // connection. This allows a client to map the server's internal objects.
    String prefix = "I";
    if (!prefixes.contains(prefix)) {
        ObjectNode connection = mapper.createObjectNode().put(TYPE, SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(DATA);
        data.put(NAME, ConnectionNameFromSystemName.getConnectionName(prefix));
        data.put(PREFIX, prefix);
        data.putNull(MFG);
        root.add(connection);
    }
    return root;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TrainCommon.splitString(jmri.jmrit.operations.trains.TrainCommon.splitString) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Example 9 with ConnectionConfig

use of jmri.jmrix.ConnectionConfig in project JMRI by JMRI.

the class JmrixConfigPaneXml method store.

/**
     * Forward to the configurexml class for the specific object type.
     */
@Override
public Element store(Object o) {
    ConnectionConfig oprime = ((JmrixConfigPane) o).getCurrentObject();
    if (oprime == null) {
        return null;
    }
    String adapter = ConfigXmlManager.adapterName(oprime);
    log.debug("forward to " + adapter);
    try {
        XmlAdapter x = (XmlAdapter) Class.forName(adapter).newInstance();
        return x.store(oprime);
    } catch (Exception e) {
        log.error("Exception: " + e);
        e.printStackTrace();
        return null;
    }
}
Also used : JmrixConfigPane(jmri.jmrix.JmrixConfigPane) ConnectionConfig(jmri.jmrix.ConnectionConfig) AbstractXmlAdapter(jmri.configurexml.AbstractXmlAdapter) XmlAdapter(jmri.configurexml.XmlAdapter) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException)

Example 10 with ConnectionConfig

use of jmri.jmrix.ConnectionConfig in project JMRI by JMRI.

the class AboutServlet method processRequest.

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //retrieve the list of JMRI connections as a string
    String connList = "";
    String comma = "";
    for (ConnectionConfig conn : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!conn.getDisabled()) {
            connList += comma + Bundle.getMessage(request.getLocale(), "ConnectionSucceeded", conn.getConnectionName(), conn.name(), conn.getInfo());
            comma = ", ";
        }
    }
    //print the html, using the replacement values listed to fill in the calculated stuff
    // NOI18N
    response.setHeader("Connection", "Keep-Alive");
    response.setContentType(UTF8_TEXT_HTML);
    response.getWriter().print(String.format(request.getLocale(), FileUtil.readURL(FileUtil.findURL(Bundle.getMessage(request.getLocale(), "About.html"))), //page title is parm 1
    Bundle.getMessage(request.getLocale(), "AboutTitle"), //navbar is parm 2
    ServletUtil.getInstance().getNavBar(request.getLocale(), "/about"), //railroad name is parm 3
    ServletUtil.getInstance().getRailroadName(false), //footer is parm 4
    ServletUtil.getInstance().getFooter(request.getLocale(), "/about"), //system connection list is parm 5
    connList, //JMRI version is parm 6                                         //JMRI version is parm 6
    Application.getApplicationName() + " " + jmri.Version.name(), //Copyright is parm 7
    jmri.Version.getCopyright(), //Java version is parm 8
    System.getProperty("java.version", "<unknown>"), //locale is parm 9
    Locale.getDefault().toString(), //active profile name is 10
    ProfileManager.getDefault().getActiveProfile().getName()));
}
Also used : ConnectionConfig(jmri.jmrix.ConnectionConfig)

Aggregations

ConnectionConfig (jmri.jmrix.ConnectionConfig)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Dimension (java.awt.Dimension)3 ArrayList (java.util.ArrayList)3 BoxLayout (javax.swing.BoxLayout)3 JLabel (javax.swing.JLabel)3 JPanel (javax.swing.JPanel)3 ConnectionConfigManager (jmri.jmrix.ConnectionConfigManager)3 Profile (jmri.profile.Profile)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImageIcon (javax.swing.ImageIcon)2 SystemConnectionMemo (jmri.jmrix.SystemConnectionMemo)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Color (java.awt.Color)1 File (java.io.File)1 Arrays (java.util.Arrays)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 List (java.util.List)1