Search in sources :

Example 1 with SystemConnectionMemo

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

the class ManagerDefaultsConfigPane method reloadConnections.

void reloadConnections(List<SystemConnectionMemo> connList) {
    log.debug(" reloadConnections");
    ManagerDefaultSelector manager = InstanceManager.getDefault(ManagerDefaultSelector.class);
    matrix.setLayout(new GridLayout2(connList.size() + 1, manager.knownManagers.length + 1));
    matrix.add(new JLabel(""));
    for (ManagerDefaultSelector.Item item : manager.knownManagers) {
        matrix.add(new JLabel(item.typeName));
    }
    groups = new ButtonGroup[manager.knownManagers.length];
    for (int i = 0; i < manager.knownManagers.length; i++) {
        groups[i] = new ButtonGroup();
    }
    boolean[] selected = new boolean[manager.knownManagers.length];
    for (int x = 0; x < connList.size(); x++) {
        // up to down
        jmri.jmrix.SystemConnectionMemo memo = connList.get(x);
        String name = memo.getUserName();
        matrix.add(new JLabel(name));
        int i = 0;
        for (ManagerDefaultSelector.Item item : manager.knownManagers) {
            // left to right
            if (memo.provides(item.managerClass)) {
                JRadioButton r = new SelectionButton(name, item.managerClass, this);
                matrix.add(r);
                groups[i].add(r);
                if (!selected[i] && manager.getDefault(item.managerClass) == null) {
                    r.setSelected(true);
                    selected[i] = true;
                }
            } else {
                // leave a blank
                JRadioButton r = new JRadioButton();
                r.setEnabled(false);
                matrix.add(r);
            }
            //we need to increment 'i' as we are going onto the next group even if we added a blank button
            i++;
        }
    }
    revalidate();
}
Also used : ManagerDefaultSelector(jmri.managers.ManagerDefaultSelector) JRadioButton(javax.swing.JRadioButton) GridLayout2(jmri.util.javaworld.GridLayout2) ButtonGroup(javax.swing.ButtonGroup) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) JLabel(javax.swing.JLabel)

Example 2 with SystemConnectionMemo

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

the class ManagerDefaultsConfigPane method update.

/**
     * Invoke when first displayed to load and present options
     */
public void update() {
    matrix.removeAll();
    // this doesn't find non-migrated systems, how do we handle that eventually?
    List<SystemConnectionMemo> connList = InstanceManager.getList(SystemConnectionMemo.class);
    if (!connList.isEmpty()) {
        log.debug("update of {} connections", connList.size());
        reloadConnections(connList);
    } else {
        log.debug("update with no new-form system connections configured");
        matrix.add(new JLabel("No new-form system connections configured"));
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) JLabel(javax.swing.JLabel)

Example 3 with SystemConnectionMemo

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

the class JmriSRCPThrottleServer method initThrottle.

public void initThrottle(int bus, int address, boolean isLong, int speedsteps, int functions) throws IOException {
    log.debug("initThrottle called with bus {} and address {}", bus, address);
    /* translate the bus into a system connection memo */
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        return;
    }
    /* request the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager t = memo.get(jmri.ThrottleManager.class);
        // we will use getThrottleInfo to request information about the
        // address, so we need to convert the address to a DccLocoAddress
        // object first.
        DccLocoAddress addr = new DccLocoAddress(address, isLong);
        busList.add(Integer.valueOf(bus));
        addressList.add(addr);
        t.requestThrottle(addr, this);
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) DccLocoAddress(jmri.DccLocoAddress)

Example 4 with SystemConnectionMemo

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

the class JmriSRCPThrottleServer method setThrottleFunctions.

/*
     * Set Throttle Functions on/off
     *
     * @param bus, bus the throttle is on.
     * @param l address of the locomotive to change speed of.
     * @param fList an ArrayList of boolean values indicating whether the
     *         function is active or not.
     */
public void setThrottleFunctions(int bus, int address, ArrayList<Boolean> fList) {
    log.debug("Setting Functions for address {} bus {}", address, bus);
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        try {
            TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        } catch (IOException ioe) {
            log.error("Error writing to network port");
        }
        return;
    }
    /* request the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager tm = memo.get(jmri.ThrottleManager.class);
        // we will use getThrottleInfo to request information about the
        // address, so we need to convert the address to a DccLocoAddress
        // object first.
        DccLocoAddress addr = new DccLocoAddress(address, tm.canBeLongAddress(address));
        // get the throttle for the address.
        if (addressList.contains(addr)) {
            log.debug("Throttle in throttle list");
            Throttle t = throttleList.get(addressList.indexOf(addr));
            for (int i = 0; i < fList.size(); i++) {
                try {
                    java.lang.reflect.Method setter = t.getClass().getMethod("setF" + i, boolean.class);
                    setter.invoke(t, fList.get(i));
                } catch (java.lang.NoSuchMethodException | java.lang.IllegalAccessException | java.lang.reflect.InvocationTargetException ex1) {
                    ex1.printStackTrace();
                    try {
                        sendErrorStatus();
                    } catch (IOException ioe) {
                        log.error("Error writing to network port");
                    }
                }
            }
        }
    }
}
Also used : IOException(java.io.IOException) DccLocoAddress(jmri.DccLocoAddress) Throttle(jmri.Throttle) DccThrottle(jmri.DccThrottle) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager)

Example 5 with SystemConnectionMemo

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

the class JmriSRCPThrottleServer method setThrottleSpeedAndDirection.

/*
     * Set Throttle Speed and Direction
     *
     * @param bus, bus the throttle is on.
     * @param l address of the locomotive to change speed of.
     * @param speed float representing the speed, -1 for emergency stop.
     * @param isForward boolean, true if forward, false if reverse or
     * undefined.
     */
public void setThrottleSpeedAndDirection(int bus, int address, float speed, boolean isForward) {
    log.debug("Setting Speed for address {} bus {} to {} with direction {}", address, bus, speed, isForward ? "forward" : "reverse");
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        try {
            TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        } catch (IOException ioe) {
            log.error("Error writing to network port");
        }
        return;
    }
    /* request the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager tm = memo.get(jmri.ThrottleManager.class);
        // we will use getThrottleInfo to request information about the
        // address, so we need to convert the address to a DccLocoAddress
        // object first.
        DccLocoAddress addr = new DccLocoAddress(address, tm.canBeLongAddress(address));
        // get the throttle for the address.
        if (addressList.contains(addr)) {
            log.debug("Throttle in throttle list");
            Throttle t = throttleList.get(addressList.indexOf(addr));
            // set the speed and direction.
            t.setSpeedSetting(speed);
            t.setIsForward(isForward);
        }
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) IOException(java.io.IOException) DccLocoAddress(jmri.DccLocoAddress) Throttle(jmri.Throttle) DccThrottle(jmri.DccThrottle)

Aggregations

SystemConnectionMemo (jmri.jmrix.SystemConnectionMemo)18 DccLocoAddress (jmri.DccLocoAddress)6 ThrottleManager (jmri.ThrottleManager)6 ArrayList (java.util.ArrayList)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 JLabel (javax.swing.JLabel)2 DccThrottle (jmri.DccThrottle)2 Throttle (jmri.Throttle)2 ConnectionConfig (jmri.jmrix.ConnectionConfig)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Arrays (java.util.Arrays)1 Enumeration (java.util.Enumeration)1 Locale (java.util.Locale)1 CheckForNull (javax.annotation.CheckForNull)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Action (javax.swing.Action)1 ButtonGroup (javax.swing.ButtonGroup)1