001package jmri.jmris; 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 server. 011 * 012 * @author Paul Bender Copyright (C) 2010 013 */ 014public class JmriServerFrame extends jmri.util.JmriJFrame { 015 016 public JmriServerFrame() { 017 this("Jmri Server Starter"); 018 } 019 020 public JmriServerFrame(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 -> startServer()); 036 037 // install stop button handler 038 stopButton.addActionListener(a -> stopServer()); 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 Server"); 049 JToggleButton stopButton = new JToggleButton("Stop Server"); 050 JToggleButton closeButton = new JToggleButton("Close Server"); 051 052 // Close the window when the close box is clicked 053 void thisWindowClosing(java.awt.event.WindowEvent e) { 054 setVisible(false); 055 dispose(); 056 } 057 058 @Override 059 public void dispose() { 060 // take apart the JFrame 061 super.dispose(); 062 } 063 064 public void startServer() { 065 InstanceManager.getDefault(JmriServer.class).start(); 066 } 067 068 public void stopServer() { 069 InstanceManager.getDefault(JmriServer.class).stop(); 070 } 071 072}