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 89f04e3e779502d95becf05bda0f0cb51fef6019
parent 595762d13fd3677909350b4445f1258ba0bfc4e6
Author: jamisonv93 <47033011+jamisonv93@users.noreply.github.com>
Date:   Sun,  1 Mar 2020 13:43:45 -0500

Merge pull request #22 from cloud0x9/new-ui

implement remove selected course
Diffstat:
MScheduleCreator/DBAdapter.java | 38++++++++++++++++++++++++--------------
MScheduleCreator/controllers/CoursesController.java | 8++++++++
MScheduleCreator/resources/views/select_courses.fxml | 2+-
3 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/ScheduleCreator/DBAdapter.java b/ScheduleCreator/DBAdapter.java @@ -17,27 +17,18 @@ import java.util.Scanner; public class DBAdapter { - protected static Scanner input; - protected static File file; - protected static int currentLineNumber = 0; - protected static String currentLine = ""; + protected static File selectedCourseFile = new File("src/ScheduleCreator/resources/raw/user_selected_courses.txt");; /** * Saves a selected course (abbreviation and number) and saves to database. * @param _course * @throws Exception */ - - public static void main(String[] args) { - System.out.println("db adapter"); - } - - + public static void saveCourse(String _course) throws Exception { - file = new File("src/ScheduleCreator/resources/raw/user_selected_courses.txt"); //Open file to add new classes. - FileWriter output = new FileWriter(file, true); + FileWriter output = new FileWriter(selectedCourseFile, true); //Adds new selected course to new line. output.append(_course + "\n"); @@ -45,9 +36,28 @@ public class DBAdapter { output.close(); } + public static void removeCourse(String _course) throws Exception { + + Scanner input = new Scanner(selectedCourseFile); + StringBuffer newContents = new StringBuffer(); + String line = ""; + + while (input.hasNext()) { + line = input.nextLine(); + if (line.contains("")); + if (!line.contains(_course)) + newContents.append(_course + '\n'); + } + + FileWriter writer = new FileWriter(selectedCourseFile); + writer.append(newContents.toString()); + writer.close(); + + } + public static ArrayList<String> getSelectedCourses() throws Exception { - file = new File("src/ScheduleCreator/resources/raw/user_selected_courses.txt"); - Scanner input = new Scanner(file); + + Scanner input = new Scanner(selectedCourseFile); //Load courses from text file to be returned as a list. ArrayList<String> selectedCourses = new ArrayList(); diff --git a/ScheduleCreator/controllers/CoursesController.java b/ScheduleCreator/controllers/CoursesController.java @@ -33,6 +33,7 @@ public class CoursesController implements Initializable { @FXML private ListView selectedCourses; @FXML private Button courseButton; + @FXML private Button removeCourseButton; @Override public void initialize(URL url, ResourceBundle rb) { @@ -52,6 +53,13 @@ public class CoursesController implements Initializable { DBAdapter.saveCourse(choice); } + public void removeSelectedCourse(ActionEvent _event) throws Exception { + Object itemToRemove = selectedCourses.getSelectionModel().getSelectedItem(); + String courseToDelete = (String)itemToRemove; + selectedCourses.getItems().remove(itemToRemove); + DBAdapter.removeCourse(courseToDelete); + } + public void loadAllCourses() throws Exception { File file = new File("src/ScheduleCreator/resources/raw/courses.txt"); Scanner input = new Scanner(file); diff --git a/ScheduleCreator/resources/views/select_courses.fxml b/ScheduleCreator/resources/views/select_courses.fxml @@ -23,7 +23,7 @@ <ListView fx:id="selectedCourses" layoutX="126.0" layoutY="403.0" prefHeight="85.0" prefWidth="262.0" /> <Button fx:id="getSectionsButton" layoutX="125.0" layoutY="497.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="123.0" text="Get Sections" /> - <Button fx:id="removeCourseButton" layoutX="257.0" layoutY="497.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="131.0" text="Remove" /> + <Button fx:id="removeCourseButton" onAction="#removeSelectedCourse" layoutX="257.0" layoutY="497.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="131.0" text="Remove" /> <ComboBox fx:id="sectionBox" layoutX="126.0" layoutY="596.0" prefHeight="25.0" prefWidth="262.0" promptText="Select Section" /> <Button fx:id="AddSectionButton" layoutX="407.0" layoutY="596.0" mnemonicParsing="false" text="Add" />