📄 copilotgui.java.svn-base
字号:
package gui;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.util.Collection;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import world.*;
//import agents.GroundControllerAgent;
//import agents.LocalControllerAgent;
public class CoPilotGUI extends JPanel
{
private JLabel runwayTitle;
private JLabel runwayLabel;
private JLabel gateTitle;
private JLabel gateLabel;
private JLabel approachTitle;
private JLabel approachLabel;
private JLabel destinationTitle;
private JLabel destinationLabel;
private JLabel pathTitle;
private JLabel pathLabel;
private JLabel localControllerTitle;
private JLabel localControllerLabel;
private JLabel lastPathTitle;
private JLabel lastPathLabel;
private JLabel taxiInstructionsTitle;
private JLabel taxiInstructionsLabel;
private JLabel arrivalTitle;
private JLabel arrivalLabel;
private JLabel reportTitle;
private JLabel reportLabel;
private JLabel groundControllerTitle;
private JLabel groundControllerLabel;
private JLabel procedureTitle;
private JLabel procedureLabel;
private JLabel takeoffRunwayTitle;
private JLabel takeoffRunwayLabel;
private JLabel departureControlTitle;
private JLabel departureControlLabel;
private JPanel viewInfo;
private JPanel viewControls;
private RadioWindow radioWindow;
private Fuel fuel;
private Speed speed;
private Thrust thrust;
private Altitude altitude;
private Yoke yoke;
private MessageWindow messageWindow;
private AttitudeIndicator attitudeIndicator;
private CoPilotHelperGUI coPilotAgent;
private boolean enabled;
public CoPilotGUI()
{
coPilotAgent = null;
enabled = false;
viewInfo = new JPanel();
viewControls = new JPanel();
radioWindow = new RadioWindow();
fuel = new Fuel();
speed = new Speed();
thrust = new Thrust();
altitude = new Altitude();
attitudeIndicator = new AttitudeIndicator();
yoke = new Yoke();
messageWindow = new MessageWindow();
runwayTitle = new JLabel( "Runway" );
runwayLabel = new JLabel( "" );
gateTitle = new JLabel( "Gate" );
gateLabel = new JLabel( "" );
approachTitle = new JLabel( "Approach" );
approachLabel = new JLabel( "" );
destinationTitle = new JLabel( "Destination" );
destinationLabel = new JLabel( "" );
pathTitle = new JLabel( "Path" );
pathLabel = new JLabel( "" );
localControllerTitle = new JLabel( "Local Controller" );
localControllerLabel = new JLabel( "" );
lastPathTitle = new JLabel( "Last Path" );
lastPathLabel = new JLabel( "" );
taxiInstructionsTitle = new JLabel( "Taxi Instructions" );
taxiInstructionsLabel = new JLabel( "" );
arrivalTitle = new JLabel( "Arrival" );
arrivalLabel = new JLabel( "" );
reportTitle = new JLabel( "Report" );
reportLabel = new JLabel( "" );
groundControllerTitle = new JLabel( "Ground Controller" );
groundControllerLabel = new JLabel( "" );
procedureTitle = new JLabel( "Procedure" );
procedureLabel = new JLabel( "" );
takeoffRunwayTitle = new JLabel( "Takeoff Runway" );
takeoffRunwayLabel = new JLabel( "" );
departureControlTitle = new JLabel( "DepartureControl" );
departureControlLabel = new JLabel( "" );
viewControls.setLayout( new GridLayout( 2, 5 ) );
viewControls.add( fuel );
viewControls.add( speed );
viewControls.add( altitude );
viewControls.add( attitudeIndicator );
viewControls.add( radioWindow );
viewControls.add( new JPanel() );
viewControls.add( thrust );
viewControls.add( new JPanel() );
viewControls.add( yoke );
viewControls.add( messageWindow );
viewInfo.setLayout( new GridLayout( 4, 7 ) );
viewInfo.add( runwayTitle );
viewInfo.add( gateTitle );
viewInfo.add( approachTitle );
viewInfo.add( destinationTitle );
viewInfo.add( pathTitle );
viewInfo.add( localControllerTitle );
viewInfo.add( lastPathTitle );
viewInfo.add( runwayLabel );
viewInfo.add( gateLabel );
viewInfo.add( approachLabel );
viewInfo.add( destinationLabel );
viewInfo.add( pathLabel );
viewInfo.add( localControllerLabel );
viewInfo.add( lastPathLabel );
viewInfo.add( taxiInstructionsTitle );
viewInfo.add( arrivalTitle );
viewInfo.add( reportTitle );
viewInfo.add( groundControllerTitle );
viewInfo.add( procedureTitle );
viewInfo.add( takeoffRunwayTitle );
viewInfo.add( departureControlTitle );
viewInfo.add( taxiInstructionsLabel );
viewInfo.add( arrivalLabel );
viewInfo.add( reportLabel );
viewInfo.add( groundControllerLabel );
viewInfo.add( procedureLabel );
viewInfo.add( takeoffRunwayLabel );
viewInfo.add( departureControlLabel );
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout( gbl );
//setLayout( new GridLayout( 2, 1 ) );
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
gbl.setConstraints( viewInfo, c );
add( viewInfo );
gbl.setConstraints( viewControls, c );
add( viewControls );
}
public void setCoPilotAgent( CoPilotHelperGUI coPilotAgent )
{
this.coPilotAgent = coPilotAgent;
}
public void setEnabled( boolean enabledTemp )
{
enabled = enabledTemp;
}
public Fuel getFuel()
{
return fuel;
}
public Speed getSpeed()
{
return speed;
}
public Altitude getAltitude()
{
return altitude;
}
public AttitudeIndicator getAttitudeIndicator()
{
return attitudeIndicator;
}
public Thrust getThrust()
{
return thrust;
}
public Yoke getYoke()
{
return yoke;
}
public RadioWindow getRadioWindow()
{
return radioWindow;
}
public MessageWindow getMessageWindow()
{
return messageWindow;
}
public class AttitudeIndicator extends JPanel
{
private final int X_OFFSET = 30;
private final int Y_OFFSET = 20;
private final int X_CENTER = 50;
private final int Y_CENTER = 50;
private final int RADIUS = 50;
private final int SMALL_RADIUS = 4;
private final int HALF_LINE_LENGTH = 50;
private double pitch;
private double roll;
public AttitudeIndicator()
{
this( 0.0, 0.0 );
}
public AttitudeIndicator( double pitchTemp, double rollTemp )
{
pitch = pitchTemp;
roll = rollTemp;
setBackground( Color.BLACK );
}
protected void paintComponent( Graphics g )
{
super.paintComponent( g );
g.setColor( Color.WHITE );
g.fillOval( X_OFFSET, Y_OFFSET, 2 * RADIUS, 2 * RADIUS );
g.setColor( Color.BLACK );
g.drawOval( X_OFFSET + RADIUS - SMALL_RADIUS, Y_OFFSET + RADIUS - SMALL_RADIUS, 2 * SMALL_RADIUS, 2 * SMALL_RADIUS );
g.drawLine( X_OFFSET, Y_OFFSET + RADIUS, X_OFFSET + 2 * RADIUS, Y_OFFSET + RADIUS );
g.drawLine( X_OFFSET + RADIUS, Y_OFFSET + RADIUS, X_OFFSET + RADIUS, Y_OFFSET + 2 * RADIUS );
double rollRadians = roll * Math.PI / 180.0;
int pitchX = (int) ( pitch * Math.sin( rollRadians ) );
int pitchY = (int) ( pitch * Math.cos( rollRadians ) );
int xPositionRight = X_CENTER + pitchX + (int) ( (double) HALF_LINE_LENGTH * Math.cos( rollRadians ) );
int xPositionLeft = -xPositionRight + ( 2 * ( X_CENTER + pitchX ) );
int yPositionRight = Y_CENTER + pitchY + (int) ( (double) HALF_LINE_LENGTH * -Math.sin( rollRadians ) );
int yPositionLeft = -yPositionRight + ( 2 * ( Y_CENTER + pitchY ) );
g.drawLine( X_OFFSET + xPositionRight, Y_OFFSET + yPositionRight, X_OFFSET + xPositionLeft, Y_OFFSET + yPositionLeft );
}
public void setPitch( double pitchTemp )
{
pitch = pitchTemp;
repaint();
}
public double getPitch()
{
return pitch;
}
public void setRoll( double rollTemp )
{
roll = rollTemp;
repaint();
}
public double getRoll()
{
return roll;
}
}
public class Fuel extends JPanel
{
private double fuel;
private JLabel fuelLabel;
public Fuel()
{
this( 100.0 );
//this( 0.0 );
}
public Fuel( double fuelTemp )
{
fuel = fuelTemp;
fuelLabel = new JLabel( Double.toString( fuel ) );
add( fuelLabel );
}
public void setFuel( double fuelTemp )
{
fuel = fuelTemp;
fuelLabel.setText( Double.toString( fuel ) );
}
public double getFuel()
{
return fuel;
}
}
public class Speed extends JPanel
{
private double speed;
Gauge speedGauge;
public Speed()
{
this( 0.0 );
}
public Speed( double speedTemp )
{
speed = speedTemp;
speedGauge = new Gauge( "Speed", 50, 0, 500, Math.PI / 4, 1.5 * Math.PI, 30, 20, 0.0 );
setLayout( new GridLayout( 1, 1 ) );
add( speedGauge );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -