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 4ac497758bb2706ac2fdbcc1dc7df30eebd2816a
parent 681be013b25a445ec2f3e689c4cd1a7a5ea5186a
Author: jamisonv93 <47033011+jamisonv93@users.noreply.github.com>
Date:   Wed,  1 Apr 2020 15:23:44 -0400

style and refactor (#53)


Diffstat:
MScheduleCreator/controllers/CoursesController.java | 49+++++++++++++++++++------------------------------
MScheduleCreator/models/Schedule.java | 13+++++++++----
MScheduleCreator/models/Section.java | 9++++-----
MScheduleCreator/models/Semester.java | 34+++++++++++++++++++---------------
4 files changed, 51 insertions(+), 54 deletions(-)

diff --git a/ScheduleCreator/controllers/CoursesController.java b/ScheduleCreator/controllers/CoursesController.java @@ -48,7 +48,7 @@ import javafx.scene.shape.Rectangle; * * @author Jamison Valentine, Ilyass Sfar, Nick Econopouly, Nathan Tolodzieki * - * Last Updated: 3/29/2020 + * Last Updated: 3/31/2020 */ public class CoursesController implements Initializable { @@ -125,8 +125,6 @@ public class CoursesController implements Initializable { public void setSections(ActionEvent _event) { - int index = this.sectionTabPane.getSelectionModel().getSelectedIndex(); - Course course; Tab tab; for (int i = 0; i < this.sectionTabPane.getTabs().size(); i++) { @@ -175,9 +173,7 @@ public class CoursesController implements Initializable { public String semesterDirName(String _semester) { String[] temp = _semester.split(" "); - String formattedSemester = temp[0].toLowerCase() + temp[1]; - return formattedSemester; } @@ -185,10 +181,10 @@ public class CoursesController implements Initializable { * Clears the current displayed schedule. */ public void clearScheduleGrid() { - for (BorderPane entry : entries) { + for (BorderPane entry : this.entries) { scheduleGridPane.getChildren().remove(entry); } - entries.clear(); + this.entries.clear(); } /** @@ -263,7 +259,6 @@ public class CoursesController implements Initializable { // Get the corresponding course to reference for sections for (Course course : this.currentSemester.getSelectedCourses()) { if (course.getFullText().equals(currentSelection)) { - this.focusedCourse = course; break; } @@ -357,8 +352,7 @@ public class CoursesController implements Initializable { m = p.matcher(semester); if (m.matches()) { - formattedSemester = m.group(1).substring(0, 1).toUpperCase() + m.group(1).substring(1) + " " - + m.group(2); + formattedSemester = m.group(1).substring(0, 1).toUpperCase() + m.group(1).substring(1) + " " + m.group(2); } newList.add(formattedSemester); } @@ -368,8 +362,7 @@ public class CoursesController implements Initializable { public void loadSelectedCourses() { this.sectionTabPane.getTabs().clear(); - this.selectedCoursesListView - .setItems(FXCollections.observableList(this.currentSemester.getSelectedCourseStrings())); + this.selectedCoursesListView.setItems(FXCollections.observableList(this.currentSemester.getSelectedCourseStrings())); for (Course course : this.currentSemester.getSelectedCourses()) { this.createNewTab(course); @@ -419,10 +412,8 @@ public class CoursesController implements Initializable { int index = this.sectionTabPane.getSelectionModel().getSelectedIndex(); Tab currentTab = this.sectionTabPane.getTabs().get(index); - if (this.allUnselected(currentTab)) - setSelectAll(true, currentTab); - else - setSelectAll(false, currentTab); + if (this.allUnselected(currentTab)) this.setSelectAll(true, currentTab); + else this.setSelectAll(false, currentTab); } /** @@ -458,13 +449,14 @@ public class CoursesController implements Initializable { for (int j = 1; j < NUM_COLS; j++) { BorderPane region = new BorderPane(); region.setStyle(("-fx-border-color: black; -fx-border-width: .5;")); - grid[i][j] = region; - scheduleGridPane.add(region, j, i); + this.grid[i][j] = region; + this.scheduleGridPane.add(region, j, i); } } } public void showCRNs(ActionEvent _event) { + 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()) { @@ -483,20 +475,18 @@ public class CoursesController implements Initializable { public void addEntry(Section _section, int _numberOfCampusCourses) { - String color = assignColor(_numberOfCampusCourses); + String color = this.assignColor(_numberOfCampusCourses); int row = (int) _section.getStartTime() / 100 - 7; double topMargin = (_section.getStartTime() % 100) / 60; for (Integer col : getDays(_section)) { Label label = new Label(_section.getCourseID() + " - " + _section.getSectionNumber()); BorderPane entryContainer = new BorderPane(); - entryContainer.paddingProperty() - .set(new Insets(grid[row][col].heightProperty().multiply(topMargin).doubleValue(), 0, 0, 0)); + entryContainer.paddingProperty().set(new Insets(grid[row][col].heightProperty().multiply(topMargin).doubleValue(), 0, 0, 0)); StackPane pane = new StackPane(); Rectangle rect = new Rectangle(); - rect.setStyle("-fx-fill:" + color - + "; -fx-stroke: black; -fx-stroke-line-cap: round; -fx-arc-height: 10; -fx-arc-width: 10;"); + rect.setStyle("-fx-fill:" + color + "; -fx-stroke: black; -fx-stroke-line-cap: round; -fx-arc-height: 10; -fx-arc-width: 10;"); label.setAlignment(Pos.CENTER); pane.setStyle(""); @@ -538,7 +528,6 @@ public class CoursesController implements Initializable { case 'F': days.add(5); break; - } } return days; @@ -586,13 +575,13 @@ public class CoursesController implements Initializable { public void loadSchedule(Schedule _schedule) { this.hideCRNs(); - clearScheduleGrid(); + this.clearScheduleGrid(); int numberOfCampusCourses = 0; int onlineCourses = 0; StringBuilder label = new StringBuilder("Online Classes: "); for (Section section : _schedule.getAddedSections()) { if (!section.isOnline()) { - addEntry(section, ++numberOfCampusCourses); + this.addEntry(section, ++numberOfCampusCourses); } else { if (onlineCourses >= 1) label.append(" | "); @@ -600,15 +589,15 @@ public class CoursesController implements Initializable { onlineCourses++; } } - scheduleLabel.setText(this.currentScheduleIndex + 1 + "/" + this.currentSemester.getNumberOfSchedules()); - onlineClassesLabel.setText(label.toString()); + this.scheduleLabel.setText(this.currentScheduleIndex + 1 + "/" + this.currentSemester.getNumberOfSchedules()); + this.onlineClassesLabel.setText(label.toString()); } public void loadNextSchedule(ActionEvent _event) { if (this.currentSemester != null) { if (this.currentScheduleIndex < this.currentSemester.getSchedules().size() - 1) { this.currentScheduleIndex++; - loadSchedule(this.currentSemester.getSchedules().get(this.currentScheduleIndex)); + this.loadSchedule(this.currentSemester.getSchedules().get(this.currentScheduleIndex)); } } } @@ -616,7 +605,7 @@ public class CoursesController implements Initializable { public void loadPrevSchedule(ActionEvent _event) { if (this.currentScheduleIndex > 0) { this.currentScheduleIndex--; - loadSchedule(this.currentSemester.getSchedules().get(this.currentScheduleIndex)); + this.loadSchedule(this.currentSemester.getSchedules().get(this.currentScheduleIndex)); } } } diff --git a/ScheduleCreator/models/Schedule.java b/ScheduleCreator/models/Schedule.java @@ -8,18 +8,23 @@ import java.util.List; * * @author Jamison Valentine * - * Last Updated: 3/28/2020 + * Last Updated: 3/31/2020 */ public class Schedule { protected List<Section> addedSections; protected String totalCredits; - //getCRNS public Schedule() { - addedSections = new ArrayList(); + this.addedSections = new ArrayList(); } + /** + * Checks to see if this _newSection can be added to the schedule + * without incident + * @param _newSection + * @return + */ public Boolean addSection(Section _newSection) { if (this.addedSections.size() > 0 && !_newSection.isOnline) { @@ -55,7 +60,7 @@ public class Schedule { @Override public String toString() { StringBuilder string = new StringBuilder(); - for (Section section : addedSections) { + for (Section section : this.addedSections) { string.append("(" + section.getCourseID() + " - " + section.getSectionNumber() + ")\n"); } return string.toString(); diff --git a/ScheduleCreator/models/Section.java b/ScheduleCreator/models/Section.java @@ -7,7 +7,7 @@ import java.util.Scanner; * * @author Jamison Valentine * - * Last Updated: 3/27/2020 + * Last Updated: 3/31/2020 */ public class Section { @@ -32,7 +32,7 @@ public class Section { this.sectionNumber = _sectionNumber; this.id = _courseID + "-" + _sectionNumber; this.isOnline = _isOnline; - setTimes(); + this.setTimes(); } @@ -42,7 +42,6 @@ public class Section { } public double getDurationHours() { - double difference = this.endTime - this.startTime; double hours = (int) (difference / 100); double minutes = difference % 100; @@ -55,7 +54,7 @@ public class Section { } public String getDaysAndTimes() { - return daysAndTimes; + return this.daysAndTimes; } public String getDays() { @@ -103,7 +102,7 @@ public class Section { } //========================= SETTERS ============================= - public void setTimes() { + private void setTimes() { if (this.isOnline) { this.days = ""; diff --git a/ScheduleCreator/models/Semester.java b/ScheduleCreator/models/Semester.java @@ -10,7 +10,7 @@ import java.util.List; * * @author Nick Econopouly, Jamison Valentine * - * Last Updated: 3/28/2020 + * Last Updated: 3/31/2020 */ public class Semester { @@ -19,7 +19,6 @@ public class Semester { protected List<Schedule> schedules; protected LinkedHashMap<Course, List<Section>> selectedSections; - public Semester(String _name) { this.name = _name; this.allCourses = Translator.getCourses(this.name); @@ -31,10 +30,15 @@ public class Semester { public void addSelectedSection(Course _course, Section _section) { List<Section> list = new ArrayList(); + + //If the selected Course is not the the Map, add it. if (this.selectedSections.get(_course) == null) { list.add(_section); this.selectedSections.put(_course, list); - } else { + } + else { + + //Checks to see if this section is already selected. List<Section> sectionList = this.selectedSections.get(_course); if (!sectionList.contains(_section)) { sectionList.add(_section); @@ -42,10 +46,6 @@ public class Semester { } } - public LinkedHashMap<Course, List<Section>> getSelectedSections() { - return this.selectedSections; - } - public Boolean addCourse(Course _course) { if (!this.selectedSections.keySet().contains(_course)) { this.selectedSections.put(_course, _course.getSections()); @@ -55,11 +55,7 @@ public class Semester { return false; } - public List<Schedule> getSchedules() { - return this.schedules; - } - - public void generateSchedules() { + public final void generateSchedules() { List<Schedule> list = generateSchedules(new ArrayList(this.selectedSections.keySet())); this.schedules = list; } @@ -89,7 +85,9 @@ public class Semester { newSchedule.addSection(section); validSchedules.add(newSchedule); } - } //If there is more than one course in the list + } + + //If there is more than one course in the list else { //Remove the current course from the remaining list @@ -104,7 +102,6 @@ public class Semester { } } } - return validSchedules; } @@ -127,7 +124,6 @@ public class Semester { break; } } - Translator.removeCourse(_course, this.name); } @@ -157,4 +153,12 @@ public class Semester { public List<String> getSelectedCourseStrings() { return Translator.getSelectedCourses(this.name); } + + public List<Schedule> getSchedules() { + return this.schedules; + } + + public LinkedHashMap<Course, List<Section>> getSelectedSections() { + return this.selectedSections; + } }