Search in sources :

Example 11 with ConditionalAction

use of jmri.ConditionalAction in project JMRI by JMRI.

the class DefaultConditionalActionTest method testBasicBeanOperations.

public void testBasicBeanOperations() {
    ConditionalAction ix1 = new DefaultConditionalAction(1, 2, "3", 4, "5");
    ConditionalAction ix2 = new DefaultConditionalAction(1, 2, "3", 4, "5");
    ConditionalAction ix3 = new DefaultConditionalAction(0, 2, "3", 4, "5");
    ConditionalAction ix4 = new DefaultConditionalAction(1, 0, "3", 4, "5");
    ConditionalAction ix5 = new DefaultConditionalAction(1, 2, "0", 4, "5");
    ConditionalAction ix6 = new DefaultConditionalAction(1, 2, "3", 0, "5");
    ConditionalAction ix7 = new DefaultConditionalAction(1, 2, "3", 4, "0");
    Assert.assertTrue(!ix1.equals(null));
    Assert.assertTrue(ix1.equals(ix1));
    Assert.assertTrue(ix1.equals(ix2));
    Assert.assertTrue(!ix1.equals(ix3));
    Assert.assertTrue(!ix1.equals(ix4));
    Assert.assertTrue(!ix1.equals(ix5));
    Assert.assertTrue(!ix1.equals(ix6));
    Assert.assertTrue(!ix1.equals(ix7));
    Assert.assertTrue(ix1.hashCode() == ix2.hashCode());
}
Also used : ConditionalAction(jmri.ConditionalAction)

Example 12 with ConditionalAction

use of jmri.ConditionalAction in project JMRI by JMRI.

the class LogixTableAction method swapActions.

/**
     * Respond to the First/Next (Delete) Button in the Edit Conditional window.
     *
     * @param row index of the row to put as next in line (instead of the one that was supposed to be next)
     */
void swapActions(int row) {
    ConditionalAction temp = _actionList.get(row);
    for (int i = row; i > _nextInOrder; i--) {
        _actionList.set(i, _actionList.get(i - 1));
    }
    _actionList.set(_nextInOrder, temp);
    _nextInOrder++;
    if (_nextInOrder >= _actionList.size()) {
        _inReorderMode = false;
    }
    //status.setText("");
    _actionTableModel.fireTableDataChanged();
}
Also used : ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction)

Example 13 with ConditionalAction

use of jmri.ConditionalAction in project JMRI by JMRI.

the class LogixTableAction method setFileLocation.

/**
     * Respond to the [...] button in the Edit Action window action section.
     * <p>
     * Ask user to select an audio or python script file on disk.
     *
     * @param e the event heard
     */
void setFileLocation(ActionEvent e) {
    ConditionalAction action = _actionList.get(_curActionRowNumber);
    JFileChooser currentChooser;
    int actionType = action.getType();
    if (actionType == Conditional.ACTION_PLAY_SOUND) {
        if (sndFileChooser == null) {
            sndFileChooser = new JFileChooser(System.getProperty("user.dir") + java.io.File.separator + "resources" + java.io.File.separator + "sounds");
            jmri.util.FileChooserFilter filt = new jmri.util.FileChooserFilter("wav sound files");
            filt.addExtension("wav");
            sndFileChooser.setFileFilter(filt);
        }
        currentChooser = sndFileChooser;
    } else if (actionType == Conditional.ACTION_RUN_SCRIPT) {
        if (scriptFileChooser == null) {
            scriptFileChooser = new JFileChooser(FileUtil.getScriptsPath());
            jmri.util.FileChooserFilter filt = new jmri.util.FileChooserFilter("Python script files");
            filt.addExtension("py");
            scriptFileChooser.setFileFilter(filt);
        }
        currentChooser = scriptFileChooser;
    } else {
        log.warn("Unexpected actionType[" + actionType + "] = " + DefaultConditionalAction.getActionTypeString(actionType));
        if (defaultFileChooser == null) {
            defaultFileChooser = new JFileChooser(FileUtil.getUserFilesPath());
            defaultFileChooser.setFileFilter(new jmri.util.NoArchiveFileFilter());
        }
        currentChooser = defaultFileChooser;
    }
    currentChooser.rescanCurrentDirectory();
    int retVal = currentChooser.showOpenDialog(null);
    // handle selection or cancel
    if (retVal == JFileChooser.APPROVE_OPTION) {
        // set selected file location in data string
        try {
            _longActionString.setText(FileUtil.getPortableFilename(currentChooser.getSelectedFile().getCanonicalPath()));
        } catch (java.io.IOException ex) {
            if (log.isDebugEnabled()) {
                log.error("exception setting file location: " + ex);
            }
            _longActionString.setText("");
        }
    }
}
Also used : ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) JFileChooser(javax.swing.JFileChooser) Audio(jmri.Audio)

Example 14 with ConditionalAction

use of jmri.ConditionalAction in project JMRI by JMRI.

the class LRouteTableAction method getAlignmentSensors.

// getControlsAndActions
/**
     * Extract the Alignment Sensors and their types.
     *
     * @param cSysName the conditional system name
     */
void getAlignmentSensors(String cSysName) {
    Conditional c = _conditionalManager.getBySystemName(cSysName);
    if (c != null) {
        AlignElement element = null;
        ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
        for (int k = 0; k < actionList.size(); k++) {
            ConditionalAction action = actionList.get(k);
            if (action.getType() != Conditional.ACTION_SET_SENSOR) {
                javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("AlignWarn1"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
            } else {
                String name = action.getDeviceName();
                String key = SENSOR_TYPE + name;
                element = _alignUserMap.get(key);
                if (element == null) {
                    // try in system name map
                    element = _alignMap.get(key);
                }
                if (element == null) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                } else if (!name.equals(action.getDeviceName())) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("AlignWarn2"), new Object[] { action.toString(), action.getDeviceName(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                } else {
                    element.setIncluded(true);
                }
            }
        }
        // the action elements are identified in getControlsAndActions().
        //  Just identify the type of sensing
        ArrayList<ConditionalVariable> varList = c.getCopyOfStateVariables();
        int atype = 0;
        for (int k = 0; k < varList.size(); k++) {
            ConditionalVariable variable = varList.get(k);
            int testState = variable.getType();
            int type;
            switch(testState) {
                case Conditional.TYPE_SENSOR_ACTIVE:
                case Conditional.TYPE_SENSOR_INACTIVE:
                    type = SENSOR_TYPE;
                    break;
                case Conditional.TYPE_TURNOUT_CLOSED:
                case Conditional.TYPE_TURNOUT_THROWN:
                    type = TURNOUT_TYPE;
                    break;
                case Conditional.TYPE_LIGHT_ON:
                case Conditional.TYPE_LIGHT_OFF:
                    type = LIGHT_TYPE;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_LIT:
                case Conditional.TYPE_SIGNAL_HEAD_RED:
                case Conditional.TYPE_SIGNAL_HEAD_YELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_GREEN:
                case Conditional.TYPE_SIGNAL_HEAD_DARK:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHRED:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHYELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHGREEN:
                case Conditional.TYPE_SIGNAL_HEAD_HELD:
                    type = SIGNAL_TYPE;
                    break;
                default:
                    if (!LOGIX_INITIALIZER.equals(variable.getName())) {
                        javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarnVar"), new Object[] { variable.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                    }
                    continue;
            }
            if (k == 0) {
                atype = type;
            } else if (atype != type) {
                // more than one type. therefor, ALL
                atype = ALL_TYPE;
                break;
            }
        }
        if (element != null) {
            element.setState(atype);
        }
    }
}
Also used : ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Example 15 with ConditionalAction

use of jmri.ConditionalAction in project JMRI by JMRI.

the class LRouteTableAction method getControlsAndActions.

/**
     * Extract the Control (input) and Action (output) elements and their
     * states.
     *
     * @param cSysName the conditional system name
     */
void getControlsAndActions(String cSysName) {
    Conditional c = _conditionalManager.getBySystemName(cSysName);
    if (c != null) {
        ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
        boolean onChange = false;
        for (int k = 0; k < actionList.size(); k++) {
            ConditionalAction action = actionList.get(k);
            int type;
            switch(action.getType()) {
                case Conditional.ACTION_SET_SENSOR:
                    type = SENSOR_TYPE;
                    break;
                case Conditional.ACTION_SET_TURNOUT:
                    type = TURNOUT_TYPE;
                    break;
                case Conditional.ACTION_SET_LIGHT:
                    type = LIGHT_TYPE;
                    break;
                case Conditional.ACTION_SET_SIGNAL_APPEARANCE:
                case Conditional.ACTION_SET_SIGNAL_HELD:
                case Conditional.ACTION_CLEAR_SIGNAL_HELD:
                case Conditional.ACTION_SET_SIGNAL_DARK:
                case Conditional.ACTION_SET_SIGNAL_LIT:
                    type = SIGNAL_TYPE;
                    break;
                case Conditional.ACTION_RUN_SCRIPT:
                    scriptFile.setText(action.getActionString());
                    continue;
                case Conditional.ACTION_PLAY_SOUND:
                    soundFile.setText(action.getActionString());
                    continue;
                default:
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                    continue;
            }
            String name = action.getDeviceName();
            String key = type + name;
            RouteOutputElement elt = _outputUserMap.get(key);
            if (elt == null) {
                // try in system name map
                elt = _outputMap.get(key);
            }
            if (elt == null) {
                javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
            } else {
                elt.setIncluded(true);
                elt.setState(action.getActionData());
                boolean change = (action.getOption() == Conditional.ACTION_OPTION_ON_CHANGE);
                if (k == 0) {
                    onChange = change;
                } else if (change != onChange) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("OnChangeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                }
            }
        }
        ArrayList<ConditionalVariable> varList = c.getCopyOfStateVariables();
        for (int k = 0; k < varList.size(); k++) {
            ConditionalVariable variable = varList.get(k);
            int testState = variable.getType();
            //boolean negated = variable.isNegated();
            int type;
            switch(testState) {
                case Conditional.TYPE_SENSOR_ACTIVE:
                    type = SENSOR_TYPE;
                    //if (negated) testState = Conditional.TYPE_SENSOR_INACTIVE;
                    break;
                case Conditional.TYPE_SENSOR_INACTIVE:
                    type = SENSOR_TYPE;
                    //if (negated) testState = Conditional.TYPE_SENSOR_ACTIVE;
                    break;
                case Conditional.TYPE_TURNOUT_CLOSED:
                    type = TURNOUT_TYPE;
                    //if (negated) testState = Conditional.TYPE_TURNOUT_THROWN;
                    break;
                case Conditional.TYPE_TURNOUT_THROWN:
                    type = TURNOUT_TYPE;
                    //if (negated) testState = Conditional.TYPE_TURNOUT_CLOSED;
                    break;
                case Conditional.TYPE_LIGHT_ON:
                    type = LIGHT_TYPE;
                    //if (negated) testState = Conditional.TYPE_LIGHT_OFF;
                    break;
                case Conditional.TYPE_LIGHT_OFF:
                    type = LIGHT_TYPE;
                    //if (negated) testState = Conditional.TYPE_LIGHT_ON;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_LIT:
                case Conditional.TYPE_SIGNAL_HEAD_RED:
                case Conditional.TYPE_SIGNAL_HEAD_YELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_GREEN:
                case Conditional.TYPE_SIGNAL_HEAD_DARK:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHRED:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHYELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHGREEN:
                case Conditional.TYPE_SIGNAL_HEAD_HELD:
                    type = SIGNAL_TYPE;
                    break;
                default:
                    if (!LOGIX_INITIALIZER.equals(variable.getName())) {
                        javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarnVar"), new Object[] { variable.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                    }
                    continue;
            }
            int opern = variable.getOpern();
            if (k != 0 && (opern == Conditional.OPERATOR_AND || opern == Conditional.OPERATOR_AND_NOT)) {
                // guess this is a VETO
                testState += VETO;
            } else if (onChange) {
                testState = Route.ONCHANGE;
            }
            String name = variable.getName();
            String key = type + name;
            RouteInputElement elt = _inputUserMap.get(key);
            if (elt == null) {
                // try in system name map
                elt = _inputMap.get(key);
            }
            if (elt == null) {
                if (!LOGIX_INITIALIZER.equals(name)) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarnVar"), new Object[] { variable.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                }
            } else {
                elt.setIncluded(true);
                elt.setState(testState);
            }
        }
    }
}
Also used : ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Aggregations

ConditionalAction (jmri.ConditionalAction)19 DefaultConditionalAction (jmri.implementation.DefaultConditionalAction)14 Conditional (jmri.Conditional)10 ConditionalVariable (jmri.ConditionalVariable)10 ArrayList (java.util.ArrayList)8 Logix (jmri.Logix)7 ConditionalManager (jmri.ConditionalManager)3 Sensor (jmri.Sensor)3 Audio (jmri.Audio)2 JmriException (jmri.JmriException)2 DefaultConditional (jmri.implementation.DefaultConditional)2 DefaultConditionalManager (jmri.managers.DefaultConditionalManager)2 Element (org.jdom2.Element)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 File (java.io.File)1 Date (java.util.Date)1 ScriptException (javax.script.ScriptException)1 DefaultListModel (javax.swing.DefaultListModel)1 JFileChooser (javax.swing.JFileChooser)1 Timer (javax.swing.Timer)1