Schedule-Creator

Java GUI to create schedules for UNCG students
git clone git://git.wrycode.com/wrycode/archive/Schedule-Creator.git
Log | Files | Refs | README

commit 9ee4fdac952d5f53c4ab5de0d5475d48f02261b8
parent 2bb5b0d7828e0803c79d5fa5237c9d846a7befa9
Author: Ilyass Sfar <42755577+cloud0x9@users.noreply.github.com>
Date:   Wed,  8 Apr 2020 17:46:09 -0400

Added Webview with basic web buttons to "registration" screen (#56)

* Fix things I messed up

* Added a webview to "registration" screen, also added basic useful web buttons(back, forward, reload)

* Comments/format

* Made webivew slightly bigger

* Style Guide

* move "email crns" button to right place
Diffstat:
MScheduleCreator/API/APIInterface.java | 2+-
MScheduleCreator/API/EmailAPI.java | 11++++++++---
MScheduleCreator/API/EmailAdapter.java | 4++--
MScheduleCreator/Tests.java | 2+-
MScheduleCreator/controllers/CoursesController.java | 19+++++++++++++------
MScheduleCreator/controllers/PopupController.java | 2+-
MScheduleCreator/controllers/PrimaryController.java | 11-----------
AScheduleCreator/controllers/RegistrationController.java | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MScheduleCreator/resources/views/registration_screen.fxml | 17+++++++----------
MScheduleCreator/resources/views/select_courses.fxml | 6++----
10 files changed, 128 insertions(+), 39 deletions(-)

diff --git a/ScheduleCreator/API/APIInterface.java b/ScheduleCreator/API/APIInterface.java @@ -20,5 +20,5 @@ public interface APIInterface { * @throws MailjetException * @throws MailjetSocketTimeoutException */ - public void SendEmail(String _email, String _message)throws MailjetException, MailjetSocketTimeoutException; + public void sendEmail(String _email, String _message)throws MailjetException, MailjetSocketTimeoutException; } diff --git a/ScheduleCreator/API/EmailAPI.java b/ScheduleCreator/API/EmailAPI.java @@ -19,6 +19,11 @@ import org.json.JSONObject; public class EmailAPI implements APIInterface { + private static final String apiPublicKey = "4ed58dd4eac88294f8decd6ebcb37802"; + private static final String apiPrivateKey = "2ebe9765bf49eeac4c25fa0436edbcbf"; + private static final String clientVersion = "v3.1"; + private static final String sendEmail = "ScheduleCreatorUNCG@gmail.com"; + /** * Send email's using an API. * @@ -29,19 +34,19 @@ public class EmailAPI implements APIInterface { * @throws MailjetSocketTimeoutException */ @Override - public void SendEmail(String _email, String _message) throws MailjetException, MailjetSocketTimeoutException { + public void sendEmail(String _email, String _message) throws MailjetException, MailjetSocketTimeoutException { //Initalize the API requirements MailjetClient client; MailjetRequest request; MailjetResponse response; //Create a new client to send emails, using public and private api keys, and speify which version of the client is being used - client = new MailjetClient(("4ed58dd4eac88294f8decd6ebcb37802"), ("2ebe9765bf49eeac4c25fa0436edbcbf"), new ClientOptions("v3.1")); + client = new MailjetClient((apiPublicKey), (apiPrivateKey), new ClientOptions(clientVersion)); request = new MailjetRequest(Emailv31.resource) .property(Emailv31.MESSAGES, new JSONArray() .put(new JSONObject() //The email that is being used to send, this is controled from the mailjet webiste .put(Emailv31.Message.FROM, new JSONObject() - .put("Email", "ScheduleCreatorUNCG@gmail.com") + .put("Email", sendEmail) .put("Name", "Schedule Creator")) //The email that is being send to .put(Emailv31.Message.TO, new JSONArray() diff --git a/ScheduleCreator/API/EmailAdapter.java b/ScheduleCreator/API/EmailAdapter.java @@ -24,8 +24,8 @@ public class EmailAdapter implements APIInterface { * @throws MailjetSocketTimeoutException */ @Override - public void SendEmail(String _email, String _message) throws MailjetException, MailjetSocketTimeoutException { - EmailAdapter.thisApi.SendEmail(_email, _message); + public void sendEmail(String _email, String _message) throws MailjetException, MailjetSocketTimeoutException { + EmailAdapter.thisApi.sendEmail(_email, _message); } } diff --git a/ScheduleCreator/Tests.java b/ScheduleCreator/Tests.java @@ -14,7 +14,7 @@ import java.io.IOException; import java.util.List; public class Tests { - + protected static Adapter adapter = new Adapter(); public static void main(String[] args) throws IOException, MailjetException, MailjetSocketTimeoutException { diff --git a/ScheduleCreator/controllers/CoursesController.java b/ScheduleCreator/controllers/CoursesController.java @@ -3,7 +3,7 @@ package ScheduleCreator.controllers; /** * This class controls interactions in the Courses View. * - * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly, Nathan Tolodziecki + * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly, Nathan Tolodzieki * * Last Updated: 4/6/2020 */ @@ -419,8 +419,11 @@ public class CoursesController implements Initializable { int index = this.sectionTabPane.getSelectionModel().getSelectedIndex(); Tab currentTab = this.sectionTabPane.getTabs().get(index); - if (this.allUnselected(currentTab)) this.setSelectAll(true, currentTab); - else this.setSelectAll(false, currentTab); + if (this.allUnselected(currentTab)) { + this.setSelectAll(true, currentTab); + } else { + this.setSelectAll(false, currentTab); + } } /** @@ -463,8 +466,12 @@ public class CoursesController implements Initializable { } public void showCRNs(ActionEvent _event) { - if (this.currentSemester == null) return; - if (this.currentSemester.getSelectedCourses().size() == 0) return; + if (this.currentSemester == null) { + return; + } + if (this.currentSemester.getSelectedCourses().size() == 0) { + return; + } this.CRNContainer.getChildren().clear(); StringBuilder content = new StringBuilder(); for (Section section : this.currentSemester.getSchedules().get(this.currentScheduleIndex).getAddedSections()) { @@ -617,7 +624,7 @@ public class CoursesController implements Initializable { this.loadSchedule(this.currentSemester.getSchedules().get(this.currentScheduleIndex)); } } - + //Calls popup fxml for the email api public void popupAction(ActionEvent event) { try { diff --git a/ScheduleCreator/controllers/PopupController.java b/ScheduleCreator/controllers/PopupController.java @@ -28,7 +28,7 @@ public class PopupController { @FXML public void sendEmail(ActionEvent event) throws MailjetException, MailjetSocketTimeoutException { EmailAdapter testAPI = new EmailAdapter(); - testAPI.SendEmail(emailTF.getText(), "This is a temp UI API test call"); + testAPI.sendEmail(emailTF.getText(), "This is a temp UI API test call"); Stage stage = (Stage) sendBtn.getScene().getWindow(); stage.close(); } diff --git a/ScheduleCreator/controllers/PrimaryController.java b/ScheduleCreator/controllers/PrimaryController.java @@ -32,17 +32,6 @@ public class PrimaryController implements Initializable { window.show(); } - public void backToPrimary(ActionEvent _event) throws Exception { - - Parent root = FXMLLoader.load(getClass().getResource("/ScheduleCreator/resources/views/primary.fxml")); - Scene primaryScene = new Scene(root); - - //Get window object and refresh to show the new scene - Stage window = (Stage) ((Node) _event.getSource()).getScene().getWindow(); - window.setScene(primaryScene); - window.show(); - } - public void changeToRegistrationScreen(ActionEvent _event) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("/ScheduleCreator/resources/views/registration_screen.fxml")); diff --git a/ScheduleCreator/controllers/RegistrationController.java b/ScheduleCreator/controllers/RegistrationController.java @@ -0,0 +1,93 @@ +package ScheduleCreator.controllers; + +/** + * Controller for Registration + * + * @author Ilyass Sfar, Jamison Valentine + * + * Last Updated: 4/8/2020 + */ +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.application.Platform; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebHistory; +import javafx.scene.web.WebView; +import javafx.stage.Stage; + +public class RegistrationController { + + @FXML + private WebView webview; + + private WebEngine engine; + + //Button to take user back to the main screen + @FXML + void backToPrimary(ActionEvent _event) { + + try { + Parent root = FXMLLoader.load(getClass().getResource("/ScheduleCreator/resources/views/primary.fxml")); + Scene primaryScene = new Scene(root); + + //Get window object and refresh to show the new scene + Stage window = (Stage) ((Node) _event.getSource()).getScene().getWindow(); + window.setScene(primaryScene); + window.show(); + } catch (IOException ex) { + Logger.getLogger(RegistrationController.class.getName()).log(Level.SEVERE, null, ex); + } + } + + //loads the uncg geine webpage as soon as the user acesses the registration screen + public void initialize() { + engine = webview.getEngine(); + engine.load("https://ssb.uncg.edu/"); + + } + + //Forward and Backwards buttons based on https://stackoverflow.com/questions/18928333 + //Button to go back to pervious web page + @FXML + void goBackWeb(ActionEvent event) { + final WebHistory history = engine.getHistory(); + ObservableList<WebHistory.Entry> entryList = history.getEntries(); + int currentIndex = history.getCurrentIndex(); + Platform.runLater(new Runnable() { + public void run() { + history.go(-1); + } + }); + engine.load(entryList.get(currentIndex > 0 ? currentIndex - 1 : currentIndex).getUrl()); + } + + //Button to go forward to pervious web page + @FXML + void goForwardWeb(ActionEvent event) { + final WebHistory history = engine.getHistory(); + ObservableList<WebHistory.Entry> entryList = history.getEntries(); + int currentIndex = history.getCurrentIndex(); + Platform.runLater(new Runnable() { + public void run() { + history.go(1); + } + }); + engine.load(entryList.get(currentIndex < entryList.size() - 1 ? currentIndex + 1 : currentIndex).getUrl()); + + } + + //Button to reload current web page + @FXML + void reloadWeb(ActionEvent event) { + engine.reload(); + } + +} diff --git a/ScheduleCreator/resources/views/registration_screen.fxml b/ScheduleCreator/resources/views/registration_screen.fxml @@ -1,18 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?> -<?import javafx.scene.control.Label?> <?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.web.WebView?> -<AnchorPane id="AnchorPane" prefHeight="560" prefWidth="1090" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ScheduleCreator.controllers.PrimaryController"> +<AnchorPane id="AnchorPane" prefHeight="560" prefWidth="1090" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ScheduleCreator.controllers.RegistrationController"> <children> - <AnchorPane layoutX="151.0" layoutY="100.0" prefHeight="200.0" prefWidth="285.0"> - <children> - <Label layoutX="23.0" layoutY="108.0" text="Advising Code:" /> - <Label layoutX="23.0" layoutY="56.0" text="Registration Date and Time:" /> - <Label layoutX="23.0" layoutY="83.0" text="My Advisor:" /> - <Button onAction="#backToPrimary" text="Back" /> - </children> - </AnchorPane> + <Button layoutY="1.0" onAction="#backToPrimary" prefHeight="27.0" prefWidth="163.0" text="Back To Main Screen" AnchorPane.leftAnchor="1.0" AnchorPane.topAnchor="1.0" /> + <WebView fx:id="webview" layoutX="6.0" layoutY="30.0" prefHeight="500.0" prefWidth="1088.0" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="30.0" /> + <Button layoutX="14.0" layoutY="525.0" mnemonicParsing="false" onAction="#goBackWeb" prefHeight="27.0" prefWidth="318.0" text="Back" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="1.0" /> + <Button layoutX="594.0" layoutY="535.0" mnemonicParsing="false" onAction="#goForwardWeb" prefHeight="27.0" prefWidth="329.0" text="Forward" AnchorPane.bottomAnchor="1.0" AnchorPane.rightAnchor="1.0" /> + <Button layoutX="318.0" layoutY="529.0" mnemonicParsing="false" onAction="#reloadWeb" prefHeight="27.0" prefWidth="442.0" text="Reload" AnchorPane.bottomAnchor="1.0" /> </children> </AnchorPane> diff --git a/ScheduleCreator/resources/views/select_courses.fxml b/ScheduleCreator/resources/views/select_courses.fxml @@ -142,9 +142,6 @@ </BorderPane.margin> </Button> </center> - <right> - <Button mnemonicParsing="false" onAction="#popupAction" text="Email CRNs" BorderPane.alignment="CENTER" /> - </right> </BorderPane> <BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1"> <center> @@ -163,7 +160,8 @@ <RowConstraints maxHeight="27.33331298828125" minHeight="10.0" prefHeight="27.33331298828125" vgrow="SOMETIMES" /> </rowConstraints> </GridPane> - <Button mnemonicParsing="false" onAction="#showCRNs" text="Show CRNs" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> + <Button mnemonicParsing="false" onAction="#showCRNs" text="Show CRNs" translateX="-50.0" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.rowIndex="2" /> + <Button mnemonicParsing="false" onAction="#popupAction" prefHeight="27.0" prefWidth="97.0" text="Email CRNs" GridPane.columnIndex="1" GridPane.rowIndex="2" /> </children> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />