001package jmri.jmrit.throttle;
002
003import java.awt.event.ActionEvent;
004import java.util.Iterator;
005import javax.swing.JButton;
006import jmri.DccThrottle;
007import jmri.InstanceManager;
008import jmri.jmrit.catalog.NamedIcon;
009
010public class StopAllButton extends JButton {
011
012    public StopAllButton() {
013        super();
014        initGUI();
015    }
016        
017    private void initGUI() {    
018        //    stop.setText(Bundle.getMessage("ThrottleToolBarStopAll"));
019        setIcon(new NamedIcon("resources/icons/throttles/estop.png", "resources/icons/throttles/estop.png"));
020        setToolTipText(Bundle.getMessage("ThrottleToolBarStopAllToolTip"));
021        setVerticalTextPosition(JButton.BOTTOM);
022        setHorizontalTextPosition(JButton.CENTER);
023        addActionListener((ActionEvent e) -> {
024            Iterator<ThrottleFrame> tpi = InstanceManager.getDefault(ThrottleFrameManager.class).getThrottlesListPanel().getTableModel().iterator();
025            while (tpi.hasNext()) {
026                DccThrottle th = tpi.next().getAddressPanel().getThrottle();
027                if (th != null) {
028                    th.setSpeedSetting(-1);
029                }
030            }
031        });
032    }
033}