Search in sources :

Example 6 with ListDataListener

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());
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) CleanupActionsListModel(org.jabref.gui.cleanup.CleanupActionsListModel) ListDataListener(javax.swing.event.ListDataListener) Test(org.junit.Test)

Example 7 with ListDataListener

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)));
}
Also used : ListDataListener(javax.swing.event.ListDataListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with ListDataListener

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();
}
Also used : JPanel(javax.swing.JPanel) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) ListDataListener(javax.swing.event.ListDataListener) Container(java.awt.Container) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) ListDataListener(javax.swing.event.ListDataListener) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 9 with ListDataListener

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);
}
Also used : DefaultListModel(javax.swing.DefaultListModel) ListDataListener(javax.swing.event.ListDataListener)

Example 10 with ListDataListener

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);
}
Also used : CleanupActionsListModel(org.jabref.gui.cleanup.CleanupActionsListModel) ListDataListener(javax.swing.event.ListDataListener) Test(org.junit.Test)

Aggregations

ListDataListener (javax.swing.event.ListDataListener)10 ListDataEvent (javax.swing.event.ListDataEvent)5 Test (org.junit.Test)5 CleanupActionsListModel (org.jabref.gui.cleanup.CleanupActionsListModel)4 BorderLayout (java.awt.BorderLayout)2 JButton (javax.swing.JButton)2 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 TIntArrayList (gnu.trove.TIntArrayList)1 Container (java.awt.Container)1 GridLayout (java.awt.GridLayout)1 ActionEvent (java.awt.event.ActionEvent)1 MouseEvent (java.awt.event.MouseEvent)1 MouseMotionAdapter (java.awt.event.MouseMotionAdapter)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 AbstractAction (javax.swing.AbstractAction)1 ActionMap (javax.swing.ActionMap)1 DefaultListModel (javax.swing.DefaultListModel)1