use of javax.swing.event.ListDataListener 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());
}
use of javax.swing.event.ListDataListener in project zaproxy by zaproxy.
the class UsersListModelUnitTest method shouldAddListDataListeners.
@Test
public void shouldAddListDataListeners() {
// Given
ListDataListener listener = createTestListDataListener();
UsersListModel usersListModel = new UsersListModel(createUsersTableModel(0));
// When
usersListModel.addListDataListener(listener);
// Then
assertThat(usersListModel.getListDataListeners(), is(arrayContaining(listener)));
}
use of javax.swing.event.ListDataListener in project jabref by JabRef.
the class EntryCustomizationDialog method initGui.
private void initGui() {
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
if (frame.getCurrentBasePanel() == null) {
bibDatabaseMode = Globals.prefs.getDefaultBibDatabaseMode();
} else {
bibDatabaseMode = frame.getCurrentBasePanel().getBibDatabaseContext().getMode();
}
biblatexMode = BibDatabaseMode.BIBLATEX.equals(bibDatabaseMode);
JPanel main = new JPanel();
JPanel buttons = new JPanel();
JPanel right = new JPanel();
main.setLayout(new BorderLayout());
right.setLayout(new GridLayout(biblatexMode ? 2 : 1, 2));
List<String> entryTypes = new ArrayList<>();
for (String s : EntryTypes.getAllTypes(bibDatabaseMode)) {
entryTypes.add(s);
}
typeComp = new EntryTypeList(entryTypes, bibDatabaseMode);
typeComp.addListSelectionListener(this);
typeComp.addAdditionActionListener(e -> typeComp.selectField(e.getActionCommand()));
typeComp.addDefaultActionListener(new DefaultListener());
typeComp.setListSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//typeComp.setEnabled(false);
reqComp = new FieldSetComponent(Localization.lang("Required fields"), new ArrayList<>(), preset, true, true);
reqComp.setEnabled(false);
reqComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
ListDataListener dataListener = new DataListener();
reqComp.addListDataListener(dataListener);
optComp = new FieldSetComponent(Localization.lang("Optional fields"), new ArrayList<>(), preset, true, true);
optComp.setEnabled(false);
optComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
optComp.addListDataListener(dataListener);
right.add(reqComp);
right.add(optComp);
if (biblatexMode) {
optComp2 = new FieldSetComponent(Localization.lang("Optional fields") + " 2", new ArrayList<>(), preset, true, true);
optComp2.setEnabled(false);
optComp2.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
optComp2.addListDataListener(dataListener);
right.add(new JPanel());
right.add(optComp2);
}
//right.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Globals.lang("Fields")));
right.setBorder(BorderFactory.createEtchedBorder());
ok = new JButton(Localization.lang("OK"));
cancel = new JButton(Localization.lang("Cancel"));
apply = new JButton(Localization.lang("Apply"));
ok.addActionListener(e -> {
applyChanges();
dispose();
});
apply.addActionListener(e -> applyChanges());
cancel.addActionListener(e -> dispose());
ButtonBarBuilder bb = new ButtonBarBuilder(buttons);
buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
bb.addGlue();
bb.addButton(ok);
bb.addButton(apply);
bb.addButton(cancel);
bb.addGlue();
AbstractAction closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
};
ActionMap am = main.getActionMap();
InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
am.put("close", closeAction);
//con.fill = GridBagConstraints.BOTH;
//con.weightx = 0.3;
//con.weighty = 1;
//gbl.setConstraints(typeComp, con);
main.add(typeComp, BorderLayout.WEST);
main.add(right, BorderLayout.CENTER);
main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
pane.add(main, BorderLayout.CENTER);
pane.add(buttons, BorderLayout.SOUTH);
pack();
}
use of javax.swing.event.ListDataListener in project jabref by JabRef.
the class FieldSetComponent method setFields.
public void setFields(List<String> fields) {
DefaultListModel<String> newListModel = new DefaultListModel<>();
for (String field : fields) {
newListModel.addElement(field);
}
this.listModel = newListModel;
for (ListDataListener modelListener : modelListeners) {
newListModel.addListDataListener(modelListener);
}
list.setModel(newListModel);
}
use of javax.swing.event.ListDataListener in project jabref by JabRef.
the class CleanupActionsListModelTest method removedAtIndexgreaterListSizeDoesNothing.
@Test
public void removedAtIndexgreaterListSizeDoesNothing() {
CleanupActionsListModel model = new CleanupActionsListModel(getDefaultFieldFormatterCleanups());
ListDataListener listener = mock(ListDataListener.class);
model.addListDataListener(listener);
model.removeAtIndex((getDefaultFieldFormatterCleanups().size() + 1));
verifyZeroInteractions(listener);
}
Aggregations