Search in sources :

Example 1 with DynamicTransition

use of kutch.biff.marvin.widget.dynamicgrid.DynamicTransition in project Board-Instrumentation-Framework by intel.

the class DynamicImageWidget method HandleWidgetSpecificSettings.

@Override
public boolean HandleWidgetSpecificSettings(FrameworkNode node) {
    String Id = null;
    String FileName = null;
    if (node.getNodeName().equalsIgnoreCase("Initial")) {
        Utility.ValidateAttributes(new String[] { "ID" }, node);
        if (node.hasAttribute("ID")) {
            _CurrentKey = node.getAttribute("ID").toLowerCase();
            return true;
        } else {
            LOGGER.severe("Dynamic Image Widget incorrectly defined Initial Image, no ID.");
            return false;
        }
    }
    if (node.getNodeName().equalsIgnoreCase("AutoAdvance")) {
        /*        
             <AutoAdvance Frequency='1000' Loop='False'/>
             */
        if (node.hasAttribute("Frequency")) {
            _AutoAdvanceInterval = node.getIntegerAttribute("Frequency", -1);
            if (_AutoAdvanceInterval < 100) {
                LOGGER.severe("Frequency specified for DynamicImage is invalid: " + node.getAttribute("Frequency"));
                return false;
            }
            if (node.hasAttribute("Loop")) {
                _AutoLoopWithAdvance = node.getBooleanAttribute("Loop");
            }
            _AutoAdvance = true;
            return true;
        }
        return false;
    }
    if (node.getNodeName().equalsIgnoreCase("Image")) {
        Utility.ValidateAttributes(new String[] { "Source", "ID", "Monitor", "Task" }, node);
        if (node.hasAttribute("Source")) {
            FileName = node.getAttribute("Source");
        } else {
            LOGGER.severe("Dynamic Image Widget has no Source for Image");
            return false;
        }
        if (node.hasAttribute("ID")) {
            Id = node.getAttribute("ID");
            if (true == _ImageFilenames.containsKey(Id.toLowerCase())) {
                LOGGER.severe("Dynamic Image Widget has repeated Image ID: " + Id);
                return false;
            }
            Id = Id.toLowerCase();
        } else {
            LOGGER.severe("Dynamic Image Widget has no ID for Image");
            return false;
        }
        if (node.hasAttribute("Task")) {
            _TaskMap.put(Id, node.getAttribute("Task"));
        }
        String fname = convertToFileOSSpecific(FileName);
        if (null == fname) {
            return false;
        }
        File file = new File(fname);
        if (file.exists()) {
            String fn = "file:" + fname;
            // Image img = new Image(fn);
            _ImageFilenames.put(Id, fn);
            _ListID.add(Id);
            if (node.hasAttribute("Monitor")) {
                if (node.getBooleanAttribute("Monitor")) {
                    _MontorMap.put(Id, file.lastModified());
                }
            }
        } else {
            LOGGER.severe("Dynamic Image Widget - missing Image file: " + FileName);
            return false;
        }
        if (node.hasChild("Transition")) {
            DynamicTransition objTransition = DynamicTransition.ReadTransitionInformation(node);
            if (null != objTransition) {
                this._TransitionMap.put(Id, objTransition);
            }
        }
    }
    return true;
}
Also used : DynamicTransition(kutch.biff.marvin.widget.dynamicgrid.DynamicTransition) File(java.io.File)

Example 2 with DynamicTransition

use of kutch.biff.marvin.widget.dynamicgrid.DynamicTransition in project Board-Instrumentation-Framework by intel.

the class DynamicImageWidget method Create.

/**
 * @param pane
 * @param dataMgr
 * @return
 */
@Override
public boolean Create(GridPane pane, DataManager dataMgr) {
    SetParent(pane);
    if (setupImages()) {
        ConfigureAlignment();
        for (String key : this._ImageFilenames.keySet()) {
            ImageView obj = _ImageViewMap.get(key);
            basePane.add(obj, 0, 0);
        }
        pane.add(basePane, getColumn(), getRow(), getColumnSpan(), getRowSpan());
        SetupPeekaboo(dataMgr);
        if (_AutoAdvance) {
            if (null == getMinionID() || null == getNamespace()) {
                String ID = Integer.toBinaryString(DynamicImageWidget._AutoAdvanceImageNumber);
                DynamicImageWidget._AutoAdvanceImageNumber++;
                if (null == getMinionID()) {
                    setMinionID(ID);
                }
                if (null == getNamespace()) {
                    setNamespace(ID);
                }
            }
            MarvinTask mt = new MarvinTask();
            mt.AddDataset(getMinionID(), getNamespace(), "Next");
            TASKMAN.AddPostponedTask(mt, _AutoAdvanceInterval);
        }
        if (!_MontorMap.isEmpty()) {
            MarvinTask mt = new MarvinTask();
            mt.AddDataset(getMinionID(), getNamespace(), "Monitor");
            TASKMAN.AddPostponedTask(mt, _MonitorInterval);
        }
        DynamicImageWidget objDynaImg = this;
        dataMgr.AddListener(getMinionID(), getNamespace(), new ChangeListener() {

            @Override
            public void changed(ObservableValue o, Object oldVal, Object newVal) {
                boolean ChangeOcurred = false;
                if (IsPaused()) {
                    return;
                }
                String strVal = newVal.toString().replaceAll("(\\r|\\n)", "");
                String key;
                if (// go to next image in the list
                strVal.equalsIgnoreCase("Next")) {
                    key = _ListID.GetNext();
                } else if (// go to previous image in the list
                strVal.equalsIgnoreCase("Previous")) {
                    key = _ListID.GetPrevious();
                } else if (strVal.equalsIgnoreCase("Monitor")) {
                    ChangeOcurred = MonitorForFilechange();
                    if (ChangeOcurred) {
                        key = _CurrentKey;
                    }
                    key = _CurrentKey;
                    MarvinTask mt = new MarvinTask();
                    mt.AddDataset(getMinionID(), getNamespace(), "Monitor");
                    TASKMAN.AddPostponedTask(mt, _MonitorInterval);
                } else {
                    // expecting an ID
                    key = strVal;
                    // just to keep next/prev alignment
                    _ListID.get(key);
                }
                key = key.toLowerCase();
                if (_ImageFilenames.containsKey(key)) {
                    if (// no reason to re-load if it is already loaded
                    !key.equalsIgnoreCase(_CurrentKey) || ChangeOcurred) {
                        DynamicTransition objTransition = null;
                        ImageView startView = null;
                        ImageView nextView = null;
                        if (_TransitionMap.containsKey(_CurrentKey)) {
                            DynamicTransition objCurrentTransition = _TransitionMap.get(_CurrentKey);
                            if (objCurrentTransition.stillPlaying()) {
                                objCurrentTransition.stopTransition();
                            }
                        }
                        if (_TransitionMap.containsKey(key)) {
                            objTransition = _TransitionMap.get(key);
                            startView = _ImageViewMap.get(_CurrentKey);
                        } else {
                            _ImageViewMap.get(_CurrentKey).setVisible(false);
                        }
                        _CurrentKey = key;
                        if (null != objTransition && null != startView) {
                            nextView = _ImageViewMap.get(_CurrentKey);
                            objTransition.Transition(objDynaImg, startView, nextView);
                        } else {
                            _ImageViewMap.get(_CurrentKey).setVisible(true);
                        }
                    }
                } else {
                    LOGGER.warning("Received unknown ID: [" + strVal + "] for dynamic Image#" + getName() + ": [" + getNamespace() + ":" + getMinionID() + "]");
                    return;
                }
                if (_AutoAdvance) {
                    if (!_AutoLoopWithAdvance && _ListID.IsLast(key)) {
                        _AutoAdvance = false;
                        return;
                    }
                    MarvinTask mt = new MarvinTask();
                    mt.AddDataset(getMinionID(), getNamespace(), "Next");
                    TASKMAN.AddPostponedTask(mt, _AutoAdvanceInterval);
                }
            }
        });
        SetupTaskAction();
        return ApplyCSS();
    }
    return false;
}
Also used : DynamicTransition(kutch.biff.marvin.widget.dynamicgrid.DynamicTransition) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) ImageView(javafx.scene.image.ImageView) MarvinTask(kutch.biff.marvin.task.MarvinTask)

Aggregations

DynamicTransition (kutch.biff.marvin.widget.dynamicgrid.DynamicTransition)2 File (java.io.File)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 ImageView (javafx.scene.image.ImageView)1 MarvinTask (kutch.biff.marvin.task.MarvinTask)1