use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class RSSReader method updateComponentValues.
void updateComponentValues(Container root, Hashtable h) {
int c = root.getComponentCount();
for (int iter = 0; iter < c; iter++) {
Component current = root.getComponentAt(iter);
// subclasses
if (current.getClass() == com.codename1.ui.Container.class || current.getClass() == com.codename1.ui.Tabs.class) {
updateComponentValues((Container) current, h);
continue;
}
String n = current.getName();
if (n != null) {
String val = (String) h.get(n);
if (val != null) {
if (current instanceof Button) {
final String url = (String) val;
((Button) current).addActionListener(new Listener(url));
continue;
}
if (current instanceof Label) {
((Label) current).setText(val);
continue;
}
if (current instanceof TextArea) {
((TextArea) current).setText(val);
continue;
}
if (current instanceof WebBrowser) {
((WebBrowser) current).setPage(val, null);
continue;
}
}
}
}
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class JavaSEPort method getProjectBuildHints.
@Override
public Map<String, String> getProjectBuildHints() {
File cnopFile = new File("codenameone_settings.properties");
if (cnopFile.exists()) {
java.util.Properties cnop = new java.util.Properties();
try (InputStream is = new FileInputStream(cnopFile)) {
cnop.load(is);
} catch (IOException err) {
return null;
}
HashMap<String, String> result = new HashMap<>();
for (Object kk : cnop.keySet()) {
String key = (String) kk;
if (key.startsWith("codename1.arg.")) {
String val = cnop.getProperty(key);
key = key.substring(14);
result.put(key, val);
}
}
return Collections.unmodifiableMap(result);
}
return null;
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class Invoke method appendInstruction.
@Override
public void appendInstruction(StringBuilder b) {
// special case for clone on an array which isn't a real method invocation
if (name.equals("clone") && owner.indexOf('[') > -1) {
b.append(" POP_MANY_AND_PUSH_OBJ(cloneArray(PEEK_OBJ(1)), 1);\n");
return;
}
StringBuilder bld = new StringBuilder();
if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKEVIRTUAL) {
b.append(" ");
bld.append("virtual_");
} else {
b.append(" ");
}
if (opcode == Opcodes.INVOKESTATIC) {
// find the actual class of the static method to workaround javac not defining it correctly
ByteCodeClass bc = Parser.getClassObject(owner.replace('/', '_').replace('$', '_'));
owner = findActualOwner(bc);
}
// if(owner.replace('/', '_').replace('$', '_').equals("java_lang_System_1") && name.equals("sleep")) {
// System.out.println("Break");
// }
bld.append(owner.replace('/', '_').replace('$', '_'));
bld.append("_");
if (name.equals("<init>")) {
bld.append("__INIT__");
} else {
if (name.equals("<clinit>")) {
bld.append("__CLINIT__");
} else {
bld.append(name);
}
}
bld.append("__");
ArrayList<String> args = new ArrayList<String>();
String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args);
boolean noPop = false;
if (returnVal == null) {
b.append(bld);
} else {
if (args.size() == 0 && opcode == Opcodes.INVOKESTATIC) {
// special case for static method
if (returnVal.equals("JAVA_OBJECT")) {
b.append("PUSH_OBJ");
} else {
if (returnVal.equals("JAVA_INT")) {
b.append("PUSH_INT");
} else {
if (returnVal.equals("JAVA_LONG")) {
b.append("PUSH_LONG");
} else {
if (returnVal.equals("JAVA_DOUBLE")) {
b.append("PUSH_DOUBLE");
} else {
if (returnVal.equals("JAVA_FLOAT")) {
b.append("PUSH_FLOAT");
} else {
throw new UnsupportedOperationException("Unknown type: " + returnVal);
}
}
}
}
}
// b.append(returnVal);
noPop = true;
b.append("(");
} else {
// b.append("POP_MANY_AND_");
// b.append(returnVal);
b.append("{ ");
b.append(returnVal);
b.append(" tmpResult = ");
}
b.append(bld);
}
b.append("(threadStateData");
if (opcode != Opcodes.INVOKESTATIC) {
b.append(", SP[-");
b.append(args.size() + 1);
b.append("].data.o");
}
int offset = args.size();
// int numArgs = offset;
int argIndex = 0;
for (String a : args) {
b.append(", ");
b.append("SP[-");
b.append(offset);
b.append("].data.");
b.append(a);
offset--;
argIndex++;
}
if (noPop) {
b.append("));\n");
return;
}
if (returnVal != null) {
b.append(");\n");
if (opcode != Opcodes.INVOKESTATIC) {
if (args.size() > 0) {
b.append(" SP-=");
b.append(args.size());
b.append(";\n");
}
} else {
if (args.size() > 1) {
b.append(" SP-=");
b.append(args.size() - 1);
b.append(";\n");
}
}
if (returnVal.equals("JAVA_OBJECT")) {
b.append(" SP[-1].data.o = tmpResult; SP[-1].type = CN1_TYPE_OBJECT; }\n");
} else {
if (returnVal.equals("JAVA_INT")) {
b.append(" SP[-1].data.i = tmpResult; SP[-1].type = CN1_TYPE_INT; }\n");
} else {
if (returnVal.equals("JAVA_LONG")) {
b.append(" SP[-1].data.l = tmpResult; SP[-1].type = CN1_TYPE_LONG; }\n");
} else {
if (returnVal.equals("JAVA_DOUBLE")) {
b.append(" SP[-1].data.d = tmpResult; SP[-1].type = CN1_TYPE_DOUBLE; }\n");
} else {
if (returnVal.equals("JAVA_FLOAT")) {
b.append(" SP[-1].data.f = tmpResult; SP[-1].type = CN1_TYPE_FLOAT; }\n");
} else {
throw new UnsupportedOperationException("Unknown type: " + returnVal);
}
}
}
}
}
return;
}
b.append("); ");
int val;
if (opcode != Opcodes.INVOKESTATIC) {
val = args.size() + 1;
} else {
val = args.size();
}
if (val > 0) {
/*b.append("popMany(threadStateData, ");
b.append(val);
b.append(", stack, &stackPointer); \n"); */
b.append(" SP-= ");
b.append(val);
b.append(";\n");
} else {
b.append("\n");
}
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class CloudObject method bindProperty.
/**
* Binds a property value within the given component to this cloud object, this means that
* when the component changes the cloud object changes unless deferred. If the defer flag is
* false all changes are stored in a temporary location and only "committed" once commitBindings()
* is invoked.
* @param cmp the component to bind
* @param propertyName the name of the property in the bound component
* @param attributeName the key within the cloud object
* @param defer bind settings whether to defer the binding which requires developers to explicitly commit
* the binding to perform the changes
* @param objectLead if set to true the UI property is initialized from values in the CloudObject, if false
* the cloud object property is initialized from the UI
*/
public void bindProperty(Component cmp, final String propertyName, final String attributeName, final int defer, boolean objectLead) {
if (objectLead) {
Object val = values.get(attributeName);
Object cmpVal = cmp.getBoundPropertyValue(propertyName);
if (val == null) {
if (cmpVal != null) {
cmp.setBoundPropertyValue(propertyName, null);
}
} else {
if (cmpVal == null || !(val.equals(cmpVal))) {
cmp.setBoundPropertyValue(propertyName, val);
}
}
} else {
Object val = values.get(attributeName);
Object cmpVal = cmp.getBoundPropertyValue(propertyName);
if (cmpVal == null) {
if (val != null) {
values.remove(attributeName);
status = STATUS_MODIFIED;
}
} else {
if (val == null || !(val.equals(cmpVal))) {
values.put(attributeName, cmpVal);
status = STATUS_MODIFIED;
}
}
}
BindTarget target = new BindTarget() {
public void propertyChanged(Component source, String propertyName, Object oldValue, Object newValue) {
switch(defer) {
case BINDING_DEFERRED:
if (deferedValues == null) {
deferedValues = new Hashtable();
}
deferedValues.put(attributeName, newValue);
break;
case BINDING_IMMEDIATE:
values.put(attributeName, newValue);
status = STATUS_MODIFIED;
break;
case BINDING_AUTO_SAVE:
values.put(attributeName, newValue);
status = STATUS_MODIFIED;
CloudStorage.getInstance().save(CloudObject.this);
break;
}
}
};
cmp.bindProperty(propertyName, target);
cmp.putClientProperty("CN1Bind" + propertyName, target);
}
use of com.codename1.ui.util.xml.Val in project CodenameOne by codenameone.
the class GenericListCellRenderer method getCellRendererComponent.
/**
* {@inheritDoc}
*/
public Component getCellRendererComponent(Component list, Object model, T value, int index, boolean isSelected) {
Component cmp;
Component[] entries;
if (!fisheye && !Display.getInstance().shouldRenderSelection(list)) {
isSelected = false;
}
if (isSelected && (fisheye || list.hasFocus())) {
cmp = selected;
entries = selectedEntries;
if (selectedEven != null && index % 2 == 0) {
cmp = selectedEven;
entries = selectedEntriesEven;
// prevent the list from over-optimizing the background painting
if (list instanceof List) {
((List) list).setMutableRendererBackgrounds(true);
}
}
cmp.setFocus(true);
boolean lead = false;
if (cmp instanceof Container) {
lead = ((Container) cmp).getLeadComponent() != null;
}
if (value instanceof Map) {
Map h = (Map) value;
Boolean enabled = (Boolean) h.get(ENABLED);
if (enabled != null) {
cmp.setEnabled(enabled.booleanValue());
}
int elen = entries.length;
for (int iter = 0; iter < elen; iter++) {
String currentName = entries[iter].getName();
Object val;
if (currentName.equals("$number")) {
val = "" + (index + 1);
} else {
// a selected entry might differ in its value to allow for
// behavior such as rollover images
val = h.get("#" + currentName);
if (val == null) {
val = h.get(currentName);
}
val = updateModelValues(h, currentName, entries, iter, val);
}
setComponentValueWithTickering(entries[iter], val, list, cmp);
entries[iter].setFocus(lead || entries[iter].isFocusable());
}
} else {
if (value instanceof CloudObject) {
CloudObject h = (CloudObject) value;
Boolean enabled = (Boolean) h.getBoolean(ENABLED);
if (enabled != null) {
cmp.setEnabled(enabled.booleanValue());
}
int elen = entries.length;
for (int iter = 0; iter < elen; iter++) {
String currentName = entries[iter].getName();
Object val;
if (currentName.equals("$number")) {
val = "" + (index + 1);
} else {
// a selected entry might differ in its value to allow for
// behavior such as rollover images
val = h.getObject("#" + currentName);
if (val == null) {
val = h.getObject(currentName);
}
}
setComponentValueWithTickering(entries[iter], val, list, cmp);
entries[iter].setFocus(entries[iter].isFocusable());
}
} else {
setComponentValueWithTickering(entries[0], value, list, cmp);
entries[0].setFocus(entries[0].isFocusable());
}
}
return cmp;
} else {
cmp = unselected;
entries = unselectedEntries;
if (unselectedEven != null && index % 2 == 0) {
cmp = unselectedEven;
entries = unselectedEntriesEven;
// prevent the list from over-optimizing the background painting
if (list instanceof List) {
((List) list).setMutableRendererBackgrounds(true);
}
}
cmp.setFocus(false);
if (value instanceof Map) {
Map h = (Map) value;
Boolean enabled = (Boolean) h.get(ENABLED);
if (enabled != null) {
cmp.setEnabled(enabled.booleanValue());
}
int elen = entries.length;
for (int iter = 0; iter < elen; iter++) {
String currentName = entries[iter].getName();
if (currentName.equals("$number")) {
setComponentValue(entries[iter], "" + (index + 1), list, cmp);
continue;
}
Object val = h.get(currentName);
val = updateModelValues(h, currentName, entries, iter, val);
setComponentValue(entries[iter], val, list, cmp);
}
} else {
if (value instanceof CloudObject) {
CloudObject h = (CloudObject) value;
Boolean enabled = h.getBoolean(ENABLED);
if (enabled != null) {
cmp.setEnabled(enabled.booleanValue());
}
int elen = entries.length;
for (int iter = 0; iter < elen; iter++) {
String currentName = entries[iter].getName();
if (currentName.equals("$number")) {
setComponentValue(entries[iter], "" + (index + 1), list, cmp);
continue;
}
setComponentValue(entries[iter], h.getObject(currentName), list, cmp);
}
} else {
if (entries.length > 0) {
setComponentValue(entries[0], value, list, cmp);
}
}
}
return cmp;
}
}
Aggregations