use of javax.swing.event.ListDataEvent in project intellij-community by JetBrains.
the class SpecialAnnotationsUtil method createSpecialAnnotationsListControl.
public static JPanel createSpecialAnnotationsListControl(final List<String> list, final String borderTitle, final boolean acceptPatterns, final Condition<PsiClass> isApplicable) {
@SuppressWarnings("Convert2Diamond") SortedListModel<String> listModel = new SortedListModel<String>(Comparator.naturalOrder());
for (String s : list) {
listModel.add(s);
}
listModel.addListDataListener(new ListDataListener() {
@Override
public void intervalAdded(ListDataEvent e) {
listChanged();
}
private void listChanged() {
list.clear();
for (int i = 0; i < listModel.getSize(); i++) {
list.add((String) listModel.getElementAt(i));
}
}
@Override
public void intervalRemoved(ListDataEvent e) {
listChanged();
}
@Override
public void contentsChanged(ListDataEvent e) {
listChanged();
}
});
return createSpecialAnnotationsListControl(borderTitle, acceptPatterns, isApplicable, listModel);
}
use of javax.swing.event.ListDataEvent in project intellij-community by JetBrains.
the class SortedListModelTest method testRemoveViaIterator.
public void testRemoveViaIterator() {
myModel.setAll(new String[] { "1", "2", "3", "4" });
Iterator iterator = myModel.iterator();
final TIntArrayList removed = new TIntArrayList();
myModel.addListDataListener(new ListDataListener() {
@Override
public void contentsChanged(ListDataEvent e) {
throw new RuntimeException();
}
@Override
public void intervalAdded(ListDataEvent e) {
throw new RuntimeException();
}
@Override
public void intervalRemoved(ListDataEvent e) {
assertEquals(e.getIndex0(), e.getIndex1());
removed.add(e.getIndex0());
}
});
iterator.next();
iterator.remove();
assertEquals(1, removed.size());
assertEquals(0, removed.get(0));
while (iterator.hasNext()) iterator.next();
assertFalse(iterator.hasNext());
iterator.remove();
assertEquals(2, removed.size());
assertEquals(2, removed.get(1));
CHECK.compareAll(new String[] { "2", "3" }, myModel.getItems());
}
use of javax.swing.event.ListDataEvent in project jabref by JabRef.
the class FieldFormatterCleanupsPanel method buildLayout.
private void buildLayout(List<FieldFormatterCleanup> actionsToDisplay) {
FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 13dlu, left:pref:grow, 4dlu, pref, 4dlu, pref", "pref, 2dlu, pref, 2dlu, pref, 4dlu, pref, 2dlu, fill:pref:grow, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu"));
builder.add(cleanupEnabled).xyw(1, 1, 7);
actionsList = new JList<>(new CleanupActionsListModel(actionsToDisplay));
actionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
actionsList.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
CleanupActionsListModel m = (CleanupActionsListModel) actionsList.getModel();
int index = actionsList.locationToIndex(e.getPoint());
if (index > -1) {
actionsList.setToolTipText(m.getElementAt(index).getFormatter().getDescription());
}
}
});
actionsList.getModel().addListDataListener(new ListDataListener() {
@Override
public void intervalRemoved(ListDataEvent e) {
//index0 is sufficient, because of SingleSelection
if (e.getIndex0() == 0) {
//when an item gets deleted, the next one becomes the new 0
actionsList.setSelectedIndex(e.getIndex0());
}
if (e.getIndex0() > 0) {
actionsList.setSelectedIndex(e.getIndex0() - 1);
}
}
@Override
public void intervalAdded(ListDataEvent e) {
//empty, not needed
}
@Override
public void contentsChanged(ListDataEvent e) {
//empty, not needed
}
});
builder.add(actionsList).xyw(3, 5, 5);
resetButton = new JButton(Localization.lang("Reset"));
resetButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).reset(defaultFormatters));
BibDatabaseContext databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabaseContext();
recommendButton = new JButton(Localization.lang("Recommended for %0", databaseContext.getMode().getFormattedName()));
boolean isBiblatex = databaseContext.isBiblatexMode();
recommendButton.addActionListener(e -> {
if (isBiblatex) {
((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBLATEX_ACTIONS);
} else {
((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBTEX_ACTIONS);
}
});
removeButton = new JButton(Localization.lang("Remove selected"));
removeButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).removeAtIndex(actionsList.getSelectedIndex()));
builder.add(removeButton).xy(7, 11);
builder.add(resetButton).xy(3, 11);
builder.add(recommendButton).xy(5, 11);
builder.add(getSelectorPanel()).xyw(3, 15, 5);
makeDescriptionTextAreaLikeJLabel();
builder.add(descriptionAreaText).xyw(3, 17, 5);
this.setLayout(new BorderLayout());
this.add(builder.getPanel(), BorderLayout.WEST);
updateDescription();
// make sure the layout is set according to the checkbox
cleanupEnabled.addActionListener(new EnablementStatusListener(fieldFormatterCleanups.isEnabled()));
cleanupEnabled.setSelected(fieldFormatterCleanups.isEnabled());
}
use of javax.swing.event.ListDataEvent in project jabref by JabRef.
the class CleanupActionsListModelTest method resetFiresItemsChanged.
@Test
public void resetFiresItemsChanged() throws Exception {
CleanupActionsListModel model = new CleanupActionsListModel(Collections.emptyList());
ListDataListener listener = mock(ListDataListener.class);
model.addListDataListener(listener);
FieldFormatterCleanups defaultFormatters = mock(FieldFormatterCleanups.class);
model.reset(defaultFormatters);
ArgumentCaptor<ListDataEvent> argument = ArgumentCaptor.forClass(ListDataEvent.class);
verify(listener).contentsChanged(argument.capture());
assertEquals(ListDataEvent.CONTENTS_CHANGED, argument.getValue().getType());
}
use of javax.swing.event.ListDataEvent in project jabref by JabRef.
the class CleanupActionsListModelTest method removedAtIndexOkay.
@Test
public void removedAtIndexOkay() {
CleanupActionsListModel model = new CleanupActionsListModel(getDefaultFieldFormatterCleanups());
ListDataListener listener = mock(ListDataListener.class);
model.addListDataListener(listener);
model.removeAtIndex(0);
ArgumentCaptor<ListDataEvent> argument = ArgumentCaptor.forClass(ListDataEvent.class);
verify(listener).intervalRemoved(argument.capture());
assertEquals(ListDataEvent.INTERVAL_REMOVED, argument.getValue().getType());
}
Aggregations