001package jmri.jmris.srcp;
002
003import javax.swing.BoxLayout;
004import javax.swing.JPanel;
005import javax.swing.JToggleButton;
006
007import jmri.InstanceManager;
008import jmri.jmris.JmriServer;
009
010/**
011 * Frame displaying start/stop buttons for the JMRI SRCP server.
012 *
013 * @author Paul Bender Copyright (C) 2009
014 */
015public class JmriSRCPServerFrame extends jmri.util.JmriJFrame {
016
017
018    public JmriSRCPServerFrame() {
019        this("Jmri SRCP Server Starter");
020    }
021
022    public JmriSRCPServerFrame(String FrameName) {
023        super(FrameName);
024        getContentPane().setLayout(new BoxLayout(getContentPane(),
025                BoxLayout.Y_AXIS));
026
027        JPanel pane0 = new JPanel();
028        pane0.add(startButton);
029        pane0.add(stopButton);
030        pane0.add(closeButton);
031        getContentPane().add(pane0);
032
033        // and prep for display
034        pack();
035
036        // install start button handler
037        startButton.addActionListener(a -> startSRCPServer());
038
039        // install stop button handler
040        stopButton.addActionListener(a -> stopSRCPServer());
041
042        // install close button handler
043        closeButton.addActionListener(a -> {
044            setVisible(false);
045            dispose();
046        });
047
048    }
049
050    JToggleButton startButton = new JToggleButton("Start SRCP Server");
051    JToggleButton stopButton = new JToggleButton("Stop SRCP Server");
052    JToggleButton closeButton = new JToggleButton("Close SRCP Server");
053
054    // Close the window when the close box is clicked
055    void thisWindowClosing(java.awt.event.WindowEvent e) {
056        setVisible(false);
057        dispose();
058    }
059
060    @Override
061    public void dispose() {
062        // take apart the JFrame
063        super.dispose();
064    }
065
066    public void startSRCPServer() {
067        InstanceManager.getDefault(JmriServer.class).start();
068    }
069
070    public void stopSRCPServer() {
071        InstanceManager.getDefault(JmriServer.class).stop();
072    }
073
074}