use of jmri.Logix in project JMRI by JMRI.
the class LogixTableAction method checkFlags.
/**
* Check if another Logix editing session is currently open
* or no system name is provided.
*
* @param sName system name of Logix to be copied
* @return true if a new session may be started
*/
boolean checkFlags(String sName) {
if (inEditMode) {
// Already editing a Logix, ask for completion of that edit
javax.swing.JOptionPane.showMessageDialog(editLogixFrame, java.text.MessageFormat.format(rbx.getString("Error32"), new Object[] { _curLogix.getSystemName() }), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
return false;
}
if (inCopyMode) {
// Already editing a Logix, ask for completion of that edit
javax.swing.JOptionPane.showMessageDialog(editLogixFrame, java.text.MessageFormat.format(rbx.getString("Error31"), new Object[] { _logixSysName }), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
return false;
}
if (sName != null) {
// check if a Logix with this name exists
Logix x = _logixManager.getBySystemName(sName);
if (x == null) {
// Logix does not exist, so cannot be edited
log.error("No Logix with system name: " + sName);
javax.swing.JOptionPane.showMessageDialog(editLogixFrame, rbx.getString("Error5"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
if (editLogixFrame != null) {
editLogixFrame.setVisible(false);
}
return false;
}
}
return true;
}
use of jmri.Logix in project JMRI by JMRI.
the class LogixTableAction method loadSelectLogixBox.
/**
* Load the Logix selection box. Set the selection to the current Logix
* @since 4.7.4
*/
void loadSelectLogixBox() {
// Get the current Logix name for selecting the current combo box row
String cdlName = _curVariable.getName();
String lgxName;
if (cdlName.length() == 0 || (_curVariable.getType() != Conditional.TYPE_CONDITIONAL_TRUE && _curVariable.getType() != Conditional.TYPE_CONDITIONAL_FALSE)) {
// Use the current logix name for "add" state variable
lgxName = _curLogix.getSystemName();
} else {
Logix x = _conditionalManager.getParentLogix(cdlName);
if (x == null) {
log.error("Unable to find the Logix for {}, using the current Logix", cdlName);
lgxName = _curLogix.getSystemName();
} else {
lgxName = x.getSystemName();
}
}
_selectLogixBox.removeAllItems();
_selectLogixList.clear();
String itemKey = "";
for (String xName : _logixManager.getSystemNameList()) {
if (xName.equals("SYS")) {
// Cannot refer to sensor name groups
continue;
}
Logix x = _logixManager.getLogix(xName);
String uName = x.getUserName();
String itemName = "";
if (uName == null || uName.length() < 1) {
itemName = xName;
} else {
itemName = uName + " ( " + xName + " )";
}
_selectLogixBox.addItem(itemName);
_selectLogixList.add(xName);
if (lgxName.equals(xName)) {
itemKey = itemName;
}
}
_selectLogixBox.setSelectedItem(itemKey);
loadSelectConditionalBox(lgxName);
}
use of jmri.Logix in project JMRI by JMRI.
the class SensorGroupFrame method viewPressed.
void viewPressed() {
for (int i = 0; i < _sensorModel.getRowCount(); i++) {
_sensorModel.setValueAt(Boolean.FALSE, i, BeanTableModel.INCLUDE_COLUMN);
}
// look for name in List panel
String group = _sensorGroupList.getSelectedValue();
if (group == null) {
// not there, look in text field
group = _nameField.getText().toUpperCase().trim();
}
_nameField.setText(group);
// Look for Sensor group in Route table
RouteManager rm = InstanceManager.getDefault(jmri.RouteManager.class);
List<String> l = rm.getSystemNameList();
String prefix = (namePrefix + group + nameDivider).toUpperCase();
boolean isRoute = false;
int setRow = 0;
for (int i = 0; i < l.size(); i++) {
String name = l.get(i);
if (name.startsWith(prefix)) {
isRoute = true;
String sensor = name.substring(prefix.length());
// find and check that sensor
for (int j = _sensorModel.getRowCount() - 1; j >= 0; j--) {
if (_sensorModel.getValueAt(j, BeanTableModel.SNAME_COLUMN).equals(sensor)) {
_sensorModel.setValueAt(Boolean.TRUE, j, BeanTableModel.INCLUDE_COLUMN);
setRow = j;
}
}
}
}
// look for Sensor group in SYSTEM Logix
if (!isRoute) {
Logix logix = getSystemLogix();
String cSystemName = (ConditionalSystemPrefix + group).toUpperCase();
String cUserName = ConditionalUserPrefix + group;
for (int i = 0; i < logix.getNumConditionals(); i++) {
String name = logix.getConditionalByNumberOrder(i);
if (cSystemName.equals(name) || cUserName.equals(name)) {
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(name);
if (c == null) {
log.error("Conditional \"" + name + "\" expected but NOT found in Logix " + logix.getSystemName());
} else {
ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
for (int k = 0; k < variableList.size(); k++) {
String sensor = variableList.get(k).getName();
for (int j = _sensorModel.getRowCount() - 1; j >= 0; j--) {
if (_sensorModel.getValueAt(j, BeanTableModel.SNAME_COLUMN).equals(sensor)) {
_sensorModel.setValueAt(Boolean.TRUE, j, BeanTableModel.INCLUDE_COLUMN);
setRow = j;
}
}
}
}
}
}
}
_sensorModel.fireTableDataChanged();
setRow -= 9;
if (setRow < 0) {
setRow = 0;
}
_sensorScrollPane.getVerticalScrollBar().setValue(setRow * rowHeight);
}
use of jmri.Logix 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 jmri.Logix in project JMRI by JMRI.
the class OsIndicator method instantiate.
/**
* Create the underlying objects that implement this
*/
public void instantiate() {
// find/create Logix
String nameP = namePrefix + output;
Logix l = InstanceManager.getDefault(jmri.LogixManager.class).getLogix(nameP);
if (l == null) {
l = InstanceManager.getDefault(jmri.LogixManager.class).createNewLogix(nameP, "");
}
l.deActivateLogix();
// Find/create conditional and add
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getConditional(l, nameP + "C1");
if (c == null) {
c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(nameP + "C1", "");
l.addConditional(nameP + "C1", -1);
}
// Load variable into the Conditional
ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_NONE, Conditional.TYPE_SENSOR_INACTIVE, osSensor, true));
if (!lock.equals("")) {
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_AND, Conditional.TYPE_SENSOR_INACTIVE, lock, true));
}
c.setStateVariables(variableList);
ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_TURNOUT, output, Turnout.CLOSED, " "));
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_FALSE, Conditional.ACTION_SET_TURNOUT, output, Turnout.THROWN, " "));
// string data
c.setAction(actionList);
// and put it back in operation
l.activateLogix();
}
Aggregations