Search in sources :

Example 1 with TimebaseRateException

use of jmri.TimebaseRateException in project JMRI by JMRI.

the class AnalogClock2Display method addRateMenuEntry.

@SuppressFBWarnings(value = "FE_FLOATING_POINT_EQUALITY", justification = "fixed number of possible values")
void addRateMenuEntry(JMenu menu, final int newrate) {
    JRadioButtonMenuItem button = new JRadioButtonMenuItem("" + newrate + ":1");
    button.addActionListener(new ActionListener() {

        final int r = newrate;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                clock.userSetRate(r);
                rate = r;
            } catch (TimebaseRateException t) {
                log.error("TimebaseRateException for rate= " + r + ". " + t);
            }
        }
    });
    rateButtonGroup.add(button);
    // next line is the FE_FLOATING_POINT_EQUALITY annotated above
    if (rate == newrate) {
        button.setSelected(true);
    } else {
        button.setSelected(false);
    }
    menu.add(button);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) TimebaseRateException(jmri.TimebaseRateException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)1 TimebaseRateException (jmri.TimebaseRateException)1