Search in sources :

Example 31 with Function

use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.

the class WindowImpl method setTimeout.

/**
 * {@inheritDoc}
 */
@Override
public int setTimeout(final Object function, final double millis) {
    if (millis > Integer.MAX_VALUE || millis < 0) {
        throw new IllegalArgumentException("Timeout value " + millis + " is not supported.");
    }
    final int timeID = generateTimerID();
    final Integer timeIDInt = timeID;
    ActionListener task = null;
    if (function instanceof Function) {
        Function fun = (Function) function;
        task = new FunctionTimerTask(this, timeIDInt, fun, true);
    }
    if (function instanceof String) {
        String expr = (String) function;
        task = new ExpressionTimerTask(this, timeIDInt, expr, true);
    }
    int t = (int) millis;
    if (t < 1) {
        t = 1;
    }
    final Timer timer = new Timer(t, task);
    timer.setRepeats(false);
    putAndStartTask(timeIDInt, timer, function);
    return timeID;
}
Also used : Function(org.mozilla.javascript.Function) ActionListener(java.awt.event.ActionListener) Timer(javax.swing.Timer)

Example 32 with Function

use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.

the class HtmlController method onMouseOver.

/**
 * <p>onMouseOver.</p>
 *
 * @param renderable a {@link org.loboevolution.html.renderer.BaseBoundableRenderable} object.
 * @param nodeStart a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
 * @param event a {@link java.awt.event.MouseEvent} object.
 * @param x a int.
 * @param y a int.
 * @param limit a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
 */
public void onMouseOver(final BaseBoundableRenderable renderable, final ModelNode nodeStart, final MouseEvent event, final int x, final int y, final ModelNode limit) {
    ModelNode node = nodeStart;
    while (node != null) {
        if (node == limit) {
            break;
        }
        if (node instanceof HTMLElementImpl) {
            final HTMLElementImpl uiElement = (HTMLElementImpl) node;
            uiElement.setMouseOver(true);
            final Function f = uiElement.getOnmouseover();
            if (f != null) {
                final MouseEventImpl evt = new MouseEventImpl();
                evt.initMouseEvent("mouseover", false, false, null, 0, 0, 0, x, y, true, true, true, true, (short) 0, null);
                evt.setIe(event);
                Executor.executeFunction(uiElement, f, evt, new Object[0]);
            }
            final HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
            if (rcontext != null) {
                rcontext.onMouseOver(uiElement, event);
            }
        }
        node = node.getParentModelNode();
    }
    setMouseOnMouseOver(renderable, nodeStart, limit);
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) Function(org.mozilla.javascript.Function) ModelNode(org.loboevolution.html.dom.nodeimpl.ModelNode) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Example 33 with Function

use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.

the class HtmlController method onDoubleClick.

/**
 * <p>onDoubleClick.</p>
 *
 * @return True to propagate further, false if consumed.
 * @param node a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
 * @param event a {@link java.awt.event.MouseEvent} object.
 * @param x a int.
 * @param y a int.
 */
public boolean onDoubleClick(ModelNode node, MouseEvent event, int x, int y) {
    if (logger.isLoggable(Level.INFO)) {
        logger.info("onDoubleClick(): node=" + node + ",class=" + node.getClass().getName());
    }
    if (node instanceof HTMLElementImpl) {
        final HTMLElementImpl uiElement = (HTMLElementImpl) node;
        final Function f = uiElement.getOndblclick();
        if (f != null) {
            final MouseEventImpl evt = new MouseEventImpl();
            evt.initMouseEvent("dblclick", false, false, null, 0, 0, 0, x, y, true, true, true, true, (short) 0, null);
            evt.setIe(event);
            if (!Executor.executeFunction(uiElement, f, evt, new Object[0])) {
                return false;
            }
        }
        final HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
        if (rcontext != null) {
            if (!rcontext.onDoubleClick(uiElement, event)) {
                return false;
            }
        }
    }
    final ModelNode parent = node.getParentModelNode();
    if (parent == null) {
        return true;
    }
    return onDoubleClick(parent, event, 0, 0);
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) Function(org.mozilla.javascript.Function) ModelNode(org.loboevolution.html.dom.nodeimpl.ModelNode) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Example 34 with Function

use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.

the class HtmlController method onMouseDown.

/**
 * <p>onMouseDown.</p>
 *
 * @return True to propagate further, false if consumed.
 * @param node a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
 * @param event a {@link java.awt.event.MouseEvent} object.
 * @param x a int.
 * @param y a int.
 */
public boolean onMouseDown(ModelNode node, MouseEvent event, int x, int y) {
    boolean pass = true;
    if (node instanceof HTMLElementImpl) {
        final HTMLElementImpl uiElement = (HTMLElementImpl) node;
        final Function f = uiElement.getOnmousedown();
        if (f != null) {
            final MouseEventImpl evt = new MouseEventImpl();
            evt.initMouseEvent("mousedown", false, false, null, 0, 0, 0, x, y, true, true, true, true, (short) 0, null);
            evt.setIe(event);
            pass = Executor.executeFunction(uiElement, f, evt, new Object[0]);
        }
    }
    if (node instanceof HTMLLinkElementImpl) {
        ((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor("#9090FF80");
        return false;
    }
    if (!pass) {
        return false;
    }
    final ModelNode parent = node.getParentModelNode();
    if (parent == null) {
        return true;
    }
    return onMouseDown(parent, event, 0, 0);
}
Also used : Function(org.mozilla.javascript.Function) ModelNode(org.loboevolution.html.dom.nodeimpl.ModelNode) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Example 35 with Function

use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.

the class HtmlController method onChange.

/**
 * <p>onChange.</p>
 *
 * @param node a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
 * @return a boolean.
 */
public boolean onChange(ModelNode node) {
    if (node instanceof HTMLSelectElementImpl) {
        final HTMLSelectElementImpl uiElement = (HTMLSelectElementImpl) node;
        final Function f = uiElement.getOnchange();
        if (f != null) {
            final EventImpl evt = new EventImpl();
            evt.initEvent("change", false, false);
            if (!Executor.executeFunction(uiElement, f, evt, new Object[0])) {
                return false;
            }
        }
    }
    return false;
}
Also used : Function(org.mozilla.javascript.Function) EventImpl(org.loboevolution.html.js.events.EventImpl) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Aggregations

Function (org.mozilla.javascript.Function)126 Scriptable (org.mozilla.javascript.Scriptable)35 Context (org.mozilla.javascript.Context)33 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)27 ScriptableObject (org.mozilla.javascript.ScriptableObject)27 JSFunction (org.mozilla.javascript.annotations.JSFunction)25 MouseEventImpl (org.loboevolution.html.js.events.MouseEventImpl)11 BaseFunction (org.mozilla.javascript.BaseFunction)10 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)10 NativeObject (org.mozilla.javascript.NativeObject)10 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 GlobalScope (com.servoy.j2db.scripting.GlobalScope)7 ServoyException (com.servoy.j2db.util.ServoyException)7 IOException (java.io.IOException)7 HtmlRendererContext (org.loboevolution.http.HtmlRendererContext)7 JSONObject (org.json.JSONObject)6 ModelNode (org.loboevolution.html.dom.nodeimpl.ModelNode)6 RhinoException (org.mozilla.javascript.RhinoException)6 PropertyDescription (org.sablo.specification.PropertyDescription)6 ArrayList (java.util.ArrayList)5