Search in sources :

Example 1 with Invoker

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

the class WrapSwingUtilities method setExceptionHandler.

@Signature(@Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("NULL")))
public static Memory setExceptionHandler(Environment env, Memory... args) {
    if (args[0].isNull()) {
        env.setUserValue(SwingExtension.NAMESPACE + "#exceptionHandler", null);
    } else {
        final Invoker invoker = Invoker.valueOf(env, null, args[0]);
        env.setUserValue(SwingExtension.NAMESPACE + "#exceptionHandler", invoker);
    }
    return Memory.TRUE;
}
Also used : Invoker(php.runtime.invoke.Invoker)

Example 2 with Invoker

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

the class UICombobox method onCellRender.

@Signature(@Arg(value = "handler", optional = @Optional("null")))
public Memory onCellRender(final Environment env, Memory... args) {
    if (args[0].isNull())
        component.setRenderer(defaultRenderer);
    else {
        final Invoker invoker = Invoker.valueOf(env, null, args[0]);
        final ObjectMemory self = new ObjectMemory(this);
        component.setRenderer(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 3 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 4 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 5 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)

Aggregations

Invoker (php.runtime.invoke.Invoker)61 Memory (php.runtime.Memory)29 ArrayMemory (php.runtime.memory.ArrayMemory)13 ForeachIterator (php.runtime.lang.ForeachIterator)12 LongMemory (php.runtime.memory.LongMemory)12 ObjectMemory (php.runtime.memory.ObjectMemory)12 StringMemory (php.runtime.memory.StringMemory)10 Environment (php.runtime.env.Environment)7 Signature (php.runtime.annotation.Reflection.Signature)5 KeyValueMemory (php.runtime.memory.KeyValueMemory)5 ReferenceMemory (php.runtime.memory.ReferenceMemory)5 SplClassLoader (php.runtime.env.SplClassLoader)4 FileObject (php.runtime.ext.core.classes.stream.FileObject)4 DynamicMethodInvoker (php.runtime.invoke.DynamicMethodInvoker)4 RunnableInvoker (php.runtime.invoke.RunnableInvoker)3 File (java.io.File)2 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)2 WebSocketHandler (org.eclipse.jetty.websocket.server.WebSocketHandler)2