Skip to content

Commit

Permalink
Finished Angle Control
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBuker committed Mar 7, 2023
1 parent 4176501 commit c786252
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 57 deletions.
29 changes: 29 additions & 0 deletions src/main/java/JRotatingComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import javax.swing.JSlider;

import java.awt.*;
import java.awt.image.BufferedImage;

public class JRotatingComponent extends Component {

JSlider slide;
BufferedImage img;

public JRotatingComponent(JSlider slide, BufferedImage img) {
this.slide = slide;
this.img = img;

refresh();
}


@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.rotate(Math.toRadians(slide.getValue()), 125, 125);
g2d.drawImage(img, 25, 25, null);
}

public void refresh() {
repaint();
}
}
30 changes: 0 additions & 30 deletions src/main/java/JRotatingPanel.java

This file was deleted.

63 changes: 36 additions & 27 deletions src/main/java/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public class Window {

Popup popup;
JFrame popupFrame;
JRotatingPanel popupPanel;
JRotatingComponent popupImg;
JSlider popupSlider;
private JButton buttonConfirm;

private JLabel myLabel;
private JButton buttonCancel;
Expand All @@ -41,6 +42,7 @@ public class Window {
private final int labelHeight = 516;

private int currentAngle;
private int previousAngle;

private final double xScalingFactor = fieldWidth / labelWidth;
private final double yScalingFactor = fieldHeight / labelHeight;
Expand All @@ -63,14 +65,20 @@ public Window(){
}

// ========== Create Popup Window =============
currentAngle = 0;
popupFrame = new JFrame();
popupSlider = new JSlider(0, 360, 0);
popupPanel = new JRotatingPanel(popupSlider, robot);

popupImg = new JRotatingComponent(popupSlider, robot);

buttonConfirm = new JButton("Finish");
buttonConfirm.setBounds(100, 365, 200, 50);
buttonConfirm.setBackground(Color.GREEN);
buttonConfirm.setForeground(Color.BLACK);
buttonConfirm.setFocusable(false);

popupPanel.setBounds(100, 50, 200, 200);
popupImg.setBounds(75, 25, 250, 250);

popupSlider.setBounds(25, 300, 350, 50);
popupSlider.setBounds(20, 300, 350, 50);
popupSlider.setPaintTrack(true);
popupSlider.setPaintTicks(true);
popupSlider.setPaintLabels(true);
Expand All @@ -79,12 +87,13 @@ public Window(){
popupSlider.setSnapToTicks(true);


popupFrame.add(popupPanel);
popupFrame.add(popupImg);
popupFrame.add(popupSlider);
popupFrame.add(buttonConfirm);

popupPanel.setVisible(true);
popupImg.setVisible(true);

popupFrame.setSize(400, 400);
popupFrame.setSize(400, 475);
popupFrame.setResizable(false);
popupFrame.setLayout(null);
popupFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
Expand All @@ -95,8 +104,7 @@ public Window(){
popupSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
currentAngle = popupSlider.getValue();
popupPanel.refresh();
popupImg.refresh();
}

});
Expand Down Expand Up @@ -174,6 +182,12 @@ public void stateChanged(ChangeEvent e) {

buttonAngle.addActionListener(e -> {
popupFrame.setVisible(true);
previousAngle = popupSlider.getValue();
});

buttonConfirm.addActionListener(e -> {
popupFrame.setVisible(false);
currentAngle = popupSlider.getValue();
});


Expand All @@ -193,27 +207,14 @@ public void mouseClicked(java.awt.event.MouseEvent e) {
g.fillOval(e.getX() - 10, e.getY() - 10, 20,20);

} else if (eventMenu.getSelectedItem().equals("Pickup Cone")) {

arr.add(String.format("X: %f Y: %f Event: %s Angle: %d", scaleX(e.getX()), scaleY(e.getY()), eventMenu.getSelectedItem(), currentAngle));
g.setColor(Color.WHITE);
g.fillOval(e.getX() - 17, e.getY() - 17, 34,34);
g.drawImage(cone, e.getX() - 15, e.getY() - 15, null);
eventMenu.setSelectedIndex(0);
drawEventIcon(cone, g, e);

} else if (eventMenu.getSelectedItem().equals("Pickup Cube")) {

arr.add(String.format("X: %f Y: %f Event: %s Angle: %d", scaleX(e.getX()), scaleY(e.getY()), eventMenu.getSelectedItem(), currentAngle));
g.setColor(Color.WHITE);
g.fillOval(e.getX() - 17, e.getY() - 17, 34,34);
g.drawImage(cube, e.getX() - 15, e.getY() - 15, null);
eventMenu.setSelectedIndex(0);
drawEventIcon(cube, g, e);

} else if (eventMenu.getSelectedItem().equals("Balance")) {
arr.add(String.format("X: %f Y: %f Event: %s Angle: %d", scaleX(e.getX()), scaleY(e.getY()), eventMenu.getSelectedItem(), currentAngle));
g.setColor(Color.WHITE);
g.fillOval(e.getX() - 17, e.getY() - 17, 34,34);
g.drawImage(balance, e.getX() - 15, e.getY() - 15, null);
eventMenu.setSelectedIndex(0);
drawEventIcon(balance, g, e);

}
} else {
System.out.printf("X: %f Y: %f Event: %s Angle: %d \n", scaleX(e.getX()), scaleY(e.getY()), eventMenu.getSelectedItem(), currentAngle);
Expand Down Expand Up @@ -265,4 +266,12 @@ public void disablePathMode() {
pathMode = false;
}

public void drawEventIcon(BufferedImage img, Graphics g, java.awt.event.MouseEvent e) {
arr.add(String.format("X: %f Y: %f Event: %s Angle: %d", scaleX(e.getX()), scaleY(e.getY()), eventMenu.getSelectedItem(), currentAngle));
g.setColor(Color.WHITE);
g.fillOval(e.getX() - 17, e.getY() - 17, 34,34);
g.drawImage(img, e.getX() - 15, e.getY() - 15, null);
eventMenu.setSelectedIndex(0);
}

}

0 comments on commit c786252

Please sign in to comment.