Update 2 10-12-2024
This commit is contained in:
BIN
Java/Examples/Model-1/content/Rudder Pedals.png
Normal file
BIN
Java/Examples/Model-1/content/Rudder Pedals.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 115 KiB |
BIN
Java/Examples/Model-1/content/Yoke Symbol.png
Normal file
BIN
Java/Examples/Model-1/content/Yoke Symbol.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
@@ -10,6 +10,9 @@ import java.net.SocketException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@@ -125,42 +128,47 @@ public class Main
|
|||||||
display.add(four);
|
display.add(four);
|
||||||
|
|
||||||
JPanel visualizer = new JPanel();
|
JPanel visualizer = new JPanel();
|
||||||
visualizer.setLayout(new GridLayout(1,2));
|
visualizer.setLayout(new GridLayout(2,1));
|
||||||
|
|
||||||
|
|
||||||
//Col 1 of Visualizer
|
//Col 1 of Visualizer
|
||||||
JPanel grid = new JPanel();
|
JPanel yokeGrid = new JPanel();
|
||||||
grid.setMinimumSize(new Dimension(100,100));
|
yokeGrid.setMinimumSize(new Dimension(100,100));
|
||||||
//grid.setOpaque(true);
|
//grid.setOpaque(true);
|
||||||
// grid.setLayout(null);
|
// grid.setLayout(null);
|
||||||
grid.setBackground(Color.black);
|
yokeGrid.setBackground(Color.black);
|
||||||
grid.setVisible(true);
|
yokeGrid.setVisible(true);
|
||||||
Integer layer1 = 0;
|
Integer layer1 = 0;
|
||||||
Integer layer2 = 1;
|
Integer layer2 = 1;
|
||||||
// grid.setLayout(new GridLayout(1,1));
|
// grid.setLayout(new GridLayout(1,1));
|
||||||
grid.setLayout(new OverlayLayout(grid));
|
yokeGrid.setLayout(new OverlayLayout(yokeGrid));
|
||||||
|
|
||||||
yokePosition yoke = new yokePosition(grid.getWidth(), grid.getHeight());
|
yokePosition yoke = new yokePosition(yokeGrid.getWidth(), yokeGrid.getHeight());
|
||||||
// yaw yaw = new yaw(grid.getWidth(), grid.getHeight());
|
// yaw yaw = new yaw(grid.getWidth(), grid.getHeight());
|
||||||
axis axis = new axis(grid.getWidth(), grid.getHeight());
|
axis axis = new axis(yokeGrid.getWidth(), yokeGrid.getHeight());
|
||||||
|
|
||||||
// grid.setLayer(axis, layer1);
|
// grid.setLayer(axis, layer1);
|
||||||
grid.add(axis);
|
yokeGrid.add(axis);
|
||||||
grid.add(yoke);
|
yokeGrid.add(yoke);
|
||||||
// grid.add(yaw);
|
// grid.add(yaw);
|
||||||
// grid.setLayer(yoke, layer2);
|
// grid.setLayer(yoke, layer2);
|
||||||
|
|
||||||
Border greenLine = BorderFactory.createLineBorder(Color.green);
|
Border greenLine = BorderFactory.createLineBorder(Color.green);
|
||||||
grid.setBorder(greenLine);
|
yokeGrid.setBorder(greenLine);
|
||||||
|
|
||||||
visualizer.add(grid);
|
visualizer.add(yokeGrid);
|
||||||
|
|
||||||
|
|
||||||
|
//Row 2 of Visualizer
|
||||||
|
//Rudder Vizualizer
|
||||||
|
rudderPosition rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0);
|
||||||
|
visualizer.add(rudderGrid);
|
||||||
|
|
||||||
|
|
||||||
//Col 2 of Visualizer
|
|
||||||
|
|
||||||
|
|
||||||
frame.add(display);
|
frame.add(display); // Left Side
|
||||||
frame.add(visualizer);
|
frame.add(visualizer); // Right Side
|
||||||
frame.pack();
|
frame.pack();
|
||||||
|
|
||||||
// JLabel text = new JLabel("Hello");
|
// JLabel text = new JLabel("Hello");
|
||||||
@@ -178,7 +186,7 @@ public class Main
|
|||||||
|
|
||||||
|
|
||||||
int aircraft = 0;
|
int aircraft = 0;
|
||||||
boolean takeoff = false;
|
boolean takeoff = true;
|
||||||
boolean climb = false;
|
boolean climb = false;
|
||||||
boolean cruise = false;
|
boolean cruise = false;
|
||||||
boolean throttleFull = false;
|
boolean throttleFull = false;
|
||||||
@@ -243,20 +251,26 @@ public class Main
|
|||||||
four.setForeground(Color.red);
|
four.setForeground(Color.red);
|
||||||
}
|
}
|
||||||
|
|
||||||
yoke.setXBound(grid.getWidth());
|
yoke.setXBound(yokeGrid.getWidth());
|
||||||
yoke.setYBound(grid.getHeight());
|
yoke.setYBound(yokeGrid.getHeight());
|
||||||
yoke.setX(ctrl1[1]);
|
yoke.setX(ctrl1[1]);
|
||||||
yoke.setY(ctrl1[0]);
|
yoke.setY(ctrl1[0]);
|
||||||
yoke.repaint();
|
yoke.repaint();
|
||||||
|
|
||||||
|
rudderGrid.setXBound(yokeGrid.getWidth());
|
||||||
|
rudderGrid.setYBound(yokeGrid.getHeight());
|
||||||
|
rudderGrid.setX(ctrl1[2]);
|
||||||
|
rudderGrid.repaint();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// yaw.setYBound(grid.getHeight());
|
// yaw.setYBound(grid.getHeight());
|
||||||
// yaw.setYBound(grid.getHeight());
|
// yaw.setYBound(grid.getHeight());
|
||||||
// yaw.setX(ctrl1[2]);
|
// yaw.setX(ctrl1[2]);
|
||||||
// yaw.repaint();
|
// yaw.repaint();
|
||||||
|
|
||||||
axis.setXBound(grid.getWidth());
|
axis.setXBound(yokeGrid.getWidth());
|
||||||
axis.setYBound(grid.getHeight());
|
axis.setYBound(yokeGrid.getHeight());
|
||||||
axis.repaint();
|
axis.repaint();
|
||||||
|
|
||||||
//Writing Data to a File
|
//Writing Data to a File
|
||||||
@@ -495,6 +509,10 @@ class axis extends JComponent {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class yokePosition extends JComponent {
|
class yokePosition extends JComponent {
|
||||||
float x = 0;
|
float x = 0;
|
||||||
int xBound = 0;
|
int xBound = 0;
|
||||||
@@ -509,20 +527,41 @@ class yokePosition extends JComponent {
|
|||||||
yBound = currentY;
|
yBound = currentY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yokePosition() {
|
||||||
yokePosition(){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics g)
|
public void paint(Graphics g)
|
||||||
{
|
{
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final BufferedImage image = ImageIO.read(new File("/Users/flyingtopher/Desktop/Code Citadel/School/2. Research/Fork Clone/XPlaneConnectCSP/Java/Examples/Model-1/content/Yoke Symbol.png"));
|
||||||
|
Image scaledImage = image.getScaledInstance(xBound, yBound, Image.SCALE_DEFAULT);
|
||||||
|
|
||||||
|
g.drawImage(scaledImage, 0, 0, getFocusCycleRootAncestor());
|
||||||
|
} catch (IOException e){
|
||||||
|
System.out.print("Rudder Image Failed");
|
||||||
|
}
|
||||||
|
|
||||||
g2.setColor(Color.red);
|
g2.setColor(Color.red);
|
||||||
int currX = (int)(x*xBound) + xBound/2 - width/2;
|
int currX = (int)(x*xBound) + xBound/2 - width/2;
|
||||||
int currY = (int)(y*yBound) + yBound/2 - height/2;
|
int currY = (int)(y*yBound) + yBound/2 - height/2;
|
||||||
System.out.println("CurrX, CurrY: " + currX +", " + currY);
|
System.out.println("CurrX, CurrY: " + currX +", " + currY);
|
||||||
// g2.drawOval(currX, currY, width, height);
|
// g2.drawOval(currX, currY, width, height);
|
||||||
|
|
||||||
g2.fillOval(currX, currY, width, height);
|
g2.fillOval(currX, currY, width, height);
|
||||||
|
g.setColor(Color.green);
|
||||||
|
int height = g.getFontMetrics().getHeight();
|
||||||
|
g.drawString("Nose Down", (xBound/2) + 5, height);
|
||||||
|
g.drawString("Nose Up", (xBound/2) + 5, yBound - height/2);
|
||||||
|
g.drawString("Roll Left",0, yBound/2);
|
||||||
|
int width = g.getFontMetrics().stringWidth("Roll Right");
|
||||||
|
g.drawString("Roll Right", xBound - width, yBound/2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setX(float newX){
|
public void setX(float newX){
|
||||||
@@ -539,4 +578,56 @@ class yokePosition extends JComponent {
|
|||||||
public void setYBound(int newY){
|
public void setYBound(int newY){
|
||||||
this.yBound = newY;
|
this.yBound = newY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class rudderPosition extends JComponent {
|
||||||
|
|
||||||
|
int xBound = 0;
|
||||||
|
int yBound = 0;
|
||||||
|
|
||||||
|
float rudderTravel = 0;
|
||||||
|
|
||||||
|
rudderPosition(int currentXBound, int currentYBound) {
|
||||||
|
xBound = currentXBound;
|
||||||
|
yBound = currentYBound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
int spacer = 10;
|
||||||
|
g.setColor(Color.gray);
|
||||||
|
g2.fillRect(0, spacer, xBound, yBound - spacer);
|
||||||
|
|
||||||
|
g2.setColor(Color.red);
|
||||||
|
int width = (int) (xBound/2 * rudderTravel);
|
||||||
|
//g2.drawRect(xBound/2, 0 +spacer, width, yBound);
|
||||||
|
g2.fillRect(xBound/2, 0 + spacer, width, yBound);
|
||||||
|
|
||||||
|
g.drawString("Yaw Left",0, yBound/2);
|
||||||
|
int textWidth = g.getFontMetrics().stringWidth("Roll Right");
|
||||||
|
g.drawString("Yaw Right", xBound - textWidth, yBound/2);
|
||||||
|
try {
|
||||||
|
final BufferedImage image = ImageIO.read(new File("/Users/flyingtopher/Desktop/Code Citadel/School/2. Research/Fork Clone/XPlaneConnectCSP/Java/Examples/Model-1/content/Rudder Pedals.png"));
|
||||||
|
Image scaledImage = image.getScaledInstance(xBound, yBound, Image.SCALE_DEFAULT);
|
||||||
|
g.drawImage(scaledImage, 0, 0, getFocusCycleRootAncestor());
|
||||||
|
} catch (IOException e){
|
||||||
|
System.out.print("Rudder Image Failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(float newX) {
|
||||||
|
this.rudderTravel = newX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setXBound(int newX) {
|
||||||
|
this.xBound = newX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYBound(int newY) {
|
||||||
|
this.yBound = newY;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
102930
Java/Examples/Model-1/src/legacy output
Normal file
102930
Java/Examples/Model-1/src/legacy output
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user