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"));
}
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());
}
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();
}
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);
}
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;
}
Aggregations