private void initComponents() { groupsList = new JList(); add(groupsList); slider = new MultiListSlider(); add(slider); groupsList.setCellRenderer(new MultiListCellRenderer()); updateList(); slider.setMultiListSlidable(this); setPreferredSize( new Dimension( LABEL_SPACE + groupsList.getPreferredSize().width + slider.getWidth(), groupsList.getPreferredSize().height)); setSize(getPreferredSize()); updateLocations(); }
/** Fusionne deux groupes. */ protected void mergeGroups(final int groupIdx1, final int groupIdx2) { // Récupération et suppression du groupe 2. final CompetitorGroup group2 = competitorGroups.remove(groupIdx2); final CompetitorGroup group1 = competitorGroups.get(groupIdx1); // Fusion des deux groupes. group1.getCompetitors().addAll(group2.getCompetitors()); slider.setMultiListSlidable(this); repaint(); }
/** Divise un groupe. */ protected void divideGroup(final int groupIdx) { // Récupération et suppression du groupe 2. final CompetitorGroup group = competitorGroups.remove(groupIdx); final CompetitorList list1 = new CompetitorList(); final CompetitorList list2 = new CompetitorList(); // Répartition dans les deux groupes. final int middle = group.getCompetitors().size() / 2; for (int i = 0; i < middle; i++) { list1.add(group.getCompetitors().get(i)); } for (int i = middle; i < group.getCompetitors().size(); i++) { list2.add(group.getCompetitors().get(i)); } competitorGroups.add(groupIdx, new CompetitorGroup(list2, new Algorithme())); competitorGroups.add(groupIdx, new CompetitorGroup(list1, new Algorithme())); slider.setMultiListSlidable(this); repaint(); }
private void updateLocations() { groupsList.setBounds( LABEL_SPACE, 0, groupsList.getPreferredSize().width, groupsList.getPreferredSize().height); slider.setBounds(LABEL_SPACE + groupsList.getWidth(), 0, slider.getWidth(), slider.getHeight()); }
@Override public Dimension getPreferredScrollableViewportSize() { final Dimension dim = groupsList.getPreferredScrollableViewportSize(); return new Dimension( (int) (LABEL_SPACE + dim.getWidth() + slider.getWidth()), (int) dim.getHeight()); }