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;
}
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;
}
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;
}
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;
}
}
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;
}
Aggregations