use of com.codename1.ui.UIFragment in project CodenameOne by codenameone.
the class UIFragment method parseXML.
/**
* Parses input stream of XML into a Template
* @param input InputStream with XML content to parse
* @return The corresponding template, or a RuntimeException if parsing failed.
*/
public static UIFragment parseXML(InputStream input) {
try {
XMLParser p = new XMLParser();
Element el = p.parse(new InputStreamReader(input));
return new UIFragment(el);
} catch (Exception ex) {
Log.e(ex);
throw new RuntimeException(ex.getMessage());
}
}
use of com.codename1.ui.UIFragment in project CodenameOne by codenameone.
the class UIFragmentSample method testUIFragment.
private void testUIFragment() {
Form f = new Form("Test Fragments", BoxLayout.y());
TextArea ta = new TextArea();
ta.setMaxSize(5000);
String[] examples = new String[] { "<borderAbs><$button1 constraint='center'/><xng constraint='south'><$button2/><$button3/><$button4/></xng></borderAbs>", "{centerAbs:$button1, south:{xng:[$button2, $button3, $button4]}}", "{cs:$button1, south:{xng:[$button2, $button3, $button4]}}", "{ca:$button1, south:{xng:[$button2, $button3, $button4]}}", "{centerScale:$button1, south:{xng:[$button2, $button3, $button4]}}", "{ctb:$button1, south:{xng:[$button2, $button3, $button4]}}", "{centerTotalBelow:$button1, south:{xng:[$button2, $button3, $button4]}}", "{s:$button1, c:{xng:[$button2, $button3, $button4]}}", "{s:$button1, c:{x:[$button2, $button3, $button4]}}", "{s:$button1, c:{y:[$button2, $button3, $button4]}}", "{s:$button1, c:{yBottomLast:[$button2, $button3, $button4]}}", "{s:$button1, c:{ybl:[$button2, $button3, $button4]}}" };
ComboBox cb = new ComboBox(examples);
cb.addActionListener(e -> {
ta.setText(examples[cb.getSelectedIndex()]);
});
ta.setText("<borderAbs><$button1 constraint='center'/><xng constraint='south'><$button2/><$button3/><$button4/></xng></borderAbs>");
Button b = new Button("Compile");
b.addActionListener(e -> {
Form f2 = new Form("Result", new BorderLayout());
f2.setToolbar(new Toolbar());
f2.setTitle("Result");
f2.setBackCommand("Back", null, evt -> {
f.showBack();
});
f2.getToolbar().addCommandToLeftBar("Back", null, evt -> {
f.showBack();
});
Button b1 = new Button("Button 1");
Button b2 = new Button("Button 2");
Button b3 = new Button("Button 3");
Button b4 = new Button("Button 4");
$(b1, b2, b3, b4).selectAllStyles().setBorder(RoundRectBorder.create().cornerRadius(2)).setBgColor(0x003399).setBgTransparency(0xff);
UIFragment frag;
if (ta.getText().charAt(0) == '<') {
frag = UIFragment.parseXML(ta.getText());
} else {
System.out.println("Parsing " + ta.getText());
frag = UIFragment.parseJSON(ta.getText());
}
f2.add(BorderLayout.CENTER, frag.set("button1", b1).set("button2", b2).set("button3", b3).set("button4", b4).getView());
f2.show();
});
ta.setRows(5);
f.addAll(cb, ta, b);
f.show();
}
use of com.codename1.ui.UIFragment in project CodenameOne by codenameone.
the class UIFragment method parseXML.
/**
* Parses XML string into a Template
* @param xml XML string describing a UI.
* @return The corresponding template, or a RuntimeException if parsing failed.
*/
public static UIFragment parseXML(String xml) {
try {
XMLParser p = new XMLParser();
p.setCaseSensitive(true);
Element el = p.parse(new CharArrayReader(xml.toCharArray()));
return new UIFragment(el);
} catch (Exception ex) {
Log.e(ex);
throw new RuntimeException(ex.getMessage());
}
}
Aggregations