Search in sources :

Example 46 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class WrapDomDocument method createElement.

@Signature
public Element createElement(String tagName, @Nullable ArrayMemory _model) {
    Element element = getWrappedObject().createElement(tagName);
    ForeachIterator model = _model.foreachIterator(false, false);
    while (model != null && model.next()) {
        String key = model.getKey().toString();
        Memory value = model.getValue();
        if (key.startsWith("@")) {
            element.setAttribute(key.substring(1), value.toString());
        } else {
            Element subElement = getWrappedObject().createElement(key);
            if (value.isArray()) {
                for (Memory el : value.toValue(ArrayMemory.class)) {
                    Element sub = getWrappedObject().createElement("item");
                    if (el.isArray()) {
                        sub = createElement("item", el.toValue(ArrayMemory.class));
                    } else {
                        sub.setTextContent(el.toString());
                    }
                    subElement.appendChild(sub);
                }
            } else {
                subElement.setTextContent(value.toString());
            }
            element.appendChild(subElement);
        }
    }
    return element;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) Element(org.w3c.dom.Element)

Example 47 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class UIFileChooser method addChoosableExtensions.

@Signature({ @Arg(value = "extensions", type = HintType.ARRAY), @Arg(value = "description"), @Arg(value = "showDirectories", optional = @Optional(value = "1", type = HintType.BOOLEAN)) })
public Memory addChoosableExtensions(final Environment env, final Memory... args) {
    final Set<String> extensions = new HashSet<String>();
    ForeachIterator iterator = args[0].getNewIterator(env, false, false);
    while (iterator.next()) {
        extensions.add(iterator.getValue().toString());
    }
    final String description = args[1].toString();
    component.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) {
                return args[2].toBoolean();
            }
            String path = f.getPath();
            for (String ext : extensions) {
                if (Constants.PATH_NAME_CASE_INSENSITIVE) {
                    if (path.endsWith("." + ext))
                        return true;
                } else {
                    if (path.toLowerCase().endsWith("." + ext.toLowerCase()))
                        return true;
                }
            }
            return false;
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 48 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class UIListbox method __setSelectedIndexes.

@Signature(@Arg(value = "indexes", type = HintType.ARRAY))
protected Memory __setSelectedIndexes(Environment env, Memory... args) {
    ArrayMemory arr = args[0].toValue(ArrayMemory.class);
    int[] items = new int[arr.size()];
    ForeachIterator iterator = arr.foreachIterator(false, false);
    int i = 0;
    while (iterator.next()) {
        items[i] = iterator.getValue().toInteger();
        i++;
    }
    component.setSelectedIndices(items);
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator)

Example 49 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class UIListbox method setItems.

@Signature(@Arg(value = "items", type = HintType.ARRAY))
public Memory setItems(Environment env, Memory... args) {
    DefaultListModel listModel = (DefaultListModel) component.getModel();
    listModel.clear();
    ArrayMemory arr = args[0].toValue(ArrayMemory.class);
    ForeachIterator iterator = arr.foreachIterator(false, false);
    int i = 0;
    while (iterator.next()) {
        listModel.addElement(iterator.getValue());
        i++;
    }
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator)

Example 50 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class UIElement method __setAnchors.

@Signature(@Arg("value"))
protected Memory __setAnchors(Environment env, Memory... args) {
    ComponentProperties data = SwingExtension.getProperties(getComponent());
    data.anchors.clear();
    if (args[0].isArray()) {
        ForeachIterator iterator = args[0].getNewIterator(env, false, false);
        while (iterator.next()) {
            Anchor anchor = Anchor.valueOf(iterator.getValue().toString().toUpperCase());
            if (anchor == null)
                env.exception(env.trace(), "Invalid anchor value - " + iterator.getValue());
            data.anchors.add(anchor);
        }
    } else {
        Anchor anchor = Anchor.valueOf(args[0].toString().toUpperCase());
        if (anchor == null)
            env.exception(env.trace(), "Invalid anchor value - " + args[0]);
    }
    if (getComponent().getParent() != null) {
        LayoutManager layout = getComponent().getParent().getLayout();
        if (!(layout instanceof XYLayout))
            env.exception(env.trace(), "Layout must be an instance of XYLayout");
    }
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Anchor(org.develnext.jphp.swing.misc.Anchor) ComponentProperties(org.develnext.jphp.swing.ComponentProperties) XYLayout(org.develnext.jphp.swing.XYLayout)

Aggregations

ForeachIterator (php.runtime.lang.ForeachIterator)100 ArrayMemory (php.runtime.memory.ArrayMemory)49 Memory (php.runtime.Memory)47 LongMemory (php.runtime.memory.LongMemory)22 KeyValueMemory (php.runtime.memory.KeyValueMemory)18 ReferenceMemory (php.runtime.memory.ReferenceMemory)16 Invoker (php.runtime.invoke.Invoker)12 ObjectMemory (php.runtime.memory.ObjectMemory)12 IObject (php.runtime.lang.IObject)9 ArrayKeyMemory (php.runtime.memory.helper.ArrayKeyMemory)6 ArrayValueMemory (php.runtime.memory.helper.ArrayValueMemory)6 ShortcutMemory (php.runtime.memory.helper.ShortcutMemory)5 Signature (php.runtime.annotation.Reflection.Signature)4 StringMemory (php.runtime.memory.StringMemory)4 File (java.io.File)3 HashSet (java.util.HashSet)3 Element (org.w3c.dom.Element)3 FastMethod (php.runtime.annotation.Runtime.FastMethod)3 ClassEntity (php.runtime.reflection.ClassEntity)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3