Skip to content

Commit

Permalink
course type filters are added
Browse files Browse the repository at this point in the history
  • Loading branch information
skarahoda committed Sep 6, 2015
1 parent 216ea57 commit 5dcf5a0
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/io/scheduler/data/handler/FiltersSUClass.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.scheduler.data.handler;

import io.scheduler.data.Course;
import io.scheduler.data.DegreeReq;
import io.scheduler.data.Meeting;
import io.scheduler.data.Meeting.DayOfWeek;
import io.scheduler.data.SUClass;
Expand Down Expand Up @@ -78,4 +79,19 @@ public boolean apply(SUClass arg0) {
}
});
}

public static Collection<SUClass> filterDegreeReq(
Collection<SUClass> classes, DegreeReq degreeReq) {
try {
final Collection<Course> courses = degreeReq.getCourses();
return Collections2.filter(classes, new Predicate<SUClass>() {
@Override
public boolean apply(SUClass arg0) {
return courses.contains(arg0.getCourse());
}
});
} catch (SQLException e1) {
return classes;
}
}
}
78 changes: 77 additions & 1 deletion src/io/scheduler/gui/OptionSUClass.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.scheduler.gui;

import io.scheduler.data.Course;
import io.scheduler.data.DegreeReq;
import io.scheduler.data.Meeting;
import io.scheduler.data.Program;
import io.scheduler.data.SUClass;
import io.scheduler.data.SUClass.ComparisonOperator;
import io.scheduler.data.TakenCourse;
Expand Down Expand Up @@ -49,6 +51,9 @@ public class OptionSUClass {
private JCheckBox checkBoxPreReq;
private JCheckBox checkBoxTaken;
private JComboBox<Object> comboBoxOp;
private JComboBox<DegreeReq> comboBoxFirstProgram;
private JComboBox<DegreeReq> comboBoxSecondProgram;
private JComboBox<DegreeReq> comboBoxThirdProgram;
private JSpinner spinnerTime;

public OptionSUClass(Collection<SUClass> suClasses)
Expand All @@ -62,14 +67,66 @@ public OptionSUClass(Collection<SUClass> suClasses)
checkBoxPreReq = new JCheckBox("Courses that is valid for prerequisite");
checkBoxTaken = new JCheckBox("Hide taken courses");
JPanel panelTimeComparer = initPanelTimeComparer();
comboBoxFirstProgram = new JComboBox<DegreeReq>();
comboBoxFirstProgram.addItem(null);
JPanel panelFirstProgram = initPanelProgram(
"Course type for first program:", comboBoxFirstProgram);
comboBoxSecondProgram = new JComboBox<DegreeReq>();
comboBoxSecondProgram.addItem(null);
JPanel panelSecondProgram = initPanelProgram(
"Course type for second program:", comboBoxSecondProgram);
comboBoxThirdProgram = new JComboBox<DegreeReq>();
comboBoxThirdProgram.addItem(null);
JPanel panelThirdProgram = initPanelProgram(
"Course type for third program:", comboBoxThirdProgram);
addEventListeners();
fillScrollCourse();
Object[] messages = { panelTimeComparer, checkBoxCoReq, checkBoxPreReq,
checkBoxTaken, optionPanel };
checkBoxTaken, panelFirstProgram, panelSecondProgram,
panelThirdProgram, optionPanel };
option = JOptionPane.showConfirmDialog(null, messages, "Classes",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
}

private JPanel initPanelProgram(String message,
final JComboBox<DegreeReq> comboBoxReq) {

final JComboBox<Program> comboBoxProgram = new JComboBox<Program>();
JPanel returnVal = new JPanel();
comboBoxProgram.addItem(null);
try {
for (Program program : Program.getAll()) {
comboBoxProgram.addItem(program);
}
} catch (SQLException e) {
}

comboBoxProgram.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
comboBoxReq.removeAllItems();
comboBoxReq.addItem(null);
if (comboBoxProgram.getSelectedItem() == null)
return;
for (DegreeReq req : ((Program) comboBoxProgram
.getSelectedItem()).getRequirements()) {
try {
if (!req.getCourses().isEmpty())
comboBoxReq.addItem(req);
} catch (SQLException e) {
}
}
}
});

returnVal.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
returnVal.add(new JLabel(message));
returnVal.add(comboBoxProgram);
returnVal.add(comboBoxReq);
return returnVal;
}

private JPanel initPanelTimeComparer() {
spinnerTime = new JSpinner();
spinnerTime.setModel(new SpinnerDateModel());
Expand All @@ -79,6 +136,7 @@ private JPanel initPanelTimeComparer() {
comboBoxOp.setSelectedIndex(0);
JPanel returnVal = new JPanel();
returnVal.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
returnVal.add(new JLabel("Filter for time"));
returnVal.add(spinnerTime);
returnVal.add(comboBoxOp);
return returnVal;
Expand Down Expand Up @@ -149,6 +207,9 @@ public void actionPerformed(ActionEvent e) {
checkBoxPreReq.addActionListener(filterListener);
checkBoxTaken.addActionListener(filterListener);
comboBoxOp.addActionListener(filterListener);
comboBoxFirstProgram.addActionListener(filterListener);
comboBoxSecondProgram.addActionListener(filterListener);
comboBoxThirdProgram.addActionListener(filterListener);
spinnerTime.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
Expand Down Expand Up @@ -188,6 +249,21 @@ protected void filter() {
(ComparisonOperator) comboBoxOp.getSelectedItem(),
(Date) spinnerTime.getValue());
}
if (comboBoxFirstProgram.getSelectedItem() != null) {
filteredSuClasses = FiltersSUClass.filterDegreeReq(
filteredSuClasses,
(DegreeReq) comboBoxFirstProgram.getSelectedItem());
}
if (comboBoxSecondProgram.getSelectedItem() != null) {
filteredSuClasses = FiltersSUClass.filterDegreeReq(
filteredSuClasses,
(DegreeReq) comboBoxSecondProgram.getSelectedItem());
}
if (comboBoxThirdProgram.getSelectedItem() != null) {
filteredSuClasses = FiltersSUClass.filterDegreeReq(
filteredSuClasses,
(DegreeReq) comboBoxThirdProgram.getSelectedItem());
}
fillScrollCourse();
}

Expand Down

0 comments on commit 5dcf5a0

Please sign in to comment.