Skip to content

Commit

Permalink
added GUI, controller class, and event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristopher Guzman committed Nov 21, 2016
1 parent 45a941a commit 0315e25
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 50 deletions.
54 changes: 54 additions & 0 deletions src/main/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main;

/**
* Created by kristopherguzman on 11/19/16.
*/

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.AnchorPane;

import java.text.DecimalFormat;

public class Controller {

@FXML private AnchorPane controlPanel;
@FXML private AnchorPane canvasPanel;
@FXML private SplitPane rootPane;
@FXML private Canvas canvas;
@FXML private Slider offsetSlider;
@FXML private Slider zoomSlider;
@FXML private Label offsetLabel;
@FXML private Label zoomLabel;

private double MIN_OFFSET = 0.000000000000000001; //10^-18
private double MAX_OFFSET = 0.0000000000000009; //9x10^-16
private int maxResolution = 100;

private DecimalFormat df = new DecimalFormat(".##");

@FXML private void initialize() {

offsetSlider.valueProperty().addListener(((observable, oldValue, newValue) -> {
offsetLabel.setText("Offset: " + newValue);
}));

zoomLabel.setText("0.1x");
zoomSlider.setValue(10);
zoomSlider.valueProperty().addListener(((observable, oldValue, newValue) -> {
double val = newValue.doubleValue() / maxResolution;
System.out.println(val);
zoomLabel.setText("Zoom: " + df.format(val) + "x");
}));

}



}
61 changes: 11 additions & 50 deletions src/main/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
Expand All @@ -22,58 +24,17 @@ public static void main(String[] args) {

}

public void start(Stage primaryStage) {
public void start(Stage primaryStage) throws Exception {

primaryStage.setTitle("Test");
Group root = new Group();
Canvas canvas = new Canvas(800, 600);
root.getChildren().add(canvas);
GraphicsContext gc = canvas.getGraphicsContext2D();
for(int i = 0; i <= 360; i+= 10) {

gc.setLineWidth(5);
gc.beginPath();
gc.moveTo(400, 300);
double x = 400 + (400 * Math.cos(Math.toRadians(i)));
double y = 300 + (300 * Math.sin(Math.toRadians(i))) - 50;
System.out.println("X: " + x + "Y: " + y + " i: " + i);
gc.lineTo(x,y);
gc.stroke();
gc.closePath();

}

for(int i = 5; i <= 360; i+= 10) {

gc.setStroke(Color.GREEN);
gc.setLineWidth(3);
gc.beginPath();
gc.moveTo(400, 300);
double x = 400 + (400 * Math.cos(Math.toRadians(i)));
double y = 300 + (300 * Math.sin(Math.toRadians(i))) - 50;
System.out.println("X: " + x + "Y: " + y + " i: " + i);
gc.lineTo(x,y);
gc.stroke();
gc.closePath();

}

for(double i = 2.5; i <= 360; i+= 5) {

gc.setStroke(Color.RED);
gc.setLineWidth(2);
gc.beginPath();
gc.moveTo(400, 300);
double x = 400 + (400 * Math.cos(Math.toRadians(i)));
double y = 300 + (300 * Math.sin(Math.toRadians(i))) - 50;
System.out.println("X: " + x + "Y: " + y + " i: " + i);
gc.lineTo(x,y);
gc.stroke();
gc.closePath();

}

primaryStage.setScene(new Scene(root));
FXMLLoader loader = new FXMLLoader();
Parent root = FXMLLoader.load(getClass().getResource("../view/view.fxml"));
primaryStage.setTitle("Nonrobust CCW");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();

}

}
42 changes: 42 additions & 0 deletions src/view/view.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<SplitPane fx:id="rootPane" dividerPositions="0.7575250836120402" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="768.0" prefWidth="1366.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.Controller">
<items>
<AnchorPane fx:id="canvasPanel" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Canvas fx:id="canvas" height="768.0" layoutY="-1.0" width="768.0" />
</children></AnchorPane>
<AnchorPane fx:id="controlPanel" maxWidth="598.0" minWidth="598.0" prefWidth="598.0" style="-fx-background-color: #535151;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="204.0" layoutY="45.0" prefHeight="74.0" prefWidth="243.0" text="CCW Test" textFill="WHITE">
<font>
<Font name="Avenir Black Oblique" size="50.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="53.0" layoutY="128.0" prefHeight="99.0" prefWidth="490.0" text="Point Q and R are collinear and extremely far away. Observe the output of the orientation test in relation to the position of point P." textAlignment="CENTER" textFill="WHITE" wrapText="true">
<font>
<Font name="Avenir Black Oblique" size="21.0" />
</font>
</Label>
<Label fx:id="offsetLabel" alignment="CENTER" contentDisplay="CENTER" layoutX="54.0" layoutY="274.0" prefHeight="51.0" prefWidth="490.0" text="Offset: 2^-53" textAlignment="CENTER" textFill="WHITE" wrapText="true">
<font>
<Font name="Avenir Black Oblique" size="21.0" />
</font>
</Label>
<Slider fx:id="offsetSlider" blockIncrement="1.0E-16" layoutX="103.0" layoutY="316.0" max="9.0E-16" min="1.0E-18" prefHeight="16.0" prefWidth="410.0" value="1.0E-16" />
<Label fx:id="zoomLabel" alignment="CENTER" contentDisplay="CENTER" layoutX="55.0" layoutY="393.0" prefHeight="51.0" prefWidth="490.0" text="Zoom: 0.3x" textAlignment="CENTER" textFill="WHITE" wrapText="true">
<font>
<Font name="Avenir Black Oblique" size="21.0" />
</font>
</Label>
<Slider fx:id="zoomSlider" layoutX="101.0" layoutY="432.0" prefHeight="16.0" prefWidth="410.0" value="30.0" />
</children></AnchorPane>
</items>
</SplitPane>

0 comments on commit 0315e25

Please sign in to comment.