Search in sources :

Example 1 with Anchor

use of org.develnext.jphp.swing.misc.Anchor 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)

Example 2 with Anchor

use of org.develnext.jphp.swing.misc.Anchor in project jphp by jphp-compiler.

the class UIElement method __getAnchors.

@Signature
protected Memory __getAnchors(Environment env, Memory... args) {
    ArrayMemory result = new ArrayMemory();
    ComponentProperties properties = SwingExtension.getProperties(getComponent());
    if (properties != null)
        for (Anchor anchor : properties.anchors) {
            result.add(new StringMemory(anchor.name()));
        }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Anchor(org.develnext.jphp.swing.misc.Anchor) ComponentProperties(org.develnext.jphp.swing.ComponentProperties) StringMemory(php.runtime.memory.StringMemory)

Aggregations

ComponentProperties (org.develnext.jphp.swing.ComponentProperties)2 Anchor (org.develnext.jphp.swing.misc.Anchor)2 XYLayout (org.develnext.jphp.swing.XYLayout)1 ForeachIterator (php.runtime.lang.ForeachIterator)1 ArrayMemory (php.runtime.memory.ArrayMemory)1 StringMemory (php.runtime.memory.StringMemory)1