reorganized visualizer and test processes (added abstract class for test process)
This commit is contained in:
BIN
Java/ProjectModels/Visualizer/assets/Rudder Pedals.png
Normal file
BIN
Java/ProjectModels/Visualizer/assets/Rudder Pedals.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 115 KiB |
BIN
Java/ProjectModels/Visualizer/assets/Yoke Symbol.png
Normal file
BIN
Java/ProjectModels/Visualizer/assets/Yoke Symbol.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
58
Java/ProjectModels/Visualizer/axis.java
Normal file
58
Java/ProjectModels/Visualizer/axis.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package Visualizer;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.OverlayLayout;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.Border;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.*;
|
||||
|
||||
import ModelFiles.*;
|
||||
|
||||
|
||||
public class axis extends JComponent {
|
||||
|
||||
int xBound = 0;
|
||||
int yBound = 0;
|
||||
|
||||
axis(int currentX, int currentY) {
|
||||
xBound = currentX;
|
||||
yBound = currentY;
|
||||
}
|
||||
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setColor(Color.green);
|
||||
g2.drawLine(xBound/2, 0, xBound/2, yBound);
|
||||
g2.drawLine(0, yBound/2, xBound, yBound/2);
|
||||
}
|
||||
|
||||
public void setXBound(int newX){
|
||||
this.xBound = newX;
|
||||
}
|
||||
|
||||
public void setYBound(int newY){
|
||||
this.yBound = newY;
|
||||
}
|
||||
}
|
||||
75
Java/ProjectModels/Visualizer/rudderPosition.java
Normal file
75
Java/ProjectModels/Visualizer/rudderPosition.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package Visualizer;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.OverlayLayout;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.Border;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.*;
|
||||
|
||||
import ModelFiles.*;
|
||||
|
||||
public 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/ProjectModels/Visualizer/assets/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;
|
||||
}
|
||||
|
||||
}
|
||||
162
Java/ProjectModels/Visualizer/visualizer.java
Normal file
162
Java/ProjectModels/Visualizer/visualizer.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package Visualizer;
|
||||
|
||||
import javax.swing.border.Border;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.*;
|
||||
|
||||
import ModelFiles.*;
|
||||
|
||||
public class visualizer {
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
JPanel display = new JPanel();
|
||||
JPanel visualizer = new JPanel();
|
||||
JPanel yokeGrid = new JPanel();
|
||||
axis axis = new axis(0,0);
|
||||
rudderPosition rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0);
|
||||
yokePosition yoke = new yokePosition(yokeGrid.getWidth(), yokeGrid.getHeight());
|
||||
|
||||
|
||||
|
||||
public visualizer(Model m){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void initializeDisplay() {
|
||||
frame.setPreferredSize(new Dimension(1700,270));
|
||||
frame.setLayout(new GridLayout(1,2));
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
display.setPreferredSize(new Dimension(100,100));
|
||||
display.setLayout(new GridLayout(2,4));
|
||||
|
||||
Font fontTitles = new Font("Impact", 1,40);
|
||||
Font fontData = new Font("Monospaced", 1,30);
|
||||
JLabel titleOne = new JLabel("Elevator");
|
||||
titleOne.setFont(fontTitles);
|
||||
titleOne.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
titleOne.setVerticalAlignment(SwingConstants.BOTTOM);
|
||||
JLabel titleTwo = new JLabel("Roll");
|
||||
titleTwo.setFont(fontTitles);
|
||||
titleTwo.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
titleTwo.setVerticalAlignment(SwingConstants.BOTTOM);
|
||||
JLabel titleThree = new JLabel("Yaw");
|
||||
titleThree.setFont(fontTitles);
|
||||
titleThree.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
titleThree.setVerticalAlignment(SwingConstants.BOTTOM);
|
||||
JLabel titleFour = new JLabel("Throttle");
|
||||
titleFour.setFont(fontTitles);
|
||||
titleFour.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
titleFour.setVerticalAlignment(SwingConstants.BOTTOM);
|
||||
JLabel one = new JLabel();
|
||||
one.setFont(fontData);
|
||||
one.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
one.setVerticalAlignment(SwingConstants.TOP);
|
||||
JLabel two = new JLabel();
|
||||
two.setFont(fontData);
|
||||
two.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
two.setVerticalAlignment(SwingConstants.TOP);
|
||||
JLabel three = new JLabel();
|
||||
three.setFont(fontData);
|
||||
three.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
three.setVerticalAlignment(SwingConstants.TOP);
|
||||
JLabel four = new JLabel();
|
||||
four.setFont(fontData);
|
||||
four.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
four.setVerticalAlignment(SwingConstants.TOP);
|
||||
|
||||
one.setText("Test");
|
||||
two.setText("Test");
|
||||
three.setText("Test");
|
||||
four.setText("Test");
|
||||
display.add(titleOne);
|
||||
display.add(titleTwo);
|
||||
display.add(titleThree);
|
||||
display.add(titleFour);
|
||||
display.add(one);
|
||||
display.add(two);
|
||||
display.add(three);
|
||||
display.add(four);
|
||||
|
||||
|
||||
visualizer.setLayout(new GridLayout(2,1));
|
||||
|
||||
|
||||
//Col 1 of Visualizer
|
||||
|
||||
yokeGrid.setMinimumSize(new Dimension(100,100));
|
||||
//grid.setOpaque(true);
|
||||
// grid.setLayout(null);
|
||||
yokeGrid.setBackground(Color.black);
|
||||
yokeGrid.setVisible(true);
|
||||
Integer layer1 = 0;
|
||||
Integer layer2 = 1;
|
||||
// grid.setLayout(new GridLayout(1,1));
|
||||
yokeGrid.setLayout(new OverlayLayout(yokeGrid));
|
||||
|
||||
yoke = new yokePosition(yokeGrid.getWidth(), yokeGrid.getHeight());
|
||||
// yaw yaw = new yaw(grid.getWidth(), grid.getHeight());
|
||||
axis = new axis(yokeGrid.getWidth(), yokeGrid.getHeight());
|
||||
|
||||
// grid.setLayer(axis, layer1);
|
||||
yokeGrid.add(axis);
|
||||
yokeGrid.add(yoke);
|
||||
// grid.add(yaw);
|
||||
// grid.setLayer(yoke, layer2);
|
||||
|
||||
Border greenLine = BorderFactory.createLineBorder(Color.green);
|
||||
yokeGrid.setBorder(greenLine);
|
||||
visualizer.add(yokeGrid);
|
||||
//Row 2 of Visualizer
|
||||
//Rudder Vizualizer
|
||||
rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0);
|
||||
visualizer.add(rudderGrid);
|
||||
|
||||
frame.add(display); // Left Side
|
||||
frame.add(visualizer); // Right Side
|
||||
frame.pack();
|
||||
}
|
||||
|
||||
|
||||
public void updateVisualizer(float[] ctrl1){
|
||||
yoke.setXBound(yokeGrid.getWidth());
|
||||
yoke.setYBound(yokeGrid.getHeight());
|
||||
yoke.setX(ctrl1[1]);
|
||||
yoke.setY(ctrl1[0]);
|
||||
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.setX(ctrl1[2]);
|
||||
// yaw.repaint();
|
||||
|
||||
axis.setXBound(yokeGrid.getWidth());
|
||||
axis.setYBound(yokeGrid.getHeight());
|
||||
axis.repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
96
Java/ProjectModels/Visualizer/yokePosition.java
Normal file
96
Java/ProjectModels/Visualizer/yokePosition.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package Visualizer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.OverlayLayout;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.Border;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.*;
|
||||
|
||||
import ModelFiles.*;
|
||||
|
||||
class yokePosition extends JComponent {
|
||||
float x = 0;
|
||||
int xBound = 0;
|
||||
float y = 0;
|
||||
int yBound = 0;
|
||||
|
||||
int width = 50;
|
||||
int height = 50;
|
||||
|
||||
yokePosition(int currentX, int currentY) {
|
||||
xBound = currentX;
|
||||
yBound = currentY;
|
||||
}
|
||||
|
||||
yokePosition() {
|
||||
|
||||
}
|
||||
|
||||
public void paint(Graphics 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/ProjectModels/Visualizer/assets/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);
|
||||
int currX = (int)(x*xBound) + xBound/2 - width/2;
|
||||
int currY = (int)(y*yBound) + yBound/2 - height/2;
|
||||
System.out.println("CurrX, CurrY: " + currX +", " + currY);
|
||||
// g2.drawOval(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){
|
||||
this.x = newX;
|
||||
}
|
||||
|
||||
public void setXBound(int newX){
|
||||
this.xBound = newX;
|
||||
}
|
||||
|
||||
public void setY(float newY){
|
||||
this.y = newY;
|
||||
}
|
||||
public void setYBound(int newY){
|
||||
this.yBound = newY;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user