standard size for lists.

This commit is contained in:
Andrew Lalis 2018-08-30 15:54:13 +02:00
parent 7f9a44d0ad
commit ed2a337bdc
4 changed files with 51 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package nl.andrewlalis.model;
import org.kohsuke.github.GHTeam;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@ -31,6 +32,14 @@ public class TATeam extends Team {
this.name = name;
}
/**
* Gets a list of teaching assistants, as a convenience method to avoid having to do an array cast.
* @return An array of all teaching assistant members of this team.
*/
public TeachingAssistant[] getTeachingAssistants() {
return Arrays.copyOf(this.getMembers(), this.memberCount(), TeachingAssistant[].class);
}
public String getName() {
return this.name;
}

View File

@ -1,6 +1,7 @@
package nl.andrewlalis.ui.view;
import nl.andrewlalis.git_api.GithubManager;
import nl.andrewlalis.ui.view.list_models.TATeamListCellRenderer;
import nl.andrewlalis.ui.view.list_models.TATeamListModel;
import nl.andrewlalis.ui.view.list_models.TeachingAssistantListCellRenderer;
import nl.andrewlalis.ui.view.list_models.TeachingAssistantsListModel;
@ -18,6 +19,8 @@ import java.awt.*;
*/
public class DefineTaTeamsDialog extends JDialog {
private static final Dimension LIST_SIZE = new Dimension(200, -1);
/**
* The manager used to manipulate the organization.
*/
@ -63,6 +66,8 @@ public class DefineTaTeamsDialog extends JDialog {
ListModel model = new TATeamListModel(this.manager.getTeams());
JList teamsList = new JList(model);
teamsList.setCellRenderer(new TATeamListCellRenderer());
teamsList.setPreferredSize(LIST_SIZE);
teamsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JScrollPane teamsListScrollPane = new JScrollPane(teamsList);
@ -84,6 +89,7 @@ public class DefineTaTeamsDialog extends JDialog {
JList membersList = new JList();
membersList.setModel(model);
membersList.setCellRenderer(new TeachingAssistantListCellRenderer());
membersList.setPreferredSize(LIST_SIZE);
membersList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JScrollPane membersListScrollPane = new JScrollPane(membersList);

View File

@ -0,0 +1,33 @@
package nl.andrewlalis.ui.view.list_models;
import nl.andrewlalis.model.TATeam;
import nl.andrewlalis.model.TeachingAssistant;
import javax.swing.*;
import java.awt.*;
/**
* Determines how list cells are rendered for a list of TATeams. In this case, it shows the team name, and the tooltip
* text provides a list of members.
*/
public class TATeamListCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList<?> jList, Object o, int i, boolean b, boolean b1) {
super.getListCellRendererComponent(jList, o, i, b, b1);
if (o instanceof TATeam) {
TATeam team = (TATeam) o;
this.setText(team.getName());
StringBuilder sb = new StringBuilder();
TeachingAssistant[] teachingAssistants = team.getTeachingAssistants();
for (int j = 0; j < teachingAssistants.length; j++) {
sb.append(teachingAssistants[j].getGithubUsername());
if (j < teachingAssistants.length - 1) {
sb.append('\n');
}
}
this.setToolTipText(sb.toString());
}
return this;
}
}

View File

@ -5,6 +5,9 @@ import nl.andrewlalis.model.TeachingAssistant;
import javax.swing.*;
import java.awt.*;
/**
* Controls what is rendered in a single list cell when displaying a list of TeachingAssistants.
*/
public class TeachingAssistantListCellRenderer extends DefaultListCellRenderer {
@Override