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