RasPi/GroundStation/v2/GroundStation.java

117 lines
3.8 KiB
Java
Raw Normal View History

2015-02-26 14:09:39 -07:00
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
*/
class GroundStation implements ActionListener {
/** main window to hold everything */
private JFrame mainWindow;
/** window to hold emergency stop button */
2015-03-02 14:45:13 -07:00
private EStopWindow eStopWindow = new EStopWindow( false );
2015-02-26 14:09:39 -07:00
/** connection options section of window */
private ConnectionPanel connectPanel;
2015-03-08 23:02:45 -06:00
/** flight controller arm/disarm button*/
private ArmButton arm;
2015-02-26 14:09:39 -07:00
/** tabbed pane to hold stuff */
private JTabbedPane tabbedPane;
/** motor testing panel */
private MotorTestPanel motorTestPanel;
/** displays visual representation of control positions */
private DisplayController controllerPanel;
2015-02-26 14:09:39 -07:00
/** outgoing message content options */
public MessageContent sendContent = new MessageContent();
/** incoming message content */
public MessageContent receiveContent = new MessageContent();
public GroundStation() {
mainWindow = new JFrame( "PiCopter Ground Station" );
mainWindow.setResizable( false );
2015-02-26 14:09:39 -07:00
mainWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
mainWindow.getContentPane().setLayout( new BoxLayout( mainWindow.getContentPane(), BoxLayout.PAGE_AXIS ) );
connectPanel = new ConnectionPanel( sendContent, receiveContent );
connectPanel.setEnabled( true );
mainWindow.getContentPane().add( connectPanel );
2015-03-08 23:02:45 -06:00
arm = new ArmButton( sendContent );
arm.setEnabled( false );
mainWindow.getContentPane().add( arm );
2015-03-08 22:02:53 -06:00
2015-02-26 14:09:39 -07:00
tabbedPane = new JTabbedPane();
mainWindow.getContentPane().add( tabbedPane );
controllerPanel = new DisplayController( receiveContent );
tabbedPane.add( controllerPanel, "Controller" );
connectPanel.addActionListener( controllerPanel );
2015-02-26 14:09:39 -07:00
motorTestPanel = new MotorTestPanel( sendContent );
motorTestPanel.setEnabled( false );
tabbedPane.add( motorTestPanel, "Motor Test" );
connectPanel.addActionListener( this );
sendContent.addActionListener( this );
mainWindow.pack();
mainWindow.setVisible( true );
}
public void disableMotors() {
connectPanel.setEnabled( true );
2015-03-08 23:02:45 -06:00
arm.setEnabled( true );
motorTestPanel.setEnabled( true );
2015-02-26 14:09:39 -07:00
eStopWindow.dispose();
}
public void enableMotors() {
connectPanel.setEnabled( false );
2015-03-08 23:02:45 -06:00
if( motorTestPanel.getTestStatus() ) {
arm.setEnabled( false );
}
else {
motorTestPanel.setEnabled( false );
}
2015-02-26 14:09:39 -07:00
eStopWindow = new EStopWindow();
eStopWindow.addActionListener( this );
}
public void actionPerformed( ActionEvent evt ) {
if( evt.getSource() == eStopWindow ) {
sendContent.setMotorsEnabled( false );
2015-03-08 23:02:45 -06:00
arm.setText( "Arm Flight Controller" );
2015-02-26 14:09:39 -07:00
}
if( evt.getSource() == connectPanel ) {
if( evt.getActionCommand().equals( "CONNECT" ) ) {
mainWindow.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
motorTestPanel.setEnabled( true );
2015-03-08 23:02:45 -06:00
arm.setEnabled( true );
2015-02-26 14:09:39 -07:00
}
else if( evt.getActionCommand().equals( "DISCONNECT" ) ) {
mainWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
motorTestPanel.setEnabled( false );
2015-03-08 23:02:45 -06:00
arm.setEnabled( false );
2015-02-26 14:09:39 -07:00
}
}
else if( evt.getActionCommand().equals( "ENABLE_MOTORS" ) ) {
enableMotors();
}
else if( evt.getActionCommand().equals( "DISABLE_MOTORS" ) ) {
disableMotors();
}
}
public static void main( String[] args ) {
GroundStation station = new GroundStation();
}
}