Search in sources :

Example 1 with Throttle

use of jmri.Throttle 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 2 with Throttle

use of jmri.Throttle 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)

Example 3 with Throttle

use of jmri.Throttle in project JMRI by JMRI.

the class ThrottlesTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable jtable, Object value, boolean bln, boolean bln1, int i, int i1) {
    JPanel retPanel = new JPanel();
    retPanel.setLayout(new BorderLayout());
    if (value == null) {
        return retPanel;
    }
    ThrottleFrame tf = (ThrottleFrame) value;
    ImageIcon icon = null;
    String text = null;
    if (tf.getRosterEntry() != null) {
        icon = iconFactory.getIcon(tf.getAddressPanel().getRosterEntry());
        text = tf.getAddressPanel().getRosterEntry().getId();
    } else if ((tf.getAddressPanel().getCurrentAddress() != null) && (tf.getAddressPanel().getThrottle() != null)) {
        if (tf.getAddressPanel().getCurrentAddress().getNumber() == 0) {
            text = Bundle.getMessage("ThrottleDCControl") + " - " + tf.getAddressPanel().getCurrentAddress();
        } else if (tf.getAddressPanel().getCurrentAddress().getNumber() == 3) {
            text = Bundle.getMessage("ThrottleDCCControl") + " - " + tf.getAddressPanel().getCurrentAddress();
        } else {
            text = Bundle.getMessage("ThrottleAddress") + " " + tf.getAddressPanel().getCurrentAddress();
        }
    } else {
        text = Bundle.getMessage("ThrottleNotAssigned");
    }
    if (icon != null) {
        icon.setImageObserver(jtable);
    }
    JLabel locoID = new JLabel();
    locoID.setHorizontalAlignment(JLabel.CENTER);
    locoID.setVerticalAlignment(JLabel.CENTER);
    locoID.setIcon(icon);
    locoID.setText(text);
    retPanel.add(locoID, BorderLayout.CENTER);
    if (tf.getAddressPanel().getThrottle() != null) {
        JPanel ctrlPanel = new JPanel();
        ctrlPanel.setLayout(new BorderLayout());
        Throttle thr = tf.getAddressPanel().getThrottle();
        JLabel dir = new JLabel();
        if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
            if (thr.getIsForward()) {
                dir.setIcon(fwdIcon);
            } else {
                dir.setIcon(bckIcon);
            }
        } else {
            if (thr.getIsForward()) {
                dir.setText(Bundle.getMessage("ButtonForward"));
            } else {
                dir.setText(Bundle.getMessage("ButtonReverse"));
            }
        }
        dir.setVerticalAlignment(JLabel.CENTER);
        ctrlPanel.add(dir, BorderLayout.WEST);
        if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
            if (thr.getSpeedSetting() == -1) {
                JLabel estop = new JLabel();
                estop.setPreferredSize(new Dimension(64, height - 8));
                estop.setHorizontalAlignment(JLabel.CENTER);
                estop.setIcon(estopIcon);
                ctrlPanel.add(estop, BorderLayout.CENTER);
            } else {
                JProgressBar speedBar = new javax.swing.JProgressBar();
                speedBar.setPreferredSize(new Dimension(64, height - 8));
                speedBar.setMinimum(0);
                speedBar.setMaximum(100);
                speedBar.setValue((int) (thr.getSpeedSetting() * 100f));
                ctrlPanel.add(speedBar, BorderLayout.CENTER);
            }
        } else {
            JLabel speedLabel = new JLabel("");
            if (thr.getSpeedSetting() == -1) {
                speedLabel.setText(" " + Bundle.getMessage("ButtonEStop") + " ");
            } else {
                speedLabel.setText(" " + (int) (thr.getSpeedSetting() * 100f) + "% ");
            }
            ctrlPanel.add(speedLabel, BorderLayout.CENTER);
        }
        retPanel.add(ctrlPanel, BorderLayout.EAST);
    }
    retPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    return retPanel;
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) BorderLayout(java.awt.BorderLayout) JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Throttle(jmri.Throttle)

Example 4 with Throttle

use of jmri.Throttle in project JMRI by JMRI.

the class StoppingBlock method setSpeed.

void setSpeed(float speed, boolean f1, boolean f2, boolean f3) {
    Object o = block.getValue();
    if (o == null) {
        log.error("Block " + block.getSystemName() + " contained no Throttle object");
        return;
    }
    try {
        Throttle t = (Throttle) block.getValue();
        t.setSpeedSetting(speed);
        t.setF1(f1);
        t.setF2(f2);
    } catch (ClassCastException e) {
        log.error("Block " + block.getSystemName() + " did not contain object of Throttle type: " + e);
    }
}
Also used : Throttle(jmri.Throttle)

Aggregations

Throttle (jmri.Throttle)4 IOException (java.io.IOException)2 DccLocoAddress (jmri.DccLocoAddress)2 DccThrottle (jmri.DccThrottle)2 ThrottleManager (jmri.ThrottleManager)2 SystemConnectionMemo (jmri.jmrix.SystemConnectionMemo)2 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ImageIcon (javax.swing.ImageIcon)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JProgressBar (javax.swing.JProgressBar)1