RasPi/GroundStation/v2/DisplayController.java

82 lines
2.7 KiB
Java
Raw Normal View History

2015-03-02 14:45:13 -07:00
import javax.swing.*;
import java.awt.*;
2015-03-02 14:45:13 -07:00
import java.awt.event.*;
class DisplayController extends JPanel implements ActionListener {
2015-03-02 14:45:13 -07:00
private MessageContent source = new MessageContent();
private Font normalFont = new Font( "Normal", Font.BOLD, 15 );
private int chanMax;
private int chanMin;
2015-03-02 14:45:13 -07:00
public DisplayController() {
setBackground( Color.DARK_GRAY );
setPreferredSize( new Dimension( 0, 100 ) );
}
public DisplayController( MessageContent content ) {
this();
source = content;
}
/**
*
*/
private int scaleChan( int chan, int range ) {
return (int)(range * ( ( (double)(chan - chanMin) / (chanMax - chanMin) ) - 0.5 ));
2015-03-02 14:45:13 -07:00
}
public void paintComponent( Graphics g ) {
super.paintComponent( g );
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
int boxSide = getWidth() / 3;
int circleDiam = boxSide / 10;
int circleRad = circleDiam / 2;
2015-03-02 14:45:13 -07:00
g.setColor( Color.LIGHT_GRAY );
g.fillRect( boxSide / 4, boxSide / 4, boxSide , boxSide );
g.fillRect( boxSide * 7/4 , boxSide / 4, boxSide , boxSide );
g.setColor( Color.BLACK );
g.drawRect( boxSide / 4, boxSide / 4, boxSide , boxSide );
g.drawRect( boxSide * 7/4 , boxSide / 4, boxSide , boxSide );
g.setColor( Color.RED );
// left stick
g.fillOval(
scaleChan( source.controlValues[ 3 ], boxSide ) - circleRad + boxSide * 3/4,
scaleChan( source.controlValues[ 0 ], boxSide ) - circleRad + boxSide * 3/4,
circleDiam,
circleDiam );
// right stick
g.fillOval(
scaleChan( source.controlValues[ 1 ], boxSide ) - circleRad + boxSide * 9/4,
scaleChan( source.controlValues[ 2 ], boxSide ) - circleRad + boxSide * 3/4,
circleDiam,
circleDiam );
2015-03-02 14:45:13 -07:00
g.setColor( Color.LIGHT_GRAY );
for( int i = 0; i < source.controlValues.length; i++ ) {
//g.drawString( "Channel " + i + ": " + source.controlValues[0], 15, boxSide * 3/2 + i * 15 );
if( i %3 == 0 ) {
g.drawString( "Channel " + i + ": " + source.controlValues[0], 15, boxSide * 3/2 + i/3 * 15 );
}
else if( i %3 == 1) {
g.drawString( "Channel " + i + ": " + source.controlValues[0], 150 + 15, boxSide * 3/2 + i/3 * 15 );
}
else {
g.drawString( "Channel " + i + ": " + source.controlValues[0], 300 + 15, boxSide * 3/2 + i/3 * 15 );
}
}
2015-03-02 14:45:13 -07:00
}
/**
*
*/
public void actionPerformed( ActionEvent evt ) {
repaint();
2015-03-02 14:45:13 -07:00
}
}