Search in sources :

Example 36 with Conditional

use of jmri.Conditional in project JMRI by JMRI.

the class RouteTableAction method makeTurnoutConditional.

/**
     * Create a new turnout conditional.
     *
     * @param jmriBox    control, the selection from which, will be used to
     *                   determine which sensor to make a conditional for
     * @param box        control, the selection from which, will be used to
     *                   determine the mode for the conditional
     * @param numConds   number of existing route conditionals
     * @param onChange   ???
     * @param actionList actions to take in conditional
     * @param vetoList   conditionals that can veto an action
     * @param logix      Logix to add the conditional to
     * @param prefix     system prefix for conditional
     * @param uName      user name for conditional
     * @return number of conditionals after the creation
     * @throws IllegalArgumentException if "user input no good"
     */
// why are the controls being passed, and not their selections?
int makeTurnoutConditional(JmriBeanComboBox jmriBox, JComboBox<String> box, int numConds, boolean onChange, ArrayList<ConditionalAction> actionList, ArrayList<ConditionalVariable> vetoList, Logix logix, String prefix, String uName) {
    ConditionalVariable cVar = makeCtrlTurnoutVar(jmriBox, box, false, onChange);
    if (cVar != null) {
        ArrayList<ConditionalVariable> varList = new ArrayList<>();
        varList.add(cVar);
        for (int i = 0; i < vetoList.size(); i++) {
            varList.add(cloneVariable(vetoList.get(i)));
        }
        String cSystemName = prefix + numConds + "T";
        String cUserName = jmriBox.getSelectedDisplayName() + numConds + "C " + uName;
        Conditional c = null;
        try {
            c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(cSystemName, cUserName);
        } catch (Exception ex) {
            // user input no good
            handleCreateException(cSystemName);
            // throw without creating any 
            throw new IllegalArgumentException("user input no good");
        }
        c.setStateVariables(varList);
        int option = onChange ? Conditional.ACTION_OPTION_ON_CHANGE : Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE;
        c.setAction(cloneActionList(actionList, option));
        c.setLogicType(Conditional.ALL_AND, "");
        logix.addConditional(cSystemName, 0);
        c.calculate(true, null);
        numConds++;
    }
    return numConds;
}
Also used : ArrayList(java.util.ArrayList) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Example 37 with Conditional

use of jmri.Conditional in project JMRI by JMRI.

the class Maintenance method getTypeAndNames.

/**
     * Find type of element and its names from a name that may be a user name or
     * a system name. (Maybe this can be done at a generic manager level, but
     * there seem to be two kinds of implementation of Managers and I don't know
     * which is the preferred kind or why they need to be different.)
     * <p>
     * Searches each Manager for a reference to the "name".
     *
     * @param name string (name base) to look for
     * @return 4 element String: {Type, userName, sysName, numListeners}
     */
static String[] getTypeAndNames(String name) {
    // N11N
    String userName = name.trim();
    String sysName = userName;
    // String sysName = userName.toUpperCase();
    boolean found = false;
    if (log.isDebugEnabled()) {
        log.debug("getTypeAndNames for \"" + name + "\"");
    }
    jmri.SensorManager sensorManager = InstanceManager.sensorManagerInstance();
    Sensor sen = sensorManager.getBySystemName(sysName);
    if (sen != null) {
        userName = sen.getUserName();
        found = true;
    } else {
        sen = sensorManager.getBySystemName(userName.toUpperCase());
        if (sen != null) {
            sysName = sen.getSystemName();
            userName = sen.getUserName();
            found = true;
        } else {
            sen = sensorManager.getByUserName(userName);
            if (sen != null) {
                sysName = sen.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Sensor", userName, sysName, // NOI18N
        Integer.toString(sen.getNumPropertyChangeListeners()) });
    }
    jmri.TurnoutManager turnoutManager = InstanceManager.turnoutManagerInstance();
    Turnout t = turnoutManager.getBySystemName(sysName);
    if (t != null) {
        userName = t.getUserName();
        found = true;
    } else {
        t = turnoutManager.getBySystemName(userName.toUpperCase());
        if (t != null) {
            sysName = t.getSystemName();
            userName = t.getUserName();
            found = true;
        } else {
            t = turnoutManager.getByUserName(userName);
            if (t != null) {
                sysName = t.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Turnout", userName, sysName, // NOI18N
        Integer.toString(t.getNumPropertyChangeListeners()) });
    }
    jmri.LightManager lightManager = InstanceManager.lightManagerInstance();
    Light l = lightManager.getBySystemName(sysName);
    if (l != null) {
        userName = l.getUserName();
        found = true;
    } else {
        l = lightManager.getBySystemName(userName.toUpperCase());
        if (l != null) {
            sysName = l.getSystemName();
            userName = l.getUserName();
            found = true;
        } else {
            l = lightManager.getByUserName(userName);
            if (l != null) {
                sysName = l.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Light", userName, sysName, // NOI18N
        Integer.toString(l.getNumPropertyChangeListeners()) });
    }
    jmri.SignalHeadManager signalManager = InstanceManager.getDefault(jmri.SignalHeadManager.class);
    SignalHead sh = signalManager.getBySystemName(sysName);
    if (sh != null) {
        userName = sh.getUserName();
        found = true;
    } else {
        sh = signalManager.getBySystemName(userName.toUpperCase());
        if (sh != null) {
            sysName = sh.getSystemName();
            userName = sh.getUserName();
            found = true;
        } else {
            sh = signalManager.getByUserName(userName);
            if (sh != null) {
                sysName = sh.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "SignalHead", userName, sysName, // NOI18N
        Integer.toString(sh.getNumPropertyChangeListeners()) });
    }
    jmri.ConditionalManager cm = InstanceManager.getDefault(jmri.ConditionalManager.class);
    Conditional c = cm.getBySystemName(sysName);
    if (c != null) {
        userName = c.getUserName();
        found = true;
    } else {
        c = cm.getBySystemName(userName.toUpperCase());
        if (c != null) {
            sysName = c.getSystemName();
            userName = c.getUserName();
            found = true;
        } else {
            c = cm.getByUserName(userName);
            if (c != null) {
                sysName = c.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Conditional", userName, sysName, // NOI18N
        Integer.toString(c.getNumPropertyChangeListeners()) });
    }
    jmri.BlockManager blockManager = InstanceManager.getDefault(jmri.BlockManager.class);
    jmri.Block b = blockManager.getBySystemName(sysName);
    if (b != null) {
        userName = b.getUserName();
        found = true;
    } else {
        b = blockManager.getBySystemName(userName.toUpperCase());
        if (b != null) {
            sysName = b.getSystemName();
            userName = b.getUserName();
            found = true;
        } else {
            b = blockManager.getByUserName(userName);
            if (b != null) {
                sysName = b.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Block", userName, sysName, // NOI18N
        Integer.toString(b.getNumPropertyChangeListeners()) });
    }
    jmri.SectionManager sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
    jmri.Section sec = sectionManager.getBySystemName(sysName);
    if (sec != null) {
        userName = sec.getUserName();
        found = true;
    } else {
        sec = sectionManager.getBySystemName(userName.toUpperCase());
        if (sec != null) {
            sysName = sec.getSystemName();
            userName = sec.getUserName();
            found = true;
        } else {
            sec = sectionManager.getByUserName(userName);
            if (sec != null) {
                sysName = sec.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "Block", userName, sysName, // NOI18N
        Integer.toString(sec.getNumPropertyChangeListeners()) });
    }
    log.warn(" No type found for " + userName + " (" + sysName + ").");
    jmri.jmrit.logix.OBlockManager oBlockManager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    jmri.jmrit.logix.OBlock blk = oBlockManager.getBySystemName(sysName);
    if (sec != null) {
        userName = blk.getUserName();
        found = true;
    } else {
        blk = oBlockManager.getBySystemName(userName.toUpperCase());
        if (blk != null) {
            sysName = blk.getSystemName();
            userName = blk.getUserName();
            found = true;
        } else {
            blk = oBlockManager.getByUserName(userName);
            if (blk != null) {
                sysName = blk.getSystemName();
                found = true;
            }
        }
    }
    if (found) {
        return (new String[] { "OBlock", userName, sysName, // NOI18N
        Integer.toString(blk.getNumPropertyChangeListeners()) });
    }
    log.warn(" No type found for " + userName + " (" + sysName + ").");
    return (new String[] { "", userName, sysName, "0" });
}
Also used : SignalHead(jmri.SignalHead) Conditional(jmri.Conditional) Block(jmri.Block) Light(jmri.Light) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 38 with Conditional

use of jmri.Conditional in project JMRI by JMRI.

the class DefaultConditionalManager method getByUserName.

/*
     * Conditional user names are NOT unique.
     * @param key The user name
     * @return the conditional or null when not found or a duplicate
     */
@Override
public Conditional getByUserName(String key) {
    if (key == null) {
        return null;
    }
    Conditional c = null;
    Conditional chkC = null;
    for (String cName : getSystemNameList()) {
        chkC = getBySystemName(cName);
        if (chkC == null) {
            continue;
        }
        if (key.equals(chkC.getUserName())) {
            if (c == null) {
                // Save first match
                c = getBySystemName(chkC.getSystemName());
                continue;
            }
            // Found a second match, give up
            log.warn("Duplicate conditional user names found, key = {}", key);
            return null;
        }
    }
    return c;
}
Also used : SensorGroupConditional(jmri.implementation.SensorGroupConditional) DefaultConditional(jmri.implementation.DefaultConditional) Conditional(jmri.Conditional)

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