diff --git a/src/io/scheduler/data/handler/FiltersSUClass.java b/src/io/scheduler/data/handler/FiltersSUClass.java index 96f50f7..77e9958 100644 --- a/src/io/scheduler/data/handler/FiltersSUClass.java +++ b/src/io/scheduler/data/handler/FiltersSUClass.java @@ -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; @@ -78,4 +79,19 @@ public boolean apply(SUClass arg0) { } }); } + + public static Collection filterDegreeReq( + Collection classes, DegreeReq degreeReq) { + try { + final Collection courses = degreeReq.getCourses(); + return Collections2.filter(classes, new Predicate() { + @Override + public boolean apply(SUClass arg0) { + return courses.contains(arg0.getCourse()); + } + }); + } catch (SQLException e1) { + return classes; + } + } } diff --git a/src/io/scheduler/gui/OptionSUClass.java b/src/io/scheduler/gui/OptionSUClass.java index 83ab050..81331a7 100644 --- a/src/io/scheduler/gui/OptionSUClass.java +++ b/src/io/scheduler/gui/OptionSUClass.java @@ -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; @@ -49,6 +51,9 @@ public class OptionSUClass { private JCheckBox checkBoxPreReq; private JCheckBox checkBoxTaken; private JComboBox comboBoxOp; + private JComboBox comboBoxFirstProgram; + private JComboBox comboBoxSecondProgram; + private JComboBox comboBoxThirdProgram; private JSpinner spinnerTime; public OptionSUClass(Collection suClasses) @@ -62,14 +67,66 @@ public OptionSUClass(Collection suClasses) checkBoxPreReq = new JCheckBox("Courses that is valid for prerequisite"); checkBoxTaken = new JCheckBox("Hide taken courses"); JPanel panelTimeComparer = initPanelTimeComparer(); + comboBoxFirstProgram = new JComboBox(); + comboBoxFirstProgram.addItem(null); + JPanel panelFirstProgram = initPanelProgram( + "Course type for first program:", comboBoxFirstProgram); + comboBoxSecondProgram = new JComboBox(); + comboBoxSecondProgram.addItem(null); + JPanel panelSecondProgram = initPanelProgram( + "Course type for second program:", comboBoxSecondProgram); + comboBoxThirdProgram = new JComboBox(); + 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 comboBoxReq) { + + final JComboBox comboBoxProgram = new JComboBox(); + 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()); @@ -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; @@ -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) { @@ -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(); }