001package jmri.jmris.simpleserver;
002
003import jmri.InstanceManager;
004
005import javax.swing.BoxLayout;
006import javax.swing.JPanel;
007import javax.swing.JToggleButton;
008
009/**
010 * Frame displaying start/stop buttons for the JMRI Simple Server.
011 *
012 * @author Paul Bender Copyright (C) 2009
013 */
014public class SimpleServerFrame extends jmri.util.JmriJFrame {
015
016    public SimpleServerFrame() {
017        this("Jmri Simple Server Starter");
018    }
019
020    public SimpleServerFrame(String FrameName) {
021        super(FrameName);
022        getContentPane().setLayout(new BoxLayout(getContentPane(),
023                BoxLayout.Y_AXIS));
024
025        JPanel pane0 = new JPanel();
026        pane0.add(startButton);
027        pane0.add(stopButton);
028        pane0.add(closeButton);
029        getContentPane().add(pane0);
030
031        // and prep for display
032        pack();
033
034        // install start button handler
035        startButton.addActionListener(a -> startSimpleServer());
036
037        // install stop button handler
038        stopButton.addActionListener(a -> stopSimpleServer());
039
040        // install close button handler
041        closeButton.addActionListener(a -> {
042            setVisible(false);
043            dispose();
044        });
045
046    }
047
048    JToggleButton startButton = new JToggleButton("Start Simple Server");
049    JToggleButton stopButton = new JToggleButton("Stop Simple Server");
050    JToggleButton closeButton = new JToggleButton("Close Simple Server");
051
052    public void startSimpleServer() {
053        InstanceManager.getDefault(SimpleServer.class).start();
054    }
055
056    public void stopSimpleServer() {
057        InstanceManager.getDefault(SimpleServer.class).stop();
058    }
059
060}