Search in sources :

Example 21 with DefaultListModel

use of javax.swing.DefaultListModel in project beast-mcmc by beast-dev.

the class JListBinding method get.

public void get(IValidatable bean) {
    try {
        DefaultListModel model = (DefaultListModel) _list.getModel();
        final int size = model.getSize();
        List<Object> list = new ArrayList<Object>(size);
        for (int i = 0; i < size; i++) {
            list.add(model.get(i));
        }
        PropertyUtils.setProperty(bean, _property, list);
    } catch (Exception e) {
        throw new BindingException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel)

Example 22 with DefaultListModel

use of javax.swing.DefaultListModel in project cytoscape-api by cytoscape.

the class CheckBoxJListTest method testSetSelectedItems.

@Test
public void testSetSelectedItems() {
    final List<String> selected = new ArrayList<String>();
    DefaultListModel model = new DefaultListModel();
    final String[] listItemStrings = new String[] { "test1", "test2", "test3" };
    for (String item : listItemStrings) model.addElement(item);
    list.setModel(model);
    selected.add("test2");
    list.setSelectedItems(selected);
    Object[] selectedVals = list.getSelectedValues();
    assertEquals(1, selectedVals.length);
    selected.clear();
    for (String item : listItemStrings) selected.add(item);
    list.setSelectedItems(selected);
    selectedVals = list.getSelectedValues();
    assertEquals(3, selectedVals.length);
    selected.clear();
    selected.add("invalid");
    list.setSelectedItems(selected);
    selectedVals = list.getSelectedValues();
    assertEquals(0, selectedVals.length);
}
Also used : ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel) Test(org.junit.Test)

Example 23 with DefaultListModel

use of javax.swing.DefaultListModel in project cytoscape-api by cytoscape.

the class CheckBoxJListTest method testValueChanged.

@Test
public void testValueChanged() {
    final List<String> selected = new ArrayList<String>();
    DefaultListModel model = new DefaultListModel();
    final String[] listItemStrings = new String[] { "test1", "test2", "test3" };
    for (String item : listItemStrings) model.addElement(item);
    list.setModel(model);
    for (String item : listItemStrings) selected.add(item);
    list.setSelectedItems(selected);
    ListSelectionEvent lse = mock(ListSelectionEvent.class);
    when(lse.getValueIsAdjusting()).thenReturn(false);
    list.valueChanged(lse);
    verify(lse, times(1)).getValueIsAdjusting();
}
Also used : ArrayList(java.util.ArrayList) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DefaultListModel(javax.swing.DefaultListModel) Test(org.junit.Test)

Example 24 with DefaultListModel

use of javax.swing.DefaultListModel in project processdash by dtuma.

the class RolesEditor method createUI.

private Component createUI() {
    // create the roles button panel
    JPanel roleButtons = new JPanel(new GridLayout(2, 2, 5, 5));
    roleButtons.add(new JButton(new AddRoleAction()));
    roleButtons.add(new JButton(new CopyRoleAction()));
    roleButtons.add(new JButton(new RenameRoleAction()));
    roleButtons.add(new JButton(new DeleteRoleAction()));
    // create the permissions button panel
    JPanel permButtons = new JPanel(new GridLayout(1, 4, 5, 5));
    permButtons.add(new JButton(new AddPermissionAction()));
    permButtons.add(new JButton(new EditPermissionAction()));
    permButtons.add(new JButton(new DeletePermissionAction()));
    permButtons.add(new JButton(new RevertPermissionsAction()));
    // read the known roles, and add them to a list
    roles = new DefaultListModel();
    for (Role r : PermissionsManager.getInstance().getAllRoles()) roles.addElement(r);
    rolesList = new JList(roles);
    rolesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    rolesList.addListSelectionListener(new RoleSelectionHandler());
    JScrollPane rsp = new JScrollPane(rolesList);
    int prefHeight = Math.max(rolesList.getCellBounds(0, 0).height * 15 + 6, 200);
    rsp.setPreferredSize(new Dimension(200, prefHeight));
    // create an object for editing the permissions in the selected role
    permissionList = new PermissionList();
    permissionList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    permissionList.getSelectionModel().addListSelectionListener(new PermissionSelectionHandler());
    JScrollPane psp = new JScrollPane(permissionList);
    psp.setPreferredSize(new Dimension(450, prefHeight));
    // create titles to display on the dialog
    JLabel rolesTitle = new JLabel(resources.getString("Roles_Header"));
    JLabel permissionsTitle = new JLabel(resources.getString("Permissions_Header"));
    Font f = rolesTitle.getFont();
    f = f.deriveFont(f.getSize2D() * 1.5f);
    rolesTitle.setFont(f);
    permissionsTitle.setFont(f);
    Border b = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black);
    rolesTitle.setBorder(b);
    permissionsTitle.setBorder(b);
    // arrange the components onto a panel
    GridBagLayout layout = new GridBagLayout();
    userInterface = new JPanel(layout);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = c.gridy = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    layout.addLayoutComponent(rolesTitle, c);
    userInterface.add(rolesTitle);
    c.gridx = 2;
    Component comp = BoxUtils.hbox(new JOptionPaneTweaker.MakeResizable(), new JOptionPaneTweaker.DisableKeys());
    layout.addLayoutComponent(comp, c);
    userInterface.add(comp);
    c.gridx = 1;
    c.insets = new Insets(0, 10, 0, 0);
    layout.addLayoutComponent(permissionsTitle, c);
    userInterface.add(permissionsTitle);
    c.gridx = 0;
    c.gridy = 1;
    c.gridheight = 2;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(10, 20, 0, 0);
    if (editable) {
        layout.addLayoutComponent(roleButtons, c);
        userInterface.add(roleButtons);
    }
    c.gridy = 3;
    c.gridheight = 1;
    c.weightx = c.weighty = 1.0;
    layout.addLayoutComponent(rsp, c);
    userInterface.add(rsp);
    c.gridx = c.gridy = 1;
    c.weightx = c.weighty = 0;
    c.insets = new Insets(10, 30, 0, 0);
    if (editable) {
        layout.addLayoutComponent(permButtons, c);
        userInterface.add(permButtons);
    }
    c.gridy = 2;
    c.gridheight = 2;
    c.weightx = 3.0;
    c.weighty = 1.0;
    layout.addLayoutComponent(psp, c);
    userInterface.add(psp);
    // load the preferred size of the window
    try {
        String[] size = Settings.getVal(SIZE_PREF).split(",");
        Dimension d = new Dimension(Integer.parseInt(size[0]), Integer.parseInt(size[1]));
        userInterface.setPreferredSize(d);
    } catch (Exception e) {
    }
    return userInterface;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) Font(java.awt.Font) GridLayout(java.awt.GridLayout) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) JOptionPaneTweaker(net.sourceforge.processdash.ui.lib.JOptionPaneTweaker) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Role(net.sourceforge.processdash.tool.perm.Role) Border(javax.swing.border.Border) JList(javax.swing.JList)

Example 25 with DefaultListModel

use of javax.swing.DefaultListModel in project processdash by dtuma.

the class PreferencesFileList method createList.

@Override
protected void createList(String id, String currentValue) {
    listModel = new DefaultListModel();
    //  list.
    if (StringUtils.hasValue(currentValue)) {
        String[] paths = currentValue.split(separator);
        for (String path : paths) {
            listModel.addElement(path);
        }
    }
    fileList = new JList(listModel);
    fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    fileList.addListSelectionListener(this);
    JScrollPane listScroller = new JScrollPane(fileList);
    listScroller.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HEIGHT));
    this.add(listScroller, BorderLayout.CENTER);
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultListModel(javax.swing.DefaultListModel) Dimension(java.awt.Dimension) JList(javax.swing.JList)

Aggregations

DefaultListModel (javax.swing.DefaultListModel)41 JList (javax.swing.JList)21 ArrayList (java.util.ArrayList)16 JScrollPane (javax.swing.JScrollPane)13 List (java.util.List)8 JButton (javax.swing.JButton)8 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 JPanel (javax.swing.JPanel)5 Conditional (jmri.Conditional)5 Dimension (java.awt.Dimension)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 Insets (java.awt.Insets)4 Logix (jmri.Logix)4 Component (java.awt.Component)3 JLabel (javax.swing.JLabel)3 SensorGroupConditional (jmri.implementation.SensorGroupConditional)3 FormBuilder (com.jgoodies.forms.builder.FormBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2