Search in sources :

Example 16 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class UIFileChooser method addChoosableFilter.

@Signature({ @Arg(value = "filter", type = HintType.CALLABLE), @Arg(value = "description") })
public Memory addChoosableFilter(final Environment env, Memory... args) {
    final Invoker invoker = Invoker.valueOf(env, null, args[0]);
    final String description = args[1].toString();
    component.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return invoker.callNoThrow(new ObjectMemory(new FileObject(env, f))).toBoolean();
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return Memory.NULL;
}
Also used : Invoker(php.runtime.invoke.Invoker) FileObject(php.runtime.ext.core.classes.stream.FileObject) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 17 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class UIListbox method onCellRender.

@Signature(@Arg(value = "handler", optional = @Optional("null")))
public Memory onCellRender(final Environment env, Memory... args) {
    if (args[0].isNull())
        component.getContent().setCellRenderer(defaultRenderer);
    else {
        final Invoker invoker = Invoker.valueOf(env, null, args[0]);
        final ObjectMemory self = new ObjectMemory(this);
        component.getContent().setCellRenderer(new ListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                JLabel template = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                Memory _value = MemoryUtils.valueOf(value);
                Memory _index = LongMemory.valueOf(index);
                Memory _isSelected = TrueMemory.valueOf(isSelected);
                Memory _cellHasFocus = TrueMemory.valueOf(cellHasFocus);
                Memory r = invoker.callNoThrow(self, new ObjectMemory(new UILabel(env, template)), _value, _index, _isSelected, _cellHasFocus);
                if (r.isObject() && r.instanceOf(UIElement.class)) {
                    return r.toObject(UIElement.class).getComponent();
                }
                return template;
            }
        });
    }
    return Memory.NULL;
}
Also used : Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory)

Example 18 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class UIElement method setAction.

@Signature({ @Arg("name"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory setAction(Environment env, Memory... args) {
    if (args[1].isNull()) {
        getJComponent().getActionMap().remove(args[0].toString());
        return Memory.NULL;
    }
    final Invoker invoker = Invoker.valueOf(env, null, args[1]);
    getJComponent().getActionMap().put(args[0].toString(), new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            invoker.callNoThrow();
        }
    });
    return Memory.NULL;
}
Also used : Invoker(php.runtime.invoke.Invoker) ActionEvent(java.awt.event.ActionEvent)

Example 19 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class ArrayFunctions method _array_udiff_impl.

protected static Memory _array_udiff_impl(Environment env, TraceInfo trace, Memory array1, Memory array, final boolean assoc, Memory... arrays) throws Throwable {
    if (arrays == null) {
        expectingCallback(env, trace, 3, Memory.NULL);
        return Memory.NULL;
    }
    Memory callback = arrays[arrays.length - 1];
    final Invoker expectingCallback = expectingCallback(env, trace, arrays.length + 2, callback);
    if (expectingCallback != null) {
        return _array_diff_impl(env, trace, array1, array, Arrays.copyOf(arrays, arrays.length - 1), new ArrayDiffCallback() {

            @Override
            public boolean apply(Memory keyValue, Memory value, Memory keyComparable, Memory comparable) throws Throwable {
                if (assoc && keyValue.notEqual(keyComparable)) {
                    return false;
                }
                Memory memory = expectingCallback.call(value, comparable);
                return memory.toInteger() == 0;
            }
        });
    } else {
        return Memory.NULL;
    }
}
Also used : Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) LongMemory(php.runtime.memory.LongMemory) KeyValueMemory(php.runtime.memory.KeyValueMemory)

Example 20 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class JsonProcessor method onSerialize.

@Signature({ @Arg("type"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory onSerialize(Environment env, Memory... args) {
    Memory.Type type = Memory.Type.of(args[0].toString());
    if (type == null)
        throw new IllegalArgumentException("Invalid type - " + args[0]);
    MemorySerializer.Handler handler = null;
    if (!args[1].isNull()) {
        final Invoker invoker = Invoker.valueOf(env, env.trace(), args[1]);
        handler = new MemorySerializer.Handler() {

            @Override
            public Memory call(Environment env, Memory value) {
                return invoker.callNoThrow(value);
            }
        };
    }
    memorySerializer.setTypeHandler(type, handler);
    return null;
}
Also used : MemorySerializer(org.develnext.jphp.json.gson.MemorySerializer) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Aggregations

Invoker (php.runtime.invoke.Invoker)50 Memory (php.runtime.Memory)21 ArrayMemory (php.runtime.memory.ArrayMemory)13 ForeachIterator (php.runtime.lang.ForeachIterator)12 LongMemory (php.runtime.memory.LongMemory)9 ObjectMemory (php.runtime.memory.ObjectMemory)9 KeyValueMemory (php.runtime.memory.KeyValueMemory)7 StringMemory (php.runtime.memory.StringMemory)7 Environment (php.runtime.env.Environment)6 ReferenceMemory (php.runtime.memory.ReferenceMemory)5 SplClassLoader (php.runtime.env.SplClassLoader)4 File (java.io.File)2 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 TraceInfo (php.runtime.env.TraceInfo)2 FileObject (php.runtime.ext.core.classes.stream.FileObject)2 ActionEvent (java.awt.event.ActionEvent)1 MessageDigest (java.security.MessageDigest)1 Scanner (java.util.Scanner)1 FileFilter (javax.swing.filechooser.FileFilter)1