Search in sources :

Example 31 with DefaultListModel

use of javax.swing.DefaultListModel in project JMRI by JMRI.

the class Maintenance method findEmptyPressed.

/**
     * Find useless Conditionals in the various Manager Objects.
     *
     * @param parent Frame to check
     */
public static void findEmptyPressed(Frame parent) {
    Vector<String> display = new Vector<String>();
    Vector<String> names = new Vector<String>();
    log.debug("findEmptyPressed");
    Iterator<String> iter = InstanceManager.getDefault(jmri.ConditionalManager.class).getSystemNameList().iterator();
    jmri.ConditionalManager cm = InstanceManager.getDefault(jmri.ConditionalManager.class);
    while (iter.hasNext()) {
        String name = iter.next();
        Conditional c = cm.getBySystemName(name);
        if (c != null) {
            ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
            if (variableList.size() == 0) {
                String userName = c.getUserName();
                display.add(MessageFormat.format(rbm.getString("OrphanName"), new Object[] { "Conditional", userName, name }));
                names.add(name);
            }
        }
    }
    DefaultListModel<String> listModel = new DefaultListModel<String>();
    for (int i = 0; i < display.size(); i++) {
        listModel.addElement(display.get(i));
    }
    JList<String> list = new JList<String>(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JButton button = new JButton(Bundle.getMessage("ButtonDelete"));
    button.setToolTipText(rbm.getString("OrphanDeleteHint") + Bundle.getMessage("ButtonDelete"));
    class EmptyListener implements ActionListener {

        JList<String> list;

        Vector<String> name;

        EmptyListener(JList<String> list, Vector<String> name) {
            this.list = list;
            this.name = name;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            int index = list.getMaxSelectionIndex();
            if (index < 0) {
                javax.swing.JOptionPane.showMessageDialog(null, rbm.getString("OrphanDeleteHint"), rbm.getString("DeleteTitle"), javax.swing.JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            int min = list.getMinSelectionIndex();
            DefaultListModel<String> model = (DefaultListModel<String>) list.getModel();
            while (index >= min) {
                String[] names = getTypeAndNames(name.get(index));
                model.remove(index);
                Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(names[2]);
                if (c != null) {
                    Logix x = InstanceManager.getDefault(jmri.ConditionalManager.class).getParentLogix(names[2]);
                    if (x != null) {
                        x.deActivateLogix();
                        x.deleteConditional(names[2]);
                        x.activateLogix();
                    }
                    InstanceManager.getDefault(jmri.ConditionalManager.class).deregister(c);
                    name.remove(index);
                    index--;
                }
            }
            index++;
            if (index >= model.getSize()) {
                index = model.getSize() - 1;
            }
            if (index >= 0) {
                list.setSelectedIndex(index);
            }
        }
    }
    JScrollPane scrollPane = new JScrollPane(list);
    button.addActionListener(new EmptyListener(list, names));
    button.setMaximumSize(button.getPreferredSize());
    makeDialog(scrollPane, button, parent, rbm.getString("EmptyConditionalTitle"));
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable) Logix(jmri.Logix) ActionListener(java.awt.event.ActionListener) Vector(java.util.Vector) JList(javax.swing.JList)

Example 32 with DefaultListModel

use of javax.swing.DefaultListModel in project JMRI by JMRI.

the class MemoryComboIcon method edit.

@Override
protected void edit() {
    _iconEditor = new IconAdder("Memory") {

        JList<String> list;

        JButton bDel = new JButton(Bundle.getMessage("deleteSelection"));

        JButton bAdd = new JButton(Bundle.getMessage("addItem"));

        JTextField textfield = new JTextField(30);

        @Override
        protected void addAdditionalButtons(JPanel p) {
            _listModel = new DefaultListModel<String>();
            bDel.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent a) {
                    int idx = list.getSelectedIndex();
                    if (idx >= 0) {
                        _listModel.removeElementAt(idx);
                    }
                }
            });
            bAdd.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent a) {
                    String text = textfield.getText();
                    if (text == null || text.length() == 0 || _listModel.indexOf(text) >= 0) {
                        return;
                    }
                    int idx = list.getSelectedIndex();
                    if (idx < 0) {
                        idx = _listModel.getSize();
                    }
                    _listModel.add(idx, text);
                }
            });
            for (int i = 0; i < _model.getSize(); i++) {
                _listModel.add(i, _model.getElementAt(i));
            }
            list = new JList<String>(_listModel);
            JScrollPane scrollPane = new JScrollPane(list);
            JPanel p1 = new JPanel();
            p1.add(new JLabel(Bundle.getMessage("comboList")));
            p.add(p1);
            p.add(scrollPane);
            p1 = new JPanel();
            p1.add(new JLabel(Bundle.getMessage("newItem"), SwingConstants.RIGHT));
            textfield.setMaximumSize(textfield.getPreferredSize());
            p1.add(textfield);
            p.add(p1);
            JPanel p2 = new JPanel();
            //p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
            //p2.setLayout(new FlowLayout(FlowLayout.TRAILING));
            p2.add(bDel);
            p2.add(bAdd);
            p.add(p2);
            p.setVisible(true);
        }
    };
    makeIconEditorFrame(this, "Memory", true, _iconEditor);
    _iconEditor.setPickList(jmri.jmrit.picker.PickListModel.memoryPickModelInstance());
    ActionListener addIconAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            editMemory();
        }
    };
    _iconEditor.makeIconPanel(false);
    _iconEditor.complete(addIconAction, false, true, true);
    _iconEditor.setSelection(getMemory());
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ActionListener(java.awt.event.ActionListener) JList(javax.swing.JList)

Example 33 with DefaultListModel

use of javax.swing.DefaultListModel in project JMRI by JMRI.

the class SensorGroupFrame method initComponents.

@Override
public void initComponents() {
    addHelpMenu("package.jmri.jmrit.sensorgroup.SensorGroupFrame", true);
    setTitle("Define Sensor Group");
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    // add the sensor table
    JPanel p2xs = new JPanel();
    JPanel p21s = new JPanel();
    p21s.setLayout(new BoxLayout(p21s, BoxLayout.Y_AXIS));
    p21s.add(new JLabel("Please select"));
    p21s.add(new JLabel("Sensors to "));
    p21s.add(new JLabel("be included "));
    p21s.add(new JLabel("in this group."));
    p2xs.add(p21s);
    _sensorModel = new SensorTableModel();
    JTable sensorTable = new JTable(_sensorModel);
    /*
         JTable sensorTable = jmri.util.JTableUtil.sortableDataModel(sensorModel);
         try {
         jmri.util.com.sun.TableSorter tmodel = ((jmri.util.com.sun.TableSorter)sensorTable.getModel());
         tmodel.setColumnComparator(String.class, new jmri.util.SystemNameComparator());
         tmodel.setSortingStatus(SensorTableModel.SNAME_COLUMN, jmri.util.com.sun.TableSorter.ASCENDING);
         } catch (ClassCastException e3) {}  // if not a sortable table model
         */
    sensorTable.setRowSelectionAllowed(false);
    sensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(450, 200));
    TableColumnModel sensorColumnModel = sensorTable.getColumnModel();
    TableColumn includeColumnS = sensorColumnModel.getColumn(SensorTableModel.INCLUDE_COLUMN);
    includeColumnS.setResizable(false);
    includeColumnS.setMinWidth(50);
    includeColumnS.setMaxWidth(60);
    TableColumn sNameColumnS = sensorColumnModel.getColumn(SensorTableModel.SNAME_COLUMN);
    sNameColumnS.setResizable(true);
    sNameColumnS.setMinWidth(75);
    sNameColumnS.setPreferredWidth(95);
    TableColumn uNameColumnS = sensorColumnModel.getColumn(SensorTableModel.UNAME_COLUMN);
    uNameColumnS.setResizable(true);
    uNameColumnS.setMinWidth(210);
    uNameColumnS.setPreferredWidth(260);
    rowHeight = sensorTable.getRowHeight();
    _sensorScrollPane = new JScrollPane(sensorTable);
    p2xs.add(_sensorScrollPane, BorderLayout.CENTER);
    getContentPane().add(p2xs);
    p2xs.setVisible(true);
    // add name field
    JPanel p3 = new JPanel();
    p3.add(new JLabel("Group Name:"));
    _nameField = new JTextField(20);
    p3.add(_nameField);
    getContentPane().add(p3);
    // button
    JPanel p4 = new JPanel();
    JButton viewButton = new JButton(" View ");
    viewButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewPressed();
        }
    });
    p4.add(viewButton);
    JButton addButton = new JButton("Make Group");
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addPressed();
        }
    });
    p4.add(addButton);
    JButton undoButton = new JButton("Undo Group");
    undoButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            undoGroupPressed();
        }
    });
    p4.add(undoButton);
    getContentPane().add(p4);
    JPanel p5 = new JPanel();
    DefaultListModel<String> groupModel = new DefaultListModel<String>();
    // Look for Sensor group in Route table
    RouteManager rm = InstanceManager.getDefault(jmri.RouteManager.class);
    List<String> routeList = rm.getSystemNameList();
    int i = 0;
    while (i < routeList.size()) {
        String name = routeList.get(i);
        if (name.startsWith(namePrefix)) {
            name = name.substring(namePrefix.length());
            String group = name.substring(0, name.indexOf(nameDivider));
            String prefix = namePrefix + group + nameDivider;
            do {
                i++;
                if (i >= routeList.size()) {
                    break;
                }
                name = routeList.get(i);
            } while (name.startsWith(prefix));
            groupModel.addElement(group);
        }
        i++;
    }
    // Look for Sensor group in Logix
    Logix logix = getSystemLogix();
    for (i = 0; i < logix.getNumConditionals(); i++) {
        String name = logix.getConditionalByNumberOrder(i);
        Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(name);
        String uname = c.getUserName();
        if (uname != null) {
            groupModel.addElement(uname.substring(ConditionalUserPrefix.length()));
        }
    }
    _sensorGroupList = new JList<String>(groupModel);
    _sensorGroupList.setPrototypeCellValue(ConditionalUserPrefix + "XXXXXXXXXX");
    _sensorGroupList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _sensorGroupList.setVisibleRowCount(5);
    JScrollPane scrollPane = new JScrollPane(_sensorGroupList);
    p5.add(scrollPane);
    p5.add(Box.createHorizontalStrut(10));
    JButton doneButton = new JButton(" Done ");
    doneButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            donePressed(e);
        }
    });
    p5.add(doneButton);
    getContentPane().add(p5);
    // pack to cause display
    pack();
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) TableColumnModel(javax.swing.table.TableColumnModel) DefaultListModel(javax.swing.DefaultListModel) Conditional(jmri.Conditional) SensorGroupConditional(jmri.implementation.SensorGroupConditional) JTextField(javax.swing.JTextField) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) Logix(jmri.Logix) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) RouteManager(jmri.RouteManager)

Example 34 with DefaultListModel

use of javax.swing.DefaultListModel 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 35 with DefaultListModel

use of javax.swing.DefaultListModel in project pcgen by PCGen.

the class DescriptionInfoTab method createModels.

@Override
public ModelMap createModels(CharacterFacade character) {
    ModelMap models = new ModelMap();
    DefaultListModel listModel = new DefaultListModel();
    List<NoteInfoPane> notePaneList = new ArrayList<>();
    //$NON-NLS-1$
    PageItem firstPage = new PageItem(character, LanguageBundle.getString("in_descBiography"), bioPane);
    listModel.addElement(firstPage);
    //$NON-NLS-1$
    listModel.addElement(new PageItem(character, LanguageBundle.getString("in_portrait"), portraitPane));
    //$NON-NLS-1$
    listModel.addElement(new PageItem(character, LanguageBundle.getString("in_descCampHist"), histPane));
    models.put(ListModel.class, listModel);
    models.put(List.class, notePaneList);
    models.put(NoteListHandler.class, new NoteListHandler(character, listModel, notePaneList));
    ListSelectionModel model = new DefaultListSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    model.setSelectionInterval(0, 0);
    models.put(ListSelectionModel.class, model);
    models.put(PageHandler.class, new PageHandler(model, firstPage));
    models.put(AddAction.class, new AddAction(character));
    return models;
}
Also used : ArrayList(java.util.ArrayList) DefaultListModel(javax.swing.DefaultListModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) NoteInfoPane(pcgen.gui2.tabs.bio.NoteInfoPane)

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