📄 copilotgui.java.svn-base
字号:
}
public void setSpeed( double speedTemp )
{
speed = speedTemp;
//speedLabel.setText( Double.toString( speed ) );
speedGauge.setValue( speed );
}
public double getSpeed()
{
return speed;
}
}
public class Thrust extends JPanel
{
private final int MAX = 500; //size of thruster
private final int THRUST_RATIO = 1; //how much speed the thruster imparts
private double thrust;
private JSlider thrustSlider;
public Thrust()
{
thrust = 0.0;
thrustSlider = new JSlider( JSlider.VERTICAL, 0, MAX, 0 );
thrustSlider.setMajorTickSpacing( 100 );
thrustSlider.setMinorTickSpacing( 25 );
thrustSlider.setPaintTicks( true );
thrustSlider.setPaintLabels( true );
thrustSlider.addChangeListener( new ThrustListener() );
setLayout( new GridLayout( 1, 1 ) );
add( thrustSlider );
}
public void setThrust( double thrustTemp )
{
thrust = thrustTemp;
}
public double getThrust()
{
return thrust;
}
public class ThrustListener implements ChangeListener
{
public void stateChanged( ChangeEvent ce )
{
if( fuel.getFuel() > 0 )
{
speed.setSpeed( thrustSlider.getValue() * THRUST_RATIO );
}
}
}
}
public class Altitude extends JPanel
{
private double altitude;
//private JLabel altitudeLabel;
private Gauge altitudeGauge;
public Altitude()
{
this( 0.0 );
}
public Altitude( double altitudeTemp )
{
altitude = altitudeTemp;
//altitudeLabel = new JLabel( Double.toString( altitudeTemp ) );
altitudeGauge = new Gauge( "Altitude", 50, 0, 50, Math.PI / 4, 1.5 * Math.PI, 30, 20, 0.0 );
setLayout( new GridLayout( 1, 1 ) );
add( altitudeGauge );
//add( altitudeLabel );
}
public void setAltitude( double altitudeTemp )
{
altitude = altitudeTemp;
//altitudeLabel.setText( Double.toString( altitudeTemp ) );
}
public double getAltitude()
{
return altitude;
}
}
public class Yoke extends JPanel
{
private final String IMAGE_PATH = "resources/textures/";
private double pitchDelta;
private double rollDelta;
private BufferedImage yokeImage;
private int x;
private int y;
private int width;
private int height;
public Yoke()
{
this( 0.0, 0.0 );
}
public Yoke( double pitchDeltaTemp, double rollDeltaTemp )
{
pitchDelta = pitchDeltaTemp;
rollDelta = rollDeltaTemp;
setBackground( Color.WHITE );
addMouseMotionListener( new YokeMotionListener() );
Image image = getToolkit().getImage( IMAGE_PATH + "yoke.gif" );
MediaTracker mt = new MediaTracker( this );
mt.addImage( image, 1 );
try
{
mt.waitForAll();
}
catch( Exception e )
{
System.out.println( "Exception while loading image." );
}
width = image.getWidth( this );
height = image.getHeight( this );
if( width == -1 )
{
System.out.println( "no gif file" );
System.exit( 0 );
}
yokeImage = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB );
Graphics2D big = yokeImage.createGraphics();
big.drawImage( image, 0, 0, this );
}
public void setPitchDelta( double pitchDeltaTemp )
{
pitchDelta = pitchDeltaTemp;
//this is temporary
attitudeIndicator.setPitch( pitchDelta );
}
public double getPitchDelta()
{
return pitchDelta;
}
public void setRollDelta( double rollDeltaTemp )
{
rollDelta = rollDeltaTemp;
//this is temporary
attitudeIndicator.setRoll( rollDelta );
}
public double getRollDelta()
{
return rollDelta;
}
public void paintComponent( Graphics g )
{
super.paintComponent( g );
Graphics2D g2D = (Graphics2D) g;
int[] polygonX = { x, x + width, getWidth() / 2 + width / 2, getWidth() / 2 - width / 2 };
int[] polygonY = { y + height / 2, y + height / 2, getHeight(), getHeight() };
g.fillPolygon( polygonX, polygonY, 4 );
g2D.drawImage( yokeImage, x, y, this );
}
public class YokeMotionListener extends MouseMotionAdapter
{
public void mouseDragged( MouseEvent me )
{
int mouseX = me.getX();
int mouseY = me.getY();
int panelX = yoke.getWidth();
int panelY = yoke.getHeight();
if( mouseX >= ( width / 2 ) && mouseY >= ( height / 2 ) && mouseX <= ( panelX - width / 2 ) && mouseY <= ( panelY - height / 2 ) )
{
x = mouseX - width / 2;
y = mouseY - height / 2;
setRollDelta( mouseX - panelX / 2 );
setPitchDelta( mouseY - panelY / 2 );
repaint();
}
}
//put this somewhere else
public void mouseMoved( MouseEvent me )
{
int centerX = yoke.getWidth() / 2;
int centerY = yoke.getHeight() / 2;
int imageCenterX = x + width / 2;
int imageCenterY = y + width / 2;
if( imageCenterX == centerX && imageCenterY == centerY )
{
return;
}
if( imageCenterX > centerX )
{
x--;
}
else if( imageCenterX < centerX )
{
x++;
}
if( imageCenterY > centerY )
{
y--;
}
else if( imageCenterY < centerY )
{
y++;
}
setRollDelta( imageCenterX - centerX );
setPitchDelta( imageCenterY - centerY );
repaint();
}
}
}
public class RadioWindow extends JPanel
{
private JComboBox messageOptions;
private JButton chooseMessage;
public RadioWindow()
{
setLayout( new GridLayout( 2, 1 ) );
messageOptions = new JComboBox();
chooseMessage = new JButton( "Send" );
chooseMessage.addActionListener( new MessageListener() );
add( messageOptions );
add( chooseMessage );
}
public void changeOptions( String[] options )
{
messageOptions.removeAllItems();
for( int i = 0; i < options.length; i++ )
{
messageOptions.addItem( options[i] );
}
}
public class MessageListener implements ActionListener
{
public void actionPerformed( ActionEvent ae )
{
if( messageOptions.getSelectedItem().equals( "Arrival Checklist Successful" ) )
{
messageWindow.addMessage( "Arrival Checklist Successful" );
coPilotAgent.msgArrivalChecklistSuccessful();
}
else if( messageOptions.getSelectedItem().equals( "Departure Checklist Successful" ) )
{
messageWindow.addMessage( "Departure Checklist Successful" );
coPilotAgent.msgDepartureChecklistSuccessful();
}
else if( messageOptions.getSelectedItem().equals( "CoPilot Taking Over As Pilot" ) )
{
messageWindow.addMessage( "CoPilot Taking Over As Pilot" );
coPilotAgent.coPilotTakingOverAsPilot();
}
else if( messageOptions.getSelectedItem().equals( "Arrival Checklist Unsuccessful" ) )
{
messageWindow.addMessage( "Arrival Checklist Unsuccessful" );
coPilotAgent.arrivalChecklistUnsuccessful();
}
else if( messageOptions.getSelectedItem().equals( "Arrival Checklist Successful" ) )
{
messageWindow.addMessage( "Arrival Checklist Successful" );
coPilotAgent.arrivalChecklistSuccessful();
}
else if( messageOptions.getSelectedItem().equals( "Departure Checklist Unsuccessful" ) )
{
messageWindow.addMessage( "Departure Checklist Unsuccessful" );
coPilotAgent.departureChecklistUnsuccessful();
}
else if( messageOptions.getSelectedItem().equals( "Departure Checklist Successful" ) )
{
messageWindow.addMessage( "Departure Checklist Successful" );
coPilotAgent.departureChecklistSuccessful();
}
messageOptions.removeItem( messageOptions.getSelectedItem() );
}
}
}
public class MessageWindow extends JPanel
{
private JTextArea messageWindow;
public MessageWindow()
{
messageWindow = new JTextArea();
setLayout( new GridLayout( 1, 1 ) );
JScrollPane sp = new JScrollPane( messageWindow, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
add( sp );
}
public void addMessage( String message )
{
messageWindow.append( message );
}
}
public void update( Runway runway, Gate gate, String approach, String destination, Collection<Runway> path, LocalControlHelperGUI localController, Runway lastPath, Collection<Taxiway> taxiInstructions, Strip arrival, Weather report, GroundControlHelperGUI groundController, Collection<Waypoint> procedure, Runway takeoffRunway, TRACON departureControl )
{
runwayLabel.setText( runway.toString() );
gateLabel.setText( gate.toString() );
approachLabel.setText( approach );
//path
localControllerLabel.setText( localController.toString() );
lastPathLabel.setText( lastPath.toString() );
//taxiInstructions
arrivalLabel.setText( arrival.toString() );
destinationLabel.setText( destination.toString() );
reportLabel.setText( report.toString() );
groundControllerLabel.setText( groundController.toString() );
//procedure
takeoffRunwayLabel.setText( takeoffRunway.toString() );
departureControlLabel.setText( departureControl.toString() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -