first commit

This commit is contained in:
2019-08-13 12:23:06 -05:00
commit 916073f43b
337 changed files with 23253 additions and 0 deletions

BIN
Lab 6/src/barnestr.zip Normal file

Binary file not shown.

View File

@@ -0,0 +1,134 @@
/*
* SE1021
* Spring 2018
* Lab 6 - Exceptions
* Name: Trevor Barnes
* Created: 4/18/18
*/
package barnestr;
import edu.msoe.se1021.Lab6.WebsiteTester;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.ButtonBar;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Optional;
/**
* The controller class for lab06.fxml that handles each button and text components.
* @author Trevor Barnes
* @version 2.0
*/
public class Controller {
@FXML
private TextField urlField;
@FXML
private TextField sizeField;
@FXML
private TextField downloadTimeField;
@FXML
private TextField portField;
@FXML
private TextField hostField;
@FXML
private TextField timeoutField;
@FXML
private TextArea outputArea;
WebsiteTester tester = new WebsiteTester();
/**
* Calls all of the methods required to analyze a website and catches any exceptions that
* come upt from calling these methods.
*/
public void analyze() {
try {
tester.openURL(urlField.getText());
tester.openConnection();
tester.downloadText();
outputArea.setText(tester.getContent());
sizeField.setText(Integer.toString(tester.getSize()));
downloadTimeField.setText(Long.toString(tester.getDownloadTime()));
hostField.setText(tester.getHostname());
portField.setText(Integer.toString(tester.getPort()));
} catch (MalformedURLException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Dialog");
alert.setHeaderText("URL Error");
alert.setContentText("The URL entered in the box is invalid");
alert.showAndWait();
} catch (UnknownHostException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Dialog");
alert.setHeaderText("Host Error");
alert.setContentText("Error: Unable to reach the host " + urlField.getText());
alert.showAndWait();
} catch (SocketTimeoutException e) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Timeout Dialog");
alert.setHeaderText("Wait longer?");
alert.setContentText("There has been a timeout reaching the site. " +
"Click OK to extend the timeout period?");
ButtonType buttonTypeOK = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
ButtonType buttonTypeCancel = new ButtonType("Cancel",
ButtonBar.ButtonData.CANCEL_CLOSE);
Optional<ButtonType> buttonType = alert.showAndWait();
if (buttonType.get() == ButtonType.OK) {
TextInputDialog dialog = new TextInputDialog("10");
dialog.setTitle("Set timeout");
dialog.setHeaderText("Set extended timeout");
dialog.setContentText("Desired timeout:");
dialog.showAndWait();
timeoutField.setText(dialog.getResult());
setTimeout();
}
} catch (IOException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Dialog");
alert.setHeaderText("File Error");
alert.setContentText("Error: File not found on the server, " + urlField.getText());
alert.showAndWait();
}
}
/**
* Takes the integer value in the timeout field and sets timeout with that value.
*/
public void setTimeout() {
try {
tester.setTimeout(timeoutField.getText());
} catch (NumberFormatException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Dialog");
alert.setHeaderText("Invalid Timeout Error");
alert.setContentText("Timeout must be greater than or equal to 0.");
alert.showAndWait();
timeoutField.setText(tester.getTimeout());
}
}
}

View File

@@ -0,0 +1,43 @@
/*
* SE1021
* Spring 2018
* Lab 6 - Exceptions
* Name: Trevor Barnes
* Created: 4/18/18
*/
package barnestr;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
/**
* The main class for Lab06. Launches JavaFX Application
* @author Trevor Barnes
* @version 2.0
*/
public class Lab06 extends Application {
/**
* Starts and launches the JavaFX application with lab06.fxml file.
* @param primaryStage stage containing program window
* @throws IOException throws IOException when program starts
*/
@Override
public void start(Stage primaryStage) throws IOException {
final int dimensions = 600;
Parent root = FXMLLoader.load(getClass().getResource("lab06.fxml"));
primaryStage.setTitle("Website Tester");
primaryStage.setScene(new Scene(root, dimensions, dimensions));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="barnestr.Controller">
<children>
<BorderPane prefHeight="600.0" prefWidth="600.0">
<top>
<VBox prefHeight="85.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0">
<children>
<Label text="URL" />
<TextField fx:id="urlField" onAction="#analyze" prefWidth="350.0" text="http://msoe.us/taylor/se1021/Lab6" />
<Button fx:id="analyzeButton" mnemonicParsing="false" onAction="#analyze" prefWidth="150.0" text="Analyze" />
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0">
<children>
<Label text="Size" />
<TextField fx:id="sizeField" editable="false" prefWidth="100.0" />
<Label text="Download Time">
<padding>
<Insets left="66.0" />
</padding></Label>
<TextField fx:id="downloadTimeField" editable="false" prefWidth="250.0" />
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0">
<children>
<Label text="Port" />
<TextField fx:id="portField" editable="false" prefWidth="100.0" />
<Label text="Host">
<padding>
<Insets left="125.0" />
</padding></Label>
<TextField fx:id="hostField" editable="false" prefWidth="250.0" />
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="600.0">
<children>
<Label text="Timeout" />
<TextField fx:id="timeoutField" onAction="#setTimeout" prefWidth="350.0" />
<Button fx:id="setTimeoutButton" mnemonicParsing="false" onAction="#setTimeout" prefWidth="150.0" text="Set" />
</children>
</HBox>
</children>
</VBox>
</top>
<center>
<TextArea fx:id="outputArea" editable="false" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
</children>
</Pane>