All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.pdx.cs.joy.grader.poa.ui.POAAssignmentsWidget Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package edu.pdx.cs.joy.grader.poa.ui;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import edu.pdx.cs.joy.grader.poa.POAAssignmentsView;

import javax.swing.*;
import java.awt.*;
import java.util.List;

@Singleton
public class POAAssignmentsWidget extends JPanel implements POAAssignmentsView {
  private final JComboBox assignments;
  private final JLabel dueDate;

  @Inject
  public POAAssignmentsWidget() {
    assignments = new JComboBox<>();
    assignments.setEditable(false);

    this.dueDate = new JLabel("Due:");

    this.setLayout(new BorderLayout());
    this.add(new JLabel("POA:"), BorderLayout.WEST);
    this.add(this.assignments, BorderLayout.CENTER);
    this.add(this.dueDate, BorderLayout.EAST);
  }

  @Override
  public void setAssignments(List assignments) {
    String[] array = assignments.toArray(new String[assignments.size()]);
    this.assignments.setModel(new DefaultComboBoxModel<>(array));
  }

  @Override
  public void setSelectedAssignment(int index) {
    this.assignments.setSelectedIndex(index);
  }

  @Override
  public void addAssignmentSelectedHandler(AssignmentSelectedHandler handler) {
    this.assignments.addActionListener(e -> {
      int index = assignments.getSelectedIndex();
      handler.assignmentSelected(index);
    });
  }

  @Override
  public void setSelectedAssignmentDueDate(String dueDate) {
    this.dueDate.setText("Due: " + dueDate);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy