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 ffebe24e5480397dd7b3d81bc9e0ff918aa2dfd9
parent 451aaa4c2a723a38f73abead0b2d5f4a189d0767
Author: Ilyass Sfar <42755577+cloud0x9@users.noreply.github.com>
Date:   Sun,  3 May 2020 16:15:39 -0400

Styleguide - format and whitespace (#73)

* Formatted and removed white space on everything.

* Added java doc's to some methods and more formatting.
Diffstat:
MScheduleCreator/API/APIInterface.java | 3++-
MScheduleCreator/Adapter.java | 4+---
MScheduleCreator/Admin.java | 55++++++++++++++++++++++++++++++++++++++++++++++++++++++-
MScheduleCreator/App.java | 3+--
MScheduleCreator/Tests.java | 3+--
MScheduleCreator/Translator.java | 41++++++++++++++++++-----------------------
MScheduleCreator/TranslatorInterface.java | 3++-
MScheduleCreator/controllers/CoursesController.java | 2+-
MScheduleCreator/models/Semester.java | 5+++--
MScheduleCreator/resources/Darkmode.css | 8+++++++-
MScheduleCreator/resources/views/UserUpdatedDB.fxml | 105+++++++++++++++++++++++++++++++++++++++++++------------------------------------
11 files changed, 147 insertions(+), 85 deletions(-)

diff --git a/ScheduleCreator/API/APIInterface.java b/ScheduleCreator/API/APIInterface.java @@ -11,6 +11,7 @@ import com.mailjet.client.errors.MailjetException; import com.mailjet.client.errors.MailjetSocketTimeoutException; public interface APIInterface { + /** * Send email's using an API. * @@ -19,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/Adapter.java b/ScheduleCreator/Adapter.java @@ -3,10 +3,8 @@ package ScheduleCreator; /** * An adapter that passes method calls to the translator. * - * @author Nathan Tolodziecki - * Last Updated: 4/21/2020 + * @author Nathan Tolodziecki Last Updated: 4/21/2020 */ - import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; diff --git a/ScheduleCreator/Admin.java b/ScheduleCreator/Admin.java @@ -101,6 +101,15 @@ public class Admin { } } + /** + * Given a raw course data file, this generates a text file with only the + * course name and day and time. Made for speed since its less information + * to go through, but currently not used. + * + * @param _inputFilepath Raw File + * @param _outputFilepath Generate text file + * @throws IOException + */ protected static void generateDayTime(String _inputFilepath, String _outputFilepath) throws IOException { // initial regex String regex = "(\\b[A-Z]{3}\\b.((\\b[0-9]{3}\\b)|(\\b[0-9]{3}\\w)).+ (([0-9]{2}\\b)))|[ ](((?:(?:[0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9].(?:[AaPp][Mm])\\b).-.(?:[0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9].(?:[AaPp][Mm])\\b))|[ ](\\b((TR\\b|MW\\b|MWF\\b|M\\b|T\\b|W\\b|R\\b|F\\b|(TBA.*TBA\\b)))\\b)[ ]"; @@ -116,6 +125,15 @@ public class Admin { } + /** + * Given a raw course data file, this generates a text file with all + * prevalent information to a course (name, time, day, building, and + * instructor) + * + * @param _inputFilepath Raw File + * @param _outputFilepath Generate text file + * @throws IOException + */ protected static void generateAllInfo(String _inputFilepath, String _outputFilepath) throws IOException { // initial regex String regex = "(.+?(?= - (?:[0-9]{5}))[ ])|([ ][0-9]{5}[ ])|([ ]\\b[A-Z]{3}\\b.\\b[0-9]{3}\\b.+ [0-9]{2}\\b)|([\\t](?:(?:(?:[0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9].(?:[AaPp][Mm])\\\\b).-.(?:[0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9].(?:[AaPp][Mm])\\b))|(\\b([\\t](TR\\b|MW\\b|MWF\\b|M\\b|T\\b|W\\b|R\\b|F\\b|(TBA.*TBA\\b)))\\b)|(\\t.*([0-9]{3}))(?=\\t[A-z]{3} [0-9]{2})|((?=(\\tLecture|\\tLab|\\tIndividual Study|\\tSeminar|\\tClinical|Colloquia|\\tDissertation or Thesis|\\tEnsemble|\\tInternship, Field Exp, Coop Ed|\\tLecture and lab|\\tPerformance|\\tPhysical Activity|\\tPracticum - Dlvrd Ind Setting|\\tPracticum - Dlvrd Org Course|\\tRecitations|\\tStudent Teaching|\\tStudio|\\tLecture and Lab|\\tDissertation or Thesis)).+?(?<=(((\\(P\\)E-mail)|(\\(P\\))|(TBA)))))"; @@ -137,6 +155,13 @@ public class Admin { Admin.writeNewFile(_outputFilepath, finalOutput); } + /** + * Generates a text file with avaliable semesters in the database. + * + * @param _inputFilepath + * @param _outputFilepath + * @throws IOException + */ protected static void generateCourseList(String _inputFilepath, String _outputFilepath) throws IOException { File file = new File(_inputFilepath); @@ -168,6 +193,14 @@ public class Admin { } } + /** + * Runs a regex on a file. + * + * @param _regex + * @param _filepath + * @return + * @throws IOException + */ protected static String runRegexOnFile(String _regex, String _filepath) throws IOException { // get fulltext of the semester text file. String content = Admin.getFullText(_filepath); @@ -186,6 +219,14 @@ public class Admin { } + /** + * Returns everything within a file. + * + * @param _filepath + * @return + * @throws FileNotFoundException + * @throws IOException + */ protected static String getFullText(String _filepath) throws FileNotFoundException, IOException { String content; File file = new File(_filepath); @@ -203,6 +244,13 @@ public class Admin { return content; } + /** + * Creates new files given location and content. + * + * @param _filepath + * @param _contents + * @throws IOException + */ protected static void writeNewFile(String _filepath, String _contents) throws IOException { // Open file and make parent directories File file = new File(_filepath); @@ -214,7 +262,12 @@ public class Admin { } } -// copied from https://www.baeldung.com/java-delete-directory + /** + * Delete things from the directory, copied from + * https://www.baeldung.com/java-delete-directory. + * + * @param _dir Directory + */ protected static void deleteDirectory(File _dir) { File[] allContents = _dir.listFiles(); if (allContents != null) { diff --git a/ScheduleCreator/App.java b/ScheduleCreator/App.java @@ -7,13 +7,13 @@ package ScheduleCreator; * * Last Updated: 3/18/2020 */ - import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; + public class App extends Application { /** @@ -37,7 +37,6 @@ public class App extends Application { primaryStage.setMinHeight(560); primaryStage.setMinWidth(1090); - // shows window on screen primaryStage.show(); } diff --git a/ScheduleCreator/Tests.java b/ScheduleCreator/Tests.java @@ -19,9 +19,8 @@ public class Tests { // uncomment and run this once when we add a new semester // Admin.regenDB(); - //test validate method - emailMethodTestData(); + emailMethodTestData(); } diff --git a/ScheduleCreator/Translator.java b/ScheduleCreator/Translator.java @@ -1,4 +1,5 @@ package ScheduleCreator; + /** * This class is used to retrieve and modify persistent data for the * application. @@ -7,7 +8,6 @@ package ScheduleCreator; * * Last Updated: 4/21/2020 */ - import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -54,6 +54,7 @@ public class Translator implements TranslatorInterface { return semesters; } + // DUMMY @Override public List<String> getSections(String _courseNumber, String _semester) { @@ -72,8 +73,8 @@ public class Translator implements TranslatorInterface { sections.add(line); } } + } catch (IOException ex) { } - catch (IOException ex) {} return sections; } @@ -90,7 +91,7 @@ public class Translator implements TranslatorInterface { public String getFullText(String _resourceName) throws FileNotFoundException, IOException { String path = "resources/" + _resourceName; String content; - try ( InputStream stream = Translator.class.getResourceAsStream(path); InputStreamReader reader = new InputStreamReader(stream)) { + try (InputStream stream = Translator.class.getResourceAsStream(path); InputStreamReader reader = new InputStreamReader(stream)) { BufferedReader bufreader = new BufferedReader(reader); StringBuilder sb = new StringBuilder(); String str; @@ -111,20 +112,21 @@ public class Translator implements TranslatorInterface { * */ @Override - public List<String> getCourses(String _semesterName) { + public List<String> getCourses(String _semesterName) { List<String> courses = new ArrayList(); try { - String contents = new Translator().getFullText("DB/" + _semesterName + "/courses"); - courses = Arrays.asList(contents.split("\n")); + String contents = new Translator().getFullText("DB/" + _semesterName + "/courses"); + courses = Arrays.asList(contents.split("\n")); + } catch (IOException ex) { } - catch (IOException ex) {} return courses; } /** - * Get specific information about a section + * Get specific information about a section, this is a backup method if + * necessary in the future, since the models package uses its own regex. * * @param _choice type of info wanted about section * @param _semesterName semester name from getSemesters() @@ -188,8 +190,6 @@ public class Translator implements TranslatorInterface { return "Error: Check ScheduleCreator.DBAdapter.getInfoBase"; } - // =============================================== - // (DELETE THIS) methods above this point don't modify files /** * Saves the selected course (abbreviation and number) to persistent * database. @@ -203,11 +203,10 @@ public class Translator implements TranslatorInterface { //Adds new selected course to new line. Translator.selectedCourseFile = new File(_semester + "_selected_courses.txt"); try ( //Open file to add new classes. - FileWriter output = new FileWriter(new File(_semester + "_selected_courses.txt"), true)) { + FileWriter output = new FileWriter(new File(_semester + "_selected_courses.txt"), true)) { //Adds new selected course to new line. output.append(_course + "\n"); - } - catch (Exception ex) { + } catch (Exception ex) { System.out.println("Course was not saved succesfully"); } } @@ -232,16 +231,14 @@ public class Translator implements TranslatorInterface { } } - try ( FileWriter writer = new FileWriter(Translator.selectedCourseFile)) { + try (FileWriter writer = new FileWriter(Translator.selectedCourseFile)) { for (String course : courses) { writer.append(course + "\n"); } writer.close(); + } catch (Exception ex) { } - catch (Exception ex) {} - } - - catch (IOException ex) { + } catch (IOException ex) { } } @@ -257,18 +254,16 @@ public class Translator implements TranslatorInterface { ArrayList<String> selectedCourses = new ArrayList(); //Load courses from text file to be returned as a list. - try ( Scanner input = new Scanner(new File(_semester + "_selected_courses.txt"))) { + try (Scanner input = new Scanner(new File(_semester + "_selected_courses.txt"))) { //Load courses from text file to be returned as a list. String line; while (input.hasNext()) { line = input.nextLine(); selectedCourses.add(line); } - } - catch (FileNotFoundException ex) { + } catch (FileNotFoundException ex) { System.out.println(_semester + "user_selected_courses.txt file does not exist yet (no selected courses for semester)"); - } - finally { + } finally { return selectedCourses; } } diff --git a/ScheduleCreator/TranslatorInterface.java b/ScheduleCreator/TranslatorInterface.java @@ -1,16 +1,17 @@ package ScheduleCreator; + /** * An interface to allow easier modularity of the adapter. * * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly, Nathan Tolodzieki * Last updated 04/21/2020 */ - import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; public interface TranslatorInterface { + /** * * @return a list of semester names (Strings) that can be used as arguments diff --git a/ScheduleCreator/controllers/CoursesController.java b/ScheduleCreator/controllers/CoursesController.java @@ -672,7 +672,7 @@ public class CoursesController implements Initializable { } /** - * Open the popup for when the user clicks "Email CRN" + * Open the email popup for when the user clicks "Email CRN". * * @param event */ diff --git a/ScheduleCreator/models/Semester.java b/ScheduleCreator/models/Semester.java @@ -114,7 +114,8 @@ public class Semester { /** * Removes the course from the Semester. - * @param _course + * + * @param _course */ public void removeCourse(String _course) { @@ -129,7 +130,7 @@ public class Semester { @Override public boolean equals(Object _obj) { - if(!(_obj instanceof Semester)){ + if (!(_obj instanceof Semester)) { return false; } Semester otherSemester = (Semester) _obj; diff --git a/ScheduleCreator/resources/Darkmode.css b/ScheduleCreator/resources/Darkmode.css @@ -1,3 +1,8 @@ +/* + CSS used for darkmode, based on https://stackoverflow.com/questions/49159286. + @author Ilyass Sfar + Last Updated: 4/21/2020 +*/ .root { -fx-accent: #1e74c6; -fx-focus-color: -fx-accent; @@ -11,7 +16,8 @@ } .text-field { - -fx-prompt-text-fill: gray; + -fx-prompt-text-fill: #666666; + } .titulo{ diff --git a/ScheduleCreator/resources/views/UserUpdatedDB.fxml b/ScheduleCreator/resources/views/UserUpdatedDB.fxml @@ -7,52 +7,61 @@ <?import javafx.scene.text.Text?> <AnchorPane id="AnchorPane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ScheduleCreator.controllers.UserUpdatedDBController"> - <children> - <Text layoutX="65.0" layoutY="57.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How to Add New Semesters to the Database" wrappingWidth="650.9179649353027"> - <font> - <Font name="System Bold" size="29.0" /> - </font></Text> - <Text layoutX="100.0" layoutY="115.0" strokeType="OUTSIDE" strokeWidth="0.0" text="1. Go to the &quot;Registration&quot; tab in the menu."> - <font> - <Font size="18.0" /> - </font></Text> - <Text layoutX="100.0" layoutY="152.0" strokeType="OUTSIDE" strokeWidth="0.0" text="2. Click on &quot;Detailed Class Schedule&quot; and select the desired semester." wrappingWidth="610.91796875"> - <font> - <Font size="18.0" /> - </font></Text> - <Text layoutX="100.0" layoutY="188.0" strokeType="OUTSIDE" strokeWidth="0.0" text="3. Highlight everything in the &quot;Subject&quot; box, then click &quot;Class Search&quot; at the bottom of the page" wrappingWidth="591.2802791595459"> - <font> - <Font size="18.0" /> - </font></Text> - <Text layoutX="100.0" layoutY="241.0" strokeType="OUTSIDE" strokeWidth="0.0" text="4. Copy the enitre page" wrappingWidth="457.20605850219727"> - <font> - <Font size="18.0" /> - </font></Text> - <Text layoutX="99.0" layoutY="330.0" strokeType="OUTSIDE" strokeWidth="0.0" text="5. Create a new text file, paste everything copied in the pervious step, name* and save the file." wrappingWidth="636.2802734375"> - <font> - <Font size="18.0" /> - </font></Text> - <Text layoutX="143.0" layoutY="269.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(cmd+a on mac &amp; crtl+a on windows to highlight everything)"> - <font> - <Font size="15.0" /> - </font></Text> - <Text layoutX="143.0" layoutY="289.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(cmd+c on mac &amp; ctrl+c on windows to copy) "> - <font> - <Font size="15.0" /> - </font></Text> - <Text layoutX="139.0" layoutY="383.0" strokeType="OUTSIDE" strokeWidth="0.0" text="*File name should be lower case and contain no spaces (ex. spring2020, fall2025)"> - <font> - <Font size="15.0" /> - </font></Text> - <Text layoutX="99.0" layoutY="419.0" strokeType="OUTSIDE" strokeWidth="0.0" text="6. If all pervious steps were done correctly, you can drag and drop your text file on the current screen and it will be added to the database!" wrappingWidth="658.91796875"> - <font> - <Font name="System Bold" size="18.0" /> - </font> - </Text> - <SubScene height="567.0" layoutX="3.0" layoutY="1.0" onDragDropped="#dragDrop" onDragOver="#dragOver" opacity="0.0" width="829.0"> - <root> - <Region /> - </root> - </SubScene> - </children> + <children> + <Text layoutX="65.0" layoutY="57.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How to Add New Semesters to the Database" wrappingWidth="650.9179649353027"> + <font> + <Font name="System Bold" size="29.0" /> + </font> + </Text> + <Text layoutX="100.0" layoutY="115.0" strokeType="OUTSIDE" strokeWidth="0.0" text="1. Go to the &quot;Registration&quot; tab in the menu."> + <font> + <Font size="18.0" /> + </font> + </Text> + <Text layoutX="100.0" layoutY="152.0" strokeType="OUTSIDE" strokeWidth="0.0" text="2. Click on &quot;Detailed Class Schedule&quot; and select the desired semester." wrappingWidth="610.91796875"> + <font> + <Font size="18.0" /> + </font> + </Text> + <Text layoutX="100.0" layoutY="188.0" strokeType="OUTSIDE" strokeWidth="0.0" text="3. Highlight everything in the &quot;Subject&quot; box, then click &quot;Class Search&quot; at the bottom of the page" wrappingWidth="591.2802791595459"> + <font> + <Font size="18.0" /> + </font> + </Text> + <Text layoutX="100.0" layoutY="241.0" strokeType="OUTSIDE" strokeWidth="0.0" text="4. Copy the enitre page" wrappingWidth="457.20605850219727"> + <font> + <Font size="18.0" /> + </font> + </Text> + <Text layoutX="99.0" layoutY="330.0" strokeType="OUTSIDE" strokeWidth="0.0" text="5. Create a new text file, paste everything copied in the pervious step, name* and save the file." wrappingWidth="636.2802734375"> + <font> + <Font size="18.0" /> + </font> + </Text> + <Text layoutX="143.0" layoutY="269.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(cmd+a on mac &amp; crtl+a on windows to highlight everything)"> + <font> + <Font size="15.0" /> + </font> + </Text> + <Text layoutX="143.0" layoutY="289.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(cmd+c on mac &amp; ctrl+c on windows to copy) "> + <font> + <Font size="15.0" /> + </font> + </Text> + <Text layoutX="139.0" layoutY="383.0" strokeType="OUTSIDE" strokeWidth="0.0" text="*File name should be lower case and contain no spaces (ex. spring2020, fall2025)"> + <font> + <Font size="15.0" /> + </font> + </Text> + <Text layoutX="99.0" layoutY="419.0" strokeType="OUTSIDE" strokeWidth="0.0" text="6. If all pervious steps were done correctly, you can drag and drop your text file on the current screen and it will be added to the database!" wrappingWidth="658.91796875"> + <font> + <Font name="System Bold" size="18.0" /> + </font> + </Text> + <SubScene height="567.0" layoutX="3.0" layoutY="1.0" onDragDropped="#dragDrop" onDragOver="#dragOver" opacity="0.0" width="829.0"> + <root> + <Region /> + </root> + </SubScene> + </children> </AnchorPane>