Search in sources :

Example 26 with Conditional

use of jmri.Conditional 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 27 with Conditional

use of jmri.Conditional in project JMRI by JMRI.

the class LogixTableAction method checkConditionalUserName.

boolean checkConditionalUserName(String uName, Logix logix) {
    if ((uName != null) && (!(uName.equals("")))) {
        Conditional p = _conditionalManager.getByUserName(logix, uName);
        if (p != null) {
            // Conditional with this user name already exists
            log.error("Failure to update Conditional with Duplicate User Name: " + uName);
            javax.swing.JOptionPane.showMessageDialog(editConditionalFrame, rbx.getString("Error10"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }
    // else return false;
    return true;
}
Also used : Conditional(jmri.Conditional) DefaultConditional(jmri.implementation.DefaultConditional)

Example 28 with Conditional

use of jmri.Conditional 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);
}
Also used : Logix(jmri.Logix) Conditional(jmri.Conditional) SensorGroupConditional(jmri.implementation.SensorGroupConditional) ConditionalVariable(jmri.ConditionalVariable) RouteManager(jmri.RouteManager)

Example 29 with Conditional

use of jmri.Conditional 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 30 with Conditional

use of jmri.Conditional 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();
}
Also used : DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) Logix(jmri.Logix) ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Aggregations

Conditional (jmri.Conditional)38 ConditionalVariable (jmri.ConditionalVariable)16 Logix (jmri.Logix)15 ConditionalAction (jmri.ConditionalAction)10 DefaultConditional (jmri.implementation.DefaultConditional)10 ConditionalManager (jmri.ConditionalManager)8 DefaultConditionalAction (jmri.implementation.DefaultConditionalAction)8 ArrayList (java.util.ArrayList)7 SensorGroupConditional (jmri.implementation.SensorGroupConditional)6 DefaultListModel (javax.swing.DefaultListModel)5 Sensor (jmri.Sensor)5 Light (jmri.Light)4 SignalHead (jmri.SignalHead)4 Turnout (jmri.Turnout)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JButton (javax.swing.JButton)3 JScrollPane (javax.swing.JScrollPane)3 Block (jmri.Block)3 Memory (jmri.Memory)3