use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class LazyValueC method formToContainer.
Container formToContainer(Form f) {
Container cnt = new Container(f.getContentPane().getLayout());
if (f.getContentPane().getLayout() instanceof BorderLayout || f.getContentPane().getLayout() instanceof TableLayout) {
while (f.getContentPane().getComponentCount() > 0) {
Component src = f.getContentPane().getComponentAt(0);
Object o = f.getContentPane().getLayout().getComponentConstraint(src);
f.getContentPane().removeComponent(src);
cnt.addComponent(o, src);
}
} else {
while (f.getContentPane().getComponentCount() > 0) {
Component src = f.getContentPane().getComponentAt(0);
f.getContentPane().removeComponent(src);
cnt.addComponent(src);
}
}
return cnt;
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class InstantUI method createEditUI.
/**
* Creates editing UI for the given business object
* @param bo the business object
* @param autoCommit true if the bindings used should be auto-committed
* @return a UI container that can be used to edit the business object
*/
public Container createEditUI(PropertyBusinessObject bo, boolean autoCommit) {
Container cnt;
if (Display.getInstance().isTablet()) {
TableLayout tl = new TableLayout(1, 2);
tl.setGrowHorizontally(true);
cnt = new Container(tl);
} else {
cnt = new Container(BoxLayout.y());
}
UiBinding uib = new UiBinding();
ArrayList<UiBinding.Binding> allBindings = new ArrayList<UiBinding.Binding>();
for (PropertyBase b : bo.getPropertyIndex()) {
if (isExcludedProperty(b)) {
continue;
}
Class cls = (Class) b.getClientProperty("cn1$cmpCls");
if (cls != null) {
try {
Component cmp = (Component) cls.newInstance();
cmp.setName(b.getName());
cnt.add(b.getLabel()).add(cmp);
allBindings.add(uib.bind(b, cmp));
} catch (Exception err) {
Log.e(err);
throw new RuntimeException("Custom property instant UI failed for " + b.getName() + " " + err);
}
continue;
}
String[] multiLabels = (String[]) b.getClientProperty("cn1$multiChceLbl");
if (multiLabels != null) {
// multi choice component
final Object[] multiValues = (Object[]) b.getClientProperty("cn1$multiChceVal");
if (multiLabels.length < 5) {
// toggle buttons
ButtonGroup bg = new ButtonGroup();
RadioButton[] rbs = new RadioButton[multiLabels.length];
cnt.add(b.getLabel());
Container radioBox = new Container(new GridLayout(multiLabels.length));
for (int iter = 0; iter < multiLabels.length; iter++) {
rbs[iter] = RadioButton.createToggle(multiLabels[iter], bg);
radioBox.add(rbs[iter]);
}
cnt.add(radioBox);
allBindings.add(uib.bindGroup(b, multiValues, rbs));
} else {
Picker stringPicker = new Picker();
stringPicker.setStrings(multiLabels);
Map<Object, Object> m1 = new HashMap<Object, Object>();
Map<Object, Object> m2 = new HashMap<Object, Object>();
for (int iter = 0; iter < multiLabels.length; iter++) {
m1.put(multiLabels[iter], multiValues[iter]);
m2.put(multiValues[iter], multiLabels[iter]);
}
cnt.add(b.getLabel()).add(stringPicker);
allBindings.add(uib.bind(b, stringPicker, new UiBinding.PickerAdapter<Object>(new UiBinding.MappingConverter(m1), new UiBinding.MappingConverter(m2))));
}
continue;
}
Class t = b.getGenericType();
if (t != null) {
if (t == Boolean.class) {
CheckBox cb = new CheckBox();
uib.bind(b, cb);
cnt.add(b.getLabel()).add(cb);
continue;
}
if (t == Date.class) {
Picker dp = new Picker();
dp.setType(Display.PICKER_TYPE_DATE);
uib.bind(b, dp);
cnt.add(b.getLabel()).add(dp);
continue;
}
}
TextField tf = new TextField();
tf.setConstraint(getTextFieldConstraint(b));
uib.bind(b, tf);
cnt.add(b.getLabel()).add(tf);
}
cnt.putClientProperty("cn1$iui-binding", uib.createGroupBinding(allBindings));
return cnt;
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class UserInterfaceEditor method persistToXML.
private static void persistToXML(com.codename1.ui.Container containerInstance, com.codename1.ui.Component cmp, StringBuilder build, EditableResources res, String indent, String tabTitle) {
build.append(indent);
build.append("<component type=\"");
build.append((String) cmp.getClientProperty(TYPE_KEY));
build.append("\" name=\"");
if (cmp.getName() != null) {
build.append(xmlize(cmp.getName()));
}
build.append("\" ");
if (exportToNewGuiBuilderMode) {
String cmpName = cmp.getName();
Class cls = componentNames.get(cmpName);
if (cls == null) {
componentNames.put(cmpName, cmp.getClass());
} else {
if (cls != cmp.getClass()) {
componentNames.put(cmpName, com.codename1.ui.Component.class);
}
}
if (cmp instanceof List) {
listNames.add(cmp.getName());
}
if (cmp instanceof com.codename1.ui.Button || cmp instanceof com.codename1.ui.TextArea || cmp instanceof com.codename1.ui.Slider || cmp instanceof com.codename1.ui.List || cmp instanceof com.codename1.components.MultiButton || cmp instanceof com.codename1.components.SpanButton || cmp instanceof com.codename1.components.OnOffSwitch || cmp instanceof com.codename1.ui.Calendar || cmp instanceof com.codename1.ui.list.ContainerList) {
// add action listener XML
actionEventNames.add(cmp.getName());
build.append(" actionEvent=\"true\" ");
}
}
if (cmp.getClientProperty("cn1$Properties") != null) {
String[] p = ((String) cmp.getClientProperty("cn1$Properties")).split(",");
if (p.length > 0) {
build.append("clientProperties=\"");
boolean first = true;
for (String c : p) {
if (!first) {
build.append(",");
}
first = false;
build.append(c);
build.append("=");
build.append((String) cmp.getClientProperty(c));
}
build.append("\" ");
}
}
if (tabTitle != null) {
build.append("tabTitle=\"");
build.append(xmlize(tabTitle));
build.append("\" ");
}
if (cmp.getClientProperty("%base_form%") != null) {
build.append("baseForm=\"");
build.append(xmlize((String) cmp.getClientProperty("%base_form%")));
build.append("\" ");
}
if (cmp.getCloudBoundProperty() != null) {
build.append("cloudBoundProperty=\"");
build.append(xmlize(cmp.getCloudBoundProperty()));
build.append("\" ");
}
if (cmp.getCloudDestinationProperty() != null) {
build.append("cloudDestinationProperty=\"");
build.append(xmlize(cmp.getCloudDestinationProperty()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_COMMAND) || isPropertyModified(cmp, PROPERTY_COMMAND_LEGACY)) {
ActionCommand cmd;
if (cmp instanceof com.codename1.ui.Container) {
cmd = (ActionCommand) ((com.codename1.ui.Button) ((com.codename1.ui.Container) cmp).getLeadComponent()).getCommand();
} else {
cmd = (ActionCommand) ((com.codename1.ui.Button) cmp).getCommand();
}
build.append("commandName=\"");
build.append(xmlize(cmd.getCommandName()));
build.append("\" ");
if (cmd.getIcon() != null) {
build.append("commandIcon=\"");
build.append(xmlize(res.findId(cmd.getIcon())));
build.append("\" ");
}
if (cmd.getRolloverIcon() != null) {
build.append("commandRolloverIcon=\"");
build.append(xmlize(res.findId(cmd.getRolloverIcon())));
build.append("\" ");
}
if (cmd.getPressedIcon() != null) {
build.append("commandPressedIcon=\"");
build.append(xmlize(res.findId(cmd.getPressedIcon())));
build.append("\" ");
}
if (cmd.getDisabledIcon() != null) {
build.append("commandDisabledIcon=\"");
build.append(xmlize(res.findId(cmd.getDisabledIcon())));
build.append("\" ");
}
build.append("commandId=\"");
build.append(cmd.getId());
build.append("\" ");
if (cmd.getAction() != null) {
build.append("commandAction=\"");
build.append(xmlize(cmd.getAction()));
build.append("\" ");
if (cmd.getAction().equals("$Execute")) {
build.append("commandArgument=\"");
build.append(xmlize(cmd.getArgument()));
build.append("\" ");
}
}
build.append("commandBack=\"");
build.append(cmp.getComponentForm().getBackCommand() == cmd);
build.append("\" ");
if (exportToNewGuiBuilderMode) {
build.append(" varName=\"");
String varName;
if (cmd.getCommandName() == null || cmd.getCommandName().length() == 0) {
varName = ResourceEditorView.normalizeFormName(cmd.getCommandName());
build.append(varName);
} else {
varName = "Command" + commandCounter;
build.append(varName);
commandCounter++;
}
build.append("\" ");
String action = cmd.getAction();
if (action != null) {
if (cmp.getComponentForm() != null) {
commandList.add(cmd);
cmd.putClientProperty("FORMNAME", cmp.getComponentForm().getName());
}
}
}
}
if (isPropertyModified(cmp, PROPERTY_LABEL_FOR)) {
if (cmp.getLabelForComponent() != null) {
build.append("labelFor=\"");
build.append(xmlize(cmp.getLabelForComponent().getName()));
build.append("\" ");
}
}
if (isPropertyModified(cmp, PROPERTY_LEAD_COMPONENT) && ((com.codename1.ui.Container) cmp).getLeadComponent() != null) {
build.append("leadComponent=\"");
build.append(xmlize(((com.codename1.ui.Container) cmp).getLeadComponent().getName()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_DOWN) && cmp.getNextFocusDown() != null) {
build.append("nextFocusDown=\"");
build.append(xmlize(cmp.getNextFocusDown().getName()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_UP) && cmp.getNextFocusUp() != null) {
build.append("nextFocusUp=\"");
build.append(xmlize(cmp.getNextFocusUp().getName()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_LEFT) && cmp.getNextFocusLeft() != null) {
build.append("nextFocusLeft=\"");
build.append(xmlize(cmp.getNextFocusLeft().getName()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_RIGHT) && cmp.getNextFocusRight() != null) {
build.append("nextFocusRight=\"");
build.append(xmlize(cmp.getNextFocusRight().getName()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_EMBED)) {
build.append("embed=\"");
build.append(xmlize(((EmbeddedContainer) cmp).getEmbed()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_UIID)) {
build.append("uiid=\"");
build.append(cmp.getUIID());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_FOCUSABLE)) {
build.append("focusable=\"");
build.append(cmp.isFocusable());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_ENABLED)) {
build.append("enabled=\"");
build.append(cmp.isEnabled());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_RTL)) {
build.append("rtl=\"");
build.append(cmp.isRTL());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_SCROLL_VISIBLE)) {
build.append("scrollVisible=\"");
build.append(cmp.isScrollVisible());
build.append("\" ");
}
/*if(isPropertyModified(cmp, PROPERTY_PREFERRED_WIDTH)) {
out.writeInt(PROPERTY_PREFERRED_WIDTH);
out.writeInt(cmp.getPreferredW());
}
if(isPropertyModified(cmp, PROPERTY_PREFERRED_HEIGHT)) {
out.writeInt(PROPERTY_PREFERRED_HEIGHT);
out.writeInt(cmp.getPreferredH());
}*/
if (isPropertyModified(cmp, PROPERTY_TENSILE_DRAG_ENABLED)) {
build.append("tensileDragEnabled=\"");
build.append(cmp.isTensileDragEnabled());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TACTILE_TOUCH)) {
build.append("tactileTouch=\"");
build.append(cmp.isTactileTouch());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_SNAP_TO_GRID)) {
build.append("snapToGrid=\"");
build.append(cmp.isSnapToGrid());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_FLATTEN)) {
build.append("flatten=\"");
build.append(cmp.isFlatten());
build.append("\" ");
}
if (isActualContainer(cmp) || cmp instanceof com.codename1.ui.list.ContainerList) {
com.codename1.ui.Container cnt = (com.codename1.ui.Container) cmp;
if (isPropertyModified(cnt, PROPERTY_SCROLLABLE_X)) {
build.append("scrollableX=\"");
build.append(CodenameOneAccessor.isScrollableX(cnt));
build.append("\" ");
}
if (isPropertyModified(cnt, PROPERTY_SCROLLABLE_Y)) {
build.append("scrollableY=\"");
build.append(CodenameOneAccessor.isScrollableY(cnt));
build.append("\" ");
}
if (cmp instanceof com.codename1.ui.Tabs) {
com.codename1.ui.Tabs tab = (com.codename1.ui.Tabs) cmp;
if (isPropertyModified(cmp, PROPERTY_TAB_PLACEMENT)) {
build.append("tabPlacement=\"");
build.append(((com.codename1.ui.Tabs) cmp).getTabPlacement());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TAB_TEXT_POSITION)) {
build.append("tabTextPosition=\"");
build.append(((com.codename1.ui.Tabs) cmp).getTabTextPosition());
build.append("\" ");
}
build.append(">\n");
appendComponentXMLBody(containerInstance, cmp, build, res, indent + " ");
for (int iter = 0; iter < tab.getTabCount(); iter++) {
persistToXML(containerInstance, tab.getTabComponentAt(iter), build, res, indent + " ", tab.getTabTitle(iter));
}
build.append(indent);
build.append("</component>\n");
} else {
if (isPropertyModified(cmp, PROPERTY_LAYOUT)) {
com.codename1.ui.layouts.Layout l = cnt.getLayout();
build.append("layout=\"");
if (l instanceof com.codename1.ui.layouts.FlowLayout) {
com.codename1.ui.layouts.FlowLayout f = (com.codename1.ui.layouts.FlowLayout) l;
build.append("FlowLayout\" flowLayoutFillRows=\"");
build.append(f.isFillRows());
build.append("\" flowLayoutAlign=\"");
build.append(f.getAlign());
build.append("\" flowLayoutValign=\"");
build.append(f.getValign());
build.append("\" ");
} else {
if (l instanceof com.codename1.ui.layouts.BorderLayout) {
com.codename1.ui.layouts.BorderLayout b = (com.codename1.ui.layouts.BorderLayout) l;
build.append("BorderLayout\" borderLayoutAbsoluteCenter=\"");
build.append(b.isAbsoluteCenter());
build.append("\" ");
String north = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.NORTH);
String east = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.EAST);
String west = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.WEST);
String south = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.SOUTH);
String center = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.CENTER);
if (north != null) {
build.append("borderLayoutSwapNorth=\"");
build.append(north);
build.append("\" ");
}
if (east != null) {
build.append("borderLayoutSwapEast=\"");
build.append(east);
build.append("\" ");
}
if (west != null) {
build.append("borderLayoutSwapWest=\"");
build.append(west);
build.append("\" ");
}
if (south != null) {
build.append("borderLayoutSwapSouth=\"");
build.append(south);
build.append("\" ");
}
if (center != null) {
build.append("borderLayoutSwapCenter=\"");
build.append(center);
build.append("\" ");
}
} else {
if (l instanceof com.codename1.ui.layouts.GridLayout) {
build.append("GridLayout\" gridLayoutRows=\"");
build.append(((com.codename1.ui.layouts.GridLayout) l).getRows());
build.append("\" gridLayoutColumns=\"");
build.append(((com.codename1.ui.layouts.GridLayout) l).getColumns());
build.append("\" ");
} else {
if (l instanceof com.codename1.ui.layouts.BoxLayout) {
if (getInt("axis", l.getClass(), l) == com.codename1.ui.layouts.BoxLayout.X_AXIS) {
build.append("BoxLayout\" boxLayoutAxis=\"X\" ");
} else {
build.append("BoxLayout\" boxLayoutAxis=\"Y\" ");
}
} else {
if (l instanceof com.codename1.ui.table.TableLayout) {
build.append("TableLayout\" tableLayoutRows=\"");
build.append(((com.codename1.ui.table.TableLayout) l).getRows());
build.append("\" tableLayoutColumns=\"");
build.append(((com.codename1.ui.table.TableLayout) l).getColumns());
build.append("\" ");
} else {
if (l instanceof com.codename1.ui.layouts.LayeredLayout) {
build.append("LayeredLayout\" ");
}
}
}
}
}
}
}
if (cmp instanceof com.codename1.ui.Form) {
com.codename1.ui.Form frm = (com.codename1.ui.Form) cmp;
if (isPropertyModified(cmp, PROPERTY_NEXT_FORM) && frm.getClientProperty("%next_form%") != null) {
build.append("nextForm=\"");
build.append(xmlize((String) frm.getClientProperty("%next_form%")));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TITLE)) {
build.append("title=\"");
build.append(xmlize(frm.getTitle()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_CYCLIC_FOCUS)) {
build.append("cyclicFocus=\"");
build.append(frm.isCyclicFocus());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_DIALOG_UIID) && cmp instanceof com.codename1.ui.Dialog) {
com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
build.append("dialogUIID=\"");
build.append(dlg.getDialogUIID());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_DISPOSE_WHEN_POINTER_OUT) && cmp instanceof com.codename1.ui.Dialog) {
com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
build.append("disposeWhenPointerOutOfBounds=\"");
build.append(dlg.isDisposeWhenPointerOutOfBounds());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_DIALOG_POSITION) && cmp instanceof com.codename1.ui.Dialog) {
com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
if (dlg.getDialogPosition() != null) {
build.append("dialogPosition=\"");
build.append(dlg.getDialogPosition());
build.append("\" ");
}
}
build.append(">\n");
appendComponentXMLBody(containerInstance, cmp, build, res, indent + " ");
if (frm.getCommandCount() > 0 || frm.getBackCommand() != null) {
if (isPropertyModified(cmp, PROPERTY_COMMANDS) || isPropertyModified(cmp, PROPERTY_COMMANDS_LEGACY)) {
if (frm.getBackCommand() != null && !hasBackCommand(frm, frm.getBackCommand())) {
build.append("<command name=\"");
ActionCommand cmd = (ActionCommand) frm.getBackCommand();
if (exportToNewGuiBuilderMode) {
if (cmp.getComponentForm() != null) {
commandList.add(cmd);
cmd.putClientProperty("FORMNAME", cmp.getComponentForm().getName());
}
}
build.append(xmlize(cmd.getCommandName()));
build.append("\" ");
if (cmd.getIcon() != null) {
build.append("icon=\"");
build.append(xmlize(res.findId(cmd.getIcon())));
build.append("\" ");
}
if (cmd.getRolloverIcon() != null) {
build.append("rolloverIcon=\"");
build.append(xmlize(res.findId(cmd.getRolloverIcon())));
build.append("\" ");
}
if (cmd.getPressedIcon() != null) {
build.append("pressedIcon=\"");
build.append(xmlize(res.findId(cmd.getPressedIcon())));
build.append("\" ");
}
if (cmd.getDisabledIcon() != null) {
build.append("disabledIcon=\"");
build.append(xmlize(res.findId(cmd.getDisabledIcon())));
build.append("\" ");
}
build.append("id=\"");
build.append(cmd.getId());
build.append("\" ");
if (cmd.getAction() != null) {
build.append("action=\"");
build.append(xmlize(cmd.getAction()));
build.append("\" ");
if (cmd.getAction().equals("$Execute")) {
build.append("argument=\"");
build.append(xmlize(cmd.getArgument()));
build.append("\" ");
}
}
build.append("backCommand=\"");
build.append(frm.getBackCommand() == cmd);
build.append("\" />");
}
for (int iter = frm.getCommandCount() - 1; iter >= 0; iter--) {
ActionCommand cmd = (ActionCommand) frm.getCommand(iter);
if (exportToNewGuiBuilderMode) {
if (cmp.getComponentForm() != null) {
commandList.add(cmd);
cmd.putClientProperty("FORMNAME", cmp.getComponentForm().getName());
}
}
build.append("<command name=\"");
build.append(xmlize(cmd.getCommandName()));
build.append("\" ");
if (cmd.getIcon() != null) {
build.append("icon=\"");
build.append(xmlize(res.findId(cmd.getIcon())));
build.append("\" ");
}
if (cmd.getRolloverIcon() != null) {
build.append("rolloverIcon=\"");
build.append(xmlize(res.findId(cmd.getRolloverIcon())));
build.append("\" ");
}
if (cmd.getPressedIcon() != null) {
build.append("pressedIcon=\"");
build.append(xmlize(res.findId(cmd.getPressedIcon())));
build.append("\" ");
}
if (cmd.getDisabledIcon() != null) {
build.append("disabledIcon=\"");
build.append(xmlize(res.findId(cmd.getDisabledIcon())));
build.append("\" ");
}
build.append("id=\"");
build.append(cmd.getId());
build.append("\" ");
if (cmd.getAction() != null) {
build.append("action=\"");
build.append(xmlize(cmd.getAction()));
build.append("\" ");
if (cmd.getAction().equals("$Execute")) {
build.append("argument=\"");
build.append(xmlize(cmd.getArgument()));
build.append("\" ");
}
}
build.append("backCommand=\"");
build.append(frm.getBackCommand() == cmd);
build.append("\" />");
}
}
}
build.append(indent);
build.append("</component>\n");
} else {
if (!(cmp instanceof com.codename1.ui.list.ContainerList)) {
build.append(">\n");
appendComponentXMLBody(containerInstance, cmp, build, res, indent + " ");
build.append(indent);
build.append("</component>\n");
} else {
com.codename1.ui.list.ContainerList lst = ((com.codename1.ui.list.ContainerList) cmp);
if (isPropertyModified(cmp, PROPERTY_LIST_RENDERER) && lst.getRenderer() instanceof com.codename1.ui.list.GenericListCellRenderer) {
com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) lst.getRenderer();
if (g.getSelectedEven() == null) {
build.append(" selectedRenderer=\"");
build.append(xmlize(g.getSelected().getName()));
build.append("\" unselectedRenderer=\"");
build.append(xmlize(g.getUnselected().getName()));
build.append("\" ");
} else {
build.append(" selectedRenderer=\"");
build.append(xmlize(g.getSelected().getName()));
build.append("\" unselectedRenderer=\"");
build.append(xmlize(g.getUnselected().getName()));
build.append(" selectedRendererEven=\"");
build.append(xmlize(g.getSelectedEven().getName()));
build.append("\" unselectedRendererEven=\"");
build.append(xmlize(g.getUnselectedEven().getName()));
build.append("\" ");
}
}
build.append(">\n");
appendComponentXMLBody(containerInstance, cmp, build, res, indent + " ");
build.append(indent);
build.append("</component>\n");
}
}
}
} else {
if (cmp instanceof com.codename1.ui.Label) {
com.codename1.ui.Label lbl = (com.codename1.ui.Label) cmp;
build.append("text=\"");
build.append(xmlize(lbl.getText()));
build.append("\" ");
if (isPropertyModified(cmp, PROPERTY_ALIGNMENT)) {
build.append("alignment=\"");
build.append(lbl.getAlignment());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_ICON) && lbl.getIcon() != null) {
build.append("icon=\"");
build.append(xmlize(res.findId(lbl.getIcon())));
build.append("\" ");
}
if (lbl instanceof com.codename1.ui.Button) {
com.codename1.ui.Button button = (com.codename1.ui.Button) lbl;
if (isPropertyModified(cmp, PROPERTY_ROLLOVER_ICON) && button.getRolloverIcon() != null) {
build.append("rolloverIcon=\"");
build.append(xmlize(res.findId(button.getRolloverIcon())));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_PRESSED_ICON) && button.getPressedIcon() != null) {
build.append("pressedIcon=\"");
build.append(xmlize(res.findId(button.getPressedIcon())));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_DISABLED_ICON) && button.getDisabledIcon() != null) {
build.append("disabledIcon=\"");
build.append(xmlize(res.findId(button.getDisabledIcon())));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TOGGLE_BUTTON)) {
build.append("toggle=\"");
build.append(button.isToggle());
build.append("\" ");
}
} else {
if (lbl instanceof com.codename1.ui.Slider) {
com.codename1.ui.Slider sld = (com.codename1.ui.Slider) lbl;
if (isPropertyModified(cmp, PROPERTY_EDITABLE)) {
build.append("editable=\"");
build.append(sld.isEditable());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_INFINITE)) {
build.append("infinite=\"");
build.append(sld.isInfinite());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_SLIDER_THUMB) && sld.getThumbImage() != null) {
build.append("thumbImage=\"");
build.append(xmlize(res.findId(sld.getThumbImage())));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_PROGRESS)) {
build.append("progress=\"");
build.append(sld.getProgress());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_VERTICAL)) {
build.append("vertical=\"");
build.append(sld.isVertical());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_INCREMENTS)) {
build.append("increments=\"");
build.append(sld.getIncrements());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_MAX_VALUE)) {
build.append("maxValue=\"");
build.append(sld.getMaxValue());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_MIN_VALUE)) {
build.append("minValue=\"");
build.append(sld.getMinValue());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_RENDER_PERCENTAGE_ON_TOP)) {
build.append("renderPercentageOnTop=\"");
build.append(sld.isRenderPercentageOnTop());
build.append("\" ");
}
}
}
if (isPropertyModified(cmp, PROPERTY_RADIO_GROUP)) {
build.append("group=\"");
build.append(xmlize(((com.codename1.ui.RadioButton) cmp).getGroup()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_SELECTED)) {
build.append("selected=\"");
build.append(((com.codename1.ui.Button) cmp).isSelected());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_GAP)) {
build.append("gap=\"");
build.append(lbl.getGap());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_VERTICAL_ALIGNMENT)) {
build.append("verticalAlignment=\"");
build.append(lbl.getVerticalAlignment());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TEXT_POSITION)) {
build.append("textPosition=\"");
build.append(lbl.getTextPosition());
build.append("\" ");
}
} else {
if (cmp instanceof com.codename1.ui.TextArea) {
com.codename1.ui.TextArea txt = (com.codename1.ui.TextArea) cmp;
if (isPropertyModified(cmp, PROPERTY_VERTICAL_ALIGNMENT)) {
build.append("verticalAlignment=\"");
build.append(txt.getVerticalAlignment());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TEXT)) {
build.append("text=\"");
build.append(xmlize(txt.getText()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TEXT_AREA_GROW)) {
build.append("growByContent=\"");
build.append(txt.isGrowByContent());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TEXT_CONSTRAINT)) {
build.append("constraint=\"");
build.append(txt.getConstraint());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_TEXT_MAX_LENGTH)) {
build.append("maxSize=\"");
build.append(txt.getMaxSize());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_EDITABLE)) {
build.append("editable=\"");
build.append(txt.isEditable());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_ALIGNMENT)) {
build.append("alignment=\"");
build.append(txt.getAlignment());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_HINT)) {
build.append("hint=\"");
build.append(xmlize(txt.getHint()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_HINT_ICON) && txt.getHintIcon() != null) {
build.append("hintIcon=\"");
build.append(xmlize(res.findId(txt.getHintIcon())));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_COLUMNS)) {
build.append("columns=\"");
build.append(txt.getColumns());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_ROWS)) {
build.append("rows=\"");
build.append(txt.getRows());
build.append("\" ");
}
} else {
if (cmp instanceof com.codename1.ui.List) {
com.codename1.ui.List lst = (com.codename1.ui.List) cmp;
if (isPropertyModified(cmp, PROPERTY_ITEM_GAP)) {
build.append("itemGap=\"");
build.append(lst.getItemGap());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_LIST_FIXED)) {
build.append("fixedSelection=\"");
build.append(lst.getFixedSelection());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_LIST_ORIENTATION)) {
build.append("orientation=\"");
build.append(lst.getOrientation());
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_HINT)) {
build.append("hint=\"");
build.append(xmlize(lst.getHint()));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_HINT_ICON) && lst.getHintIcon() != null) {
build.append("hintIcon=\"");
build.append(xmlize(res.findId(lst.getHintIcon())));
build.append("\" ");
}
if (isPropertyModified(cmp, PROPERTY_LIST_RENDERER) && lst.getRenderer() instanceof com.codename1.ui.list.GenericListCellRenderer) {
com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) lst.getRenderer();
if (g.getSelectedEven() == null) {
build.append(" selectedRenderer=\"");
build.append(xmlize(g.getSelected().getName()));
build.append("\" unselectedRenderer=\"");
build.append(xmlize(g.getUnselected().getName()));
build.append("\" ");
} else {
build.append(" selectedRenderer=\"");
build.append(xmlize(g.getSelected().getName()));
build.append("\" unselectedRenderer=\"");
build.append(xmlize(g.getUnselected().getName()));
build.append(" selectedRendererEven=\"");
build.append(xmlize(g.getSelectedEven().getName()));
build.append("\" unselectedRendererEven=\"");
build.append(xmlize(g.getUnselectedEven().getName()));
build.append("\" ");
}
}
}
}
}
build.append(">\n");
appendComponentXMLBody(containerInstance, cmp, build, res, indent + " ");
build.append(indent);
build.append("</component>\n");
}
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class UIBuilderOverride method createInstance.
/**
* Create a component instance from XML
*/
private Component createInstance(final ComponentEntry root, final EditableResources res, Container rootCnt, final Container parentContainer, final ArrayList<Runnable> postCreateTasks) {
try {
final Component c = createComponentType(root.getType());
if (rootCnt == null) {
rootCnt = (Container) c;
}
final Container rootContainer = rootCnt;
if (root.getBaseForm() != null) {
c.putClientProperty("%base_form%", root.getBaseForm());
}
c.putClientProperty(TYPE_KEY, root.getType());
c.setName(root.getName());
String clientProps = root.getClientProperties();
if (clientProps != null && clientProps.length() > 0) {
String[] props = clientProps.split(",");
StringBuilder b = new StringBuilder();
for (String p : props) {
String[] keyVal = p.split("=");
c.putClientProperty(keyVal[0], keyVal[1]);
if (b.length() > 0) {
b.append(",");
}
b.append(keyVal[0]);
}
c.putClientProperty("cn1$Properties", b.toString());
}
rootContainer.putClientProperty("%" + root.getName() + "%", c);
// layout must be first since we might need to rely on it later on with things such as constraints
if (root.getLayout() != null) {
modifyingProperty(c, PROPERTY_LAYOUT);
Layout l;
if (root.getLayout().equals("BorderLayout")) {
l = new BorderLayout();
if (root.isBorderLayoutAbsoluteCenter() != null) {
((BorderLayout) l).setAbsoluteCenter(root.isBorderLayoutAbsoluteCenter().booleanValue());
}
if (root.getBorderLayoutSwapCenter() != null) {
((BorderLayout) l).defineLandscapeSwap(BorderLayout.CENTER, root.getBorderLayoutSwapCenter());
}
if (root.getBorderLayoutSwapNorth() != null) {
((BorderLayout) l).defineLandscapeSwap(BorderLayout.NORTH, root.getBorderLayoutSwapNorth());
}
if (root.getBorderLayoutSwapSouth() != null) {
((BorderLayout) l).defineLandscapeSwap(BorderLayout.SOUTH, root.getBorderLayoutSwapSouth());
}
if (root.getBorderLayoutSwapEast() != null) {
((BorderLayout) l).defineLandscapeSwap(BorderLayout.EAST, root.getBorderLayoutSwapEast());
}
if (root.getBorderLayoutSwapWest() != null) {
((BorderLayout) l).defineLandscapeSwap(BorderLayout.WEST, root.getBorderLayoutSwapWest());
}
} else {
if (root.getLayout().equals("FlowLayout")) {
l = new FlowLayout();
((FlowLayout) l).setFillRows(root.isFlowLayoutFillRows());
((FlowLayout) l).setAlign(root.getFlowLayoutAlign());
((FlowLayout) l).setValign(root.getFlowLayoutValign());
} else {
if (root.getLayout().equals("GridLayout")) {
l = new GridLayout(root.getGridLayoutRows().intValue(), root.getGridLayoutColumns().intValue());
} else {
if (root.getLayout().equals("BoxLayout")) {
if (root.getBoxLayoutAxis().equals("X")) {
l = new BoxLayout(BoxLayout.X_AXIS);
} else {
l = new BoxLayout(BoxLayout.Y_AXIS);
}
} else {
if (root.getLayout().equals("TableLayout")) {
l = new TableLayout(root.getTableLayoutRows(), root.getTableLayoutColumns());
} else {
l = new LayeredLayout();
}
}
}
}
}
((Container) c).setLayout(l);
}
if (parentContainer != null && root.getLayoutConstraint() != null) {
modifyingProperty(c, PROPERTY_LAYOUT_CONSTRAINT);
if (parentContainer.getLayout() instanceof BorderLayout) {
c.putClientProperty("layoutConstraint", root.getLayoutConstraint().getValue());
} else {
TableLayout tl = (TableLayout) parentContainer.getLayout();
TableLayout.Constraint con = tl.createConstraint(root.getLayoutConstraint().getRow(), root.getLayoutConstraint().getColumn());
con.setHeightPercentage(root.getLayoutConstraint().getHeight());
con.setWidthPercentage(root.getLayoutConstraint().getWidth());
con.setHorizontalAlign(root.getLayoutConstraint().getAlign());
con.setHorizontalSpan(root.getLayoutConstraint().getSpanHorizontal());
con.setVerticalAlign(root.getLayoutConstraint().getValign());
con.setVerticalSpan(root.getLayoutConstraint().getSpanVertical());
c.putClientProperty("layoutConstraint", con);
}
}
if (root.getEmbed() != null && root.getEmbed().length() > 0) {
modifyingProperty(c, PROPERTY_EMBED);
rootContainer.putClientProperty(EMBEDDED_FORM_FLAG, "");
((EmbeddedContainer) c).setEmbed(root.getEmbed());
Container embed = createContainer(res, root.getEmbed(), (EmbeddedContainer) c);
if (embed != null) {
if (embed instanceof Form) {
embed = formToContainer((Form) embed);
}
((EmbeddedContainer) c).addComponent(BorderLayout.CENTER, embed);
// this isn't exactly the "right thing" but its the best we can do to make all
// use cases work
beforeShowContainer(embed);
postShowContainer(embed);
}
}
if (root.isToggle() != null) {
modifyingProperty(c, PROPERTY_TOGGLE_BUTTON);
((Button) c).setToggle(root.isToggle().booleanValue());
}
if (root.getGroup() != null) {
modifyingProperty(c, PROPERTY_RADIO_GROUP);
((RadioButton) c).setGroup(root.getGroup());
}
if (root.isSelected() != null) {
modifyingProperty(c, PROPERTY_SELECTED);
if (c instanceof RadioButton) {
((RadioButton) c).setSelected(root.isSelected().booleanValue());
} else {
((CheckBox) c).setSelected(root.isSelected().booleanValue());
}
}
if (root.isScrollableX() != null) {
modifyingProperty(c, PROPERTY_SCROLLABLE_X);
((Container) c).setScrollableX(root.isScrollableX().booleanValue());
}
if (root.isScrollableY() != null) {
modifyingProperty(c, PROPERTY_SCROLLABLE_Y);
((Container) c).setScrollableY(root.isScrollableY().booleanValue());
}
if (root.isTensileDragEnabled() != null) {
modifyingProperty(c, PROPERTY_TENSILE_DRAG_ENABLED);
c.setTensileDragEnabled(root.isTensileDragEnabled().booleanValue());
}
if (root.isTactileTouch() != null) {
modifyingProperty(c, PROPERTY_TACTILE_TOUCH);
c.setTactileTouch(root.isTactileTouch().booleanValue());
}
if (root.isSnapToGrid() != null) {
modifyingProperty(c, PROPERTY_SNAP_TO_GRID);
c.setSnapToGrid(root.isSnapToGrid().booleanValue());
}
if (root.isFlatten() != null) {
modifyingProperty(c, PROPERTY_FLATTEN);
c.setFlatten(root.isFlatten().booleanValue());
}
if (root.getText() != null) {
modifyingProperty(c, PROPERTY_TEXT);
if (c instanceof Label) {
((Label) c).setText(root.getText());
} else {
((TextArea) c).setText(root.getText());
}
}
if (root.getMaxSize() != null) {
modifyingProperty(c, PROPERTY_TEXT_MAX_LENGTH);
((TextArea) c).setMaxSize(root.getMaxSize().intValue());
}
if (root.getConstraint() != null) {
modifyingProperty(c, PROPERTY_TEXT_CONSTRAINT);
((TextArea) c).setConstraint(root.getConstraint().intValue());
}
if (root.getAlignment() != null) {
modifyingProperty(c, PROPERTY_ALIGNMENT);
if (c instanceof Label) {
((Label) c).setAlignment(root.getAlignment().intValue());
} else {
((TextArea) c).setAlignment(root.getAlignment().intValue());
}
}
if (root.isGrowByContent() != null) {
modifyingProperty(c, PROPERTY_TEXT_AREA_GROW);
((TextArea) c).setGrowByContent(root.isGrowByContent().booleanValue());
}
if (root.getTabPlacement() != null) {
modifyingProperty(c, PROPERTY_TAB_PLACEMENT);
((Tabs) c).setTabPlacement(root.getTabPlacement().intValue());
}
if (root.getTabTextPosition() != null) {
modifyingProperty(c, PROPERTY_TAB_TEXT_POSITION);
((Tabs) c).setTabTextPosition(root.getTabTextPosition().intValue());
}
if (root.getUiid() != null) {
modifyingProperty(c, PROPERTY_UIID);
c.setUIID(root.getUiid());
}
if (root.getDialogUIID() != null) {
modifyingProperty(c, PROPERTY_DIALOG_UIID);
((Dialog) c).setDialogUIID(root.getDialogUIID());
}
if (root.isDisposeWhenPointerOutOfBounds() != null) {
modifyingProperty(c, PROPERTY_DISPOSE_WHEN_POINTER_OUT);
((Dialog) c).setDisposeWhenPointerOutOfBounds(root.isDisposeWhenPointerOutOfBounds());
}
if (root.getCloudBoundProperty() != null) {
modifyingProperty(c, PROPERTY_CLOUD_BOUND_PROPERTY);
c.setCloudBoundProperty(root.getCloudBoundProperty());
}
if (root.getCloudDestinationProperty() != null) {
modifyingProperty(c, PROPERTY_CLOUD_DESTINATION_PROPERTY);
c.setCloudDestinationProperty(root.getCloudDestinationProperty());
}
if (root.getDialogPosition() != null && root.getDialogPosition().length() > 0) {
modifyingProperty(c, PROPERTY_DIALOG_POSITION);
((Dialog) c).setDialogPosition(root.getDialogPosition());
}
if (root.isFocusable() != null) {
modifyingProperty(c, PROPERTY_FOCUSABLE);
c.setFocusable(root.isFocusable().booleanValue());
}
if (root.isEnabled() != null) {
modifyingProperty(c, PROPERTY_ENABLED);
c.setEnabled(root.isEnabled().booleanValue());
}
if (root.isScrollVisible() != null) {
modifyingProperty(c, PROPERTY_SCROLL_VISIBLE);
c.setScrollVisible(root.isScrollVisible().booleanValue());
}
if (root.getIcon() != null) {
modifyingProperty(c, PROPERTY_ICON);
((Label) c).setIcon(res.getImage(root.getIcon()));
}
if (root.getRolloverIcon() != null) {
modifyingProperty(c, PROPERTY_ROLLOVER_ICON);
((Button) c).setRolloverIcon(res.getImage(root.getRolloverIcon()));
}
if (root.getPressedIcon() != null) {
modifyingProperty(c, PROPERTY_PRESSED_ICON);
((Button) c).setPressedIcon(res.getImage(root.getPressedIcon()));
}
if (root.getDisabledIcon() != null) {
modifyingProperty(c, PROPERTY_DISABLED_ICON);
((Button) c).setDisabledIcon(res.getImage(root.getDisabledIcon()));
}
if (root.getGap() != null) {
modifyingProperty(c, PROPERTY_GAP);
((Label) c).setGap(root.getGap().intValue());
}
if (root.getVerticalAlignment() != null) {
modifyingProperty(c, PROPERTY_VERTICAL_ALIGNMENT);
if (c instanceof Label) {
((Label) c).setVerticalAlignment(root.getVerticalAlignment().intValue());
} else {
((TextArea) c).setVerticalAlignment(root.getVerticalAlignment().intValue());
}
}
if (root.getTextPosition() != null) {
modifyingProperty(c, PROPERTY_TEXT_POSITION);
((Label) c).setTextPosition(root.getTextPosition().intValue());
}
if (root.getTitle() != null) {
modifyingProperty(c, PROPERTY_TITLE);
((Form) c).setTitle(root.getTitle());
}
// components should be added when we've set everything else up
if (root.getComponent() != null) {
modifyingProperty(c, PROPERTY_COMPONENTS);
if (c instanceof Tabs) {
for (ComponentEntry ent : root.getComponent()) {
Component newCmp = createInstance(ent, res, rootContainer, (Container) c, postCreateTasks);
((Tabs) c).addTab(ent.getTabTitle(), newCmp);
}
} else {
for (ComponentEntry ent : root.getComponent()) {
Component newCmp = createInstance(ent, res, rootContainer, (Container) c, postCreateTasks);
Object cons = newCmp.getClientProperty("layoutConstraint");
if (cons != null) {
modifyingProperty(c, PROPERTY_LAYOUT_CONSTRAINT);
((Container) c).addComponent(cons, newCmp);
} else {
((Container) c).addComponent(newCmp);
}
}
}
}
if (root.getColumns() != null) {
modifyingProperty(c, PROPERTY_COLUMNS);
((TextArea) c).setColumns(root.getColumns().intValue());
}
if (root.getRows() != null) {
modifyingProperty(c, PROPERTY_ROWS);
((TextArea) c).setRows(root.getRows().intValue());
}
if (root.getHint() != null) {
modifyingProperty(c, PROPERTY_HINT);
if (c instanceof List) {
((List) c).setHint(root.getHint());
} else {
((TextArea) c).setHint(root.getHint());
}
}
if (root.getHintIcon() != null) {
modifyingProperty(c, PROPERTY_HINT_ICON);
if (c instanceof List) {
((List) c).setHintIcon(res.getImage(root.getHint()));
} else {
((TextArea) c).setHintIcon(res.getImage(root.getHint()));
}
}
if (root.getItemGap() != null) {
modifyingProperty(c, PROPERTY_ITEM_GAP);
((List) c).setItemGap(root.getItemGap().intValue());
}
if (root.getFixedSelection() != null) {
modifyingProperty(c, PROPERTY_LIST_FIXED);
((List) c).setFixedSelection(root.getFixedSelection().intValue());
}
if (root.getOrientation() != null) {
modifyingProperty(c, PROPERTY_LIST_ORIENTATION);
((List) c).setOrientation(root.getOrientation().intValue());
}
if (c instanceof com.codename1.ui.List && !(c instanceof com.codename1.components.RSSReader)) {
modifyingProperty(c, PROPERTY_LIST_ITEMS);
if (root.getStringItem() != null && root.getStringItem().length > 0) {
String[] arr = new String[root.getStringItem().length];
for (int iter = 0; iter < arr.length; iter++) {
arr[iter] = root.getStringItem()[iter].getValue();
}
((List) c).setModel(new DefaultListModel<String>(arr));
} else {
if (root.getMapItems() != null && root.getMapItems().length > 0) {
Hashtable[] arr = new Hashtable[root.getMapItems().length];
for (int iter = 0; iter < arr.length; iter++) {
arr[iter] = new Hashtable();
if (root.getMapItems()[iter].getActionItem() != null) {
for (Val v : root.getMapItems()[iter].getActionItem()) {
Command cmd = createCommandImpl((String) v.getValue(), null, -1, v.getValue(), false, "");
cmd.putClientProperty(COMMAND_ACTION, (String) v.getValue());
arr[iter].put(v.getKey(), cmd);
}
}
if (root.getMapItems()[iter].getStringItem() != null) {
for (Val v : root.getMapItems()[iter].getActionItem()) {
arr[iter].put(v.getKey(), v.getValue());
}
}
if (root.getMapItems()[iter].getImageItem() != null) {
for (Val v : root.getMapItems()[iter].getActionItem()) {
arr[iter].put(v.getKey(), res.getImage(v.getValue()));
}
}
}
((List) c).setModel(new DefaultListModel<java.util.Map>(arr));
}
}
}
if (root.getSelectedRenderer() != null) {
modifyingProperty(c, PROPERTY_LIST_RENDERER);
GenericListCellRenderer g;
if (root.getSelectedRendererEven() == null) {
Component selected = createContainer(res, root.getSelectedRenderer());
Component unselected = createContainer(res, root.getUnselectedRenderer());
g = new GenericListCellRenderer(selected, unselected);
g.setFisheye(!root.getSelectedRenderer().equals(root.getUnselectedRenderer()));
} else {
Component selected = createContainer(res, root.getSelectedRenderer());
Component unselected = createContainer(res, root.getUnselectedRenderer());
Component even = createContainer(res, root.getSelectedRendererEven());
Component evenU = createContainer(res, root.getUnselectedRendererEven());
g = new GenericListCellRenderer(selected, unselected, even, evenU);
g.setFisheye(!root.getSelectedRenderer().equals(root.getUnselectedRenderer()));
}
if (c instanceof ContainerList) {
((ContainerList) c).setRenderer(g);
} else {
((List) c).setRenderer(g);
}
}
if (root.getNextForm() != null && root.getNextForm().length() > 0) {
modifyingProperty(c, PROPERTY_NEXT_FORM);
setNextForm(c, root.getNextForm(), res, rootContainer);
}
if (root.getCommand() != null) {
modifyingProperty(c, PROPERTY_COMMANDS);
for (CommandEntry cmd : root.getCommand()) {
Command currentCommand = createCommandImpl(cmd.getName(), res.getImage(cmd.getIcon()), cmd.getId(), cmd.getAction(), cmd.isBackCommand(), cmd.getArgument());
if (cmd.getRolloverIcon() != null && cmd.getRolloverIcon().length() > 0) {
currentCommand.setRolloverIcon(res.getImage(cmd.getRolloverIcon()));
}
if (cmd.getPressedIcon() != null && cmd.getPressedIcon().length() > 0) {
currentCommand.setPressedIcon(res.getImage(cmd.getPressedIcon()));
}
if (cmd.getDisabledIcon() != null && cmd.getDisabledIcon().length() > 0) {
currentCommand.setDisabledIcon(res.getImage(cmd.getDisabledIcon()));
}
if (cmd.isBackCommand()) {
((Form) c).setBackCommand(currentCommand);
}
((Form) c).addCommand(currentCommand);
currentCommand.putClientProperty(COMMAND_ARGUMENTS, cmd.getArgument());
currentCommand.putClientProperty(COMMAND_ACTION, cmd.getAction());
}
}
if (root.isCyclicFocus() != null) {
modifyingProperty(c, PROPERTY_CYCLIC_FOCUS);
((Form) c).setCyclicFocus(root.isCyclicFocus().booleanValue());
}
if (root.isRtl() != null) {
modifyingProperty(c, PROPERTY_RTL);
c.setRTL(root.isRtl().booleanValue());
}
if (root.getThumbImage() != null) {
modifyingProperty(c, PROPERTY_SLIDER_THUMB);
((Slider) c).setThumbImage(res.getImage(root.getThumbImage()));
}
if (root.isInfinite() != null) {
modifyingProperty(c, PROPERTY_INFINITE);
((Slider) c).setInfinite(root.isInfinite().booleanValue());
}
if (root.getProgress() != null) {
modifyingProperty(c, PROPERTY_PROGRESS);
((Slider) c).setProgress(root.getProgress().intValue());
}
if (root.isVertical() != null) {
modifyingProperty(c, PROPERTY_VERTICAL);
((Slider) c).setVertical(root.isVertical().booleanValue());
}
if (root.isEditable() != null) {
modifyingProperty(c, PROPERTY_EDITABLE);
if (c instanceof TextArea) {
((TextArea) c).setEditable(root.isEditable().booleanValue());
} else {
((Slider) c).setEditable(root.isEditable().booleanValue());
}
}
if (root.getIncrements() != null) {
modifyingProperty(c, PROPERTY_INCREMENTS);
((Slider) c).setIncrements(root.getIncrements().intValue());
}
if (root.isRenderPercentageOnTop() != null) {
modifyingProperty(c, PROPERTY_RENDER_PERCENTAGE_ON_TOP);
((Slider) c).setRenderPercentageOnTop(root.isRenderPercentageOnTop().booleanValue());
}
if (root.getMaxValue() != null) {
modifyingProperty(c, PROPERTY_MAX_VALUE);
((Slider) c).setMaxValue(root.getMaxValue().intValue());
}
if (root.getMinValue() != null) {
modifyingProperty(c, PROPERTY_MIN_VALUE);
((Slider) c).setMinValue(root.getMinValue().intValue());
}
if (root.getCommandName() != null) {
modifyingProperty(c, PROPERTY_COMMAND);
postCreateTasks.add(new Runnable() {
public void run() {
Command cmd = createCommandImpl(root.getCommandName(), res.getImage(root.getCommandIcon()), root.getCommandId().intValue(), root.getCommandAction(), root.isCommandBack().booleanValue(), root.getCommandArgument());
if (c instanceof Container) {
Button b = (Button) ((Container) c).getLeadComponent();
b.setCommand(cmd);
return;
}
((Button) c).setCommand(cmd);
}
});
}
if (root.getLabelFor() != null) {
modifyingProperty(c, PROPERTY_LABEL_FOR);
postCreateTasks.add(new Runnable() {
public void run() {
((Label) c).setLabelForComponent((Label) findByName(root.getLabelFor(), rootContainer));
}
});
}
if (root.getLeadComponent() != null) {
modifyingProperty(c, PROPERTY_LEAD_COMPONENT);
postCreateTasks.add(new Runnable() {
public void run() {
((Container) c).setLeadComponent(findByName(root.getLeadComponent(), rootContainer));
}
});
}
if (root.getNextFocusUp() != null) {
modifyingProperty(c, PROPERTY_NEXT_FOCUS_UP);
postCreateTasks.add(new Runnable() {
public void run() {
c.setNextFocusUp(findByName(root.getNextFocusUp(), rootContainer));
}
});
}
if (root.getNextFocusDown() != null) {
modifyingProperty(c, PROPERTY_NEXT_FOCUS_DOWN);
postCreateTasks.add(new Runnable() {
public void run() {
c.setNextFocusDown(findByName(root.getNextFocusDown(), rootContainer));
}
});
}
if (root.getNextFocusLeft() != null) {
modifyingProperty(c, PROPERTY_NEXT_FOCUS_LEFT);
postCreateTasks.add(new Runnable() {
public void run() {
c.setNextFocusLeft(findByName(root.getNextFocusLeft(), rootContainer));
}
});
}
if (root.getNextFocusRight() != null) {
modifyingProperty(c, PROPERTY_NEXT_FOCUS_RIGHT);
postCreateTasks.add(new Runnable() {
public void run() {
c.setNextFocusRight(findByName(root.getNextFocusRight(), rootContainer));
}
});
}
// custom settings are always last after all other properties
if (root.getCustom() != null && root.getCustom().length > 0) {
modifyingProperty(c, PROPERTY_CUSTOM);
for (Custom cust : root.getCustom()) {
modifyingCustomProperty(c, cust.getName());
Object value = null;
Class customType = UserInterfaceEditor.getPropertyCustomType(c, cust.getName());
if (customType.isArray()) {
if (customType == String[].class) {
if (cust.getStr() != null) {
String[] arr = new String[cust.getStr().length];
for (int iter = 0; iter < arr.length; iter++) {
arr[iter] = cust.getStr()[iter].getValue();
}
c.setPropertyValue(cust.getName(), arr);
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == String[][].class) {
if (cust.getArr() != null) {
String[][] arr = new String[cust.getArr().length][];
for (int iter = 0; iter < arr.length; iter++) {
if (cust.getArr()[iter] != null && cust.getArr()[iter].getValue() != null) {
arr[iter] = new String[cust.getArr()[iter].getValue().length];
for (int inter = 0; inter < arr[iter].length; inter++) {
arr[iter][inter] = cust.getArr()[iter].getValue()[inter].getValue();
}
}
}
c.setPropertyValue(cust.getName(), arr);
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == com.codename1.ui.Image[].class) {
if (cust.getStr() != null) {
com.codename1.ui.Image[] arr = new com.codename1.ui.Image[cust.getStr().length];
for (int iter = 0; iter < arr.length; iter++) {
arr[iter] = res.getImage(cust.getStr()[iter].getValue());
}
c.setPropertyValue(cust.getName(), arr);
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Object[].class) {
if (cust.getStringItem() != null) {
String[] arr = new String[cust.getStringItem().length];
for (int iter = 0; iter < arr.length; iter++) {
arr[iter] = cust.getStringItem()[iter].getValue();
}
c.setPropertyValue(cust.getName(), arr);
continue;
} else {
if (cust.getMapItems() != null) {
Hashtable[] arr = new Hashtable[cust.getMapItems().length];
for (int iter = 0; iter < arr.length; iter++) {
arr[iter] = new Hashtable();
if (cust.getMapItems()[iter].getActionItem() != null) {
for (Val v : cust.getMapItems()[iter].getActionItem()) {
Command cmd = createCommandImpl(v.getValue(), null, -1, v.getValue(), false, "");
cmd.putClientProperty(COMMAND_ACTION, v.getValue());
value = cmd;
arr[iter].put(v.getKey(), cmd);
}
}
if (cust.getMapItems()[iter].getStringItem() != null) {
for (Val v : cust.getMapItems()[iter].getActionItem()) {
arr[iter].put(v.getKey(), v.getValue());
}
}
if (cust.getMapItems()[iter].getImageItem() != null) {
for (Val v : cust.getMapItems()[iter].getActionItem()) {
arr[iter].put(v.getKey(), res.getImage(v.getValue()));
}
}
}
c.setPropertyValue(cust.getName(), arr);
continue;
}
}
c.setPropertyValue(cust.getName(), null);
continue;
}
}
if (customType == String.class) {
c.setPropertyValue(cust.getName(), cust.getValue());
continue;
}
if (customType == Integer.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), Integer.valueOf(cust.getValue()));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Long.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), Long.valueOf(cust.getValue()));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Double.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), Double.valueOf(cust.getValue()));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Date.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), new Date(Long.parseLong(cust.getValue())));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Float.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), Float.valueOf(cust.getValue()));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Byte.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), Byte.valueOf(cust.getValue()));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Character.class) {
if (cust.getValue() != null && ((String) cust.getValue()).length() > 0) {
c.setPropertyValue(cust.getName(), new Character(((String) cust.getValue()).charAt(0)));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == Boolean.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), Boolean.valueOf(cust.getValue()));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == com.codename1.ui.Image.class) {
if (cust.getValue() != null) {
c.setPropertyValue(cust.getName(), res.getImage(cust.getValue()));
} else {
c.setPropertyValue(cust.getName(), null);
}
continue;
}
if (customType == com.codename1.ui.Container.class) {
// resource might have been removed we need to fail gracefully
String[] uiNames = res.getUIResourceNames();
for (int iter = 0; iter < uiNames.length; iter++) {
if (uiNames[iter].equals(cust.getName())) {
c.setPropertyValue(cust.getName(), createContainer(res, cust.getName()));
continue;
}
}
c.setPropertyValue(cust.getName(), null);
continue;
}
if (customType == com.codename1.ui.list.CellRenderer.class) {
if (cust.getUnselectedRenderer() != null) {
GenericListCellRenderer g;
if (cust.getSelectedRendererEven() == null) {
Component selected = createContainer(res, cust.getSelectedRenderer());
Component unselected = createContainer(res, cust.getUnselectedRenderer());
g = new GenericListCellRenderer(selected, unselected);
g.setFisheye(!cust.getSelectedRenderer().equals(cust.getUnselectedRenderer()));
} else {
Component selected = createContainer(res, cust.getSelectedRenderer());
Component unselected = createContainer(res, cust.getUnselectedRenderer());
Component even = createContainer(res, cust.getSelectedRendererEven());
Component evenU = createContainer(res, cust.getUnselectedRendererEven());
g = new GenericListCellRenderer(selected, unselected, even, evenU);
g.setFisheye(!cust.getSelectedRenderer().equals(cust.getUnselectedRenderer()));
}
c.setPropertyValue(cust.getName(), g);
continue;
}
c.setPropertyValue(cust.getName(), null);
continue;
}
}
}
return c;
} catch (Throwable t) {
t.printStackTrace();
JOptionPane.showMessageDialog(java.awt.Frame.getFrames()[0], "Error creating component: " + root.getName() + "\n" + t.toString() + "\ntrying to recover...", "Error", JOptionPane.ERROR_MESSAGE);
return null;
}
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class HTMLComponent method processTag.
/**
* Processes the given tag. This is the main processing method that calls all others and uses itself in a recursive manner.
*
* @param element The element to process
* @param align The current alignment
*/
private void processTag(HTMLElement element, int align) {
if ((cancelled) && (!cancelledCaught)) {
return;
}
int curAlign = align;
HTMLFont oldFont = font;
int oldFontColor = textColor;
for (int i = 0; i < element.getNumChildren(); i++) {
if ((cancelled) && (!cancelledCaught)) {
break;
}
HTMLElement child = (HTMLElement) element.getChildAt(i);
// Process Tag Open
switch(child.getTagId()) {
case HTMLElement.TAG_TEXT:
// String text=child.getAttributeById(HTMLElement.ATTR_TITLE);
String text = child.getText();
if ((curComboBox != null) && (optionTag)) {
// Text is inside an OPTION tag, i.e. belongs to a ComboBox
OptionItem oi = new OptionItem(text, optionValue);
curComboBox.addItem(oi);
if (optionSelected) {
curComboBox.setSelectedItem(oi);
if (curForm != null) {
curForm.setDefaultValue(curComboBox, oi);
}
}
} else if (curTextArea != null) {
// Text is inside of a TEXTAREA tag
curTextArea.setText(text);
if (curForm != null) {
curForm.setDefaultValue(curTextArea, text);
}
} else if (element.getTagId() == HTMLElement.TAG_LEGEND) {
// Note: this is element, i.e. the child's parent (child is TAG_TEXT, and if parent is TAG_LEGEND then we process this block)
if (fieldsets.size() > 0) {
Container fset = (Container) fieldsets.lastElement();
fset.getStyle().setBorder(Border.createLineBorder(1, text));
fset.getStyle().setPadding(Component.TOP, fset.getStyle().getFont().getHeight() + 1);
}
} else if ((curTable != null) && (element.getTagId() == HTMLElement.TAG_CAPTION)) {
// Note: this is element, i.e. the child's parent (child is TAG_TEXT, and if parent is TAG_LEGEND then we process this block)
curTable.captionTextTag = child;
} else {
// long startTextTime=System.currentTimeMillis(); //debug code for performance measurement
Vector comps = null;
if (preTagCount != 0) {
comps = showPreTagText(text, curAlign);
} else {
if (FIXED_WIDTH) {
comps = showTextFixedWidth(text, curAlign);
} else {
comps = showText(text, curAlign);
}
}
if (loadCSS) {
child.setAssociatedComponents(comps);
}
// textTime+=(System.currentTimeMillis()-startTextTime); //debug code for performance measurement
}
break;
case HTMLElement.TAG_A:
link = child.getAttributeById(HTMLElement.ATTR_HREF);
if ((link != null) && (docInfo == null) && (!DocumentInfo.isAbsoluteURL(link))) {
if (htmlCallback != null) {
htmlCallback.parsingError(HTMLCallback.ERROR_NO_BASE_URL, child.getTagName(), child.getAttributeName(new Integer(HTMLElement.ATTR_HREF)), link, "Disabling relative link (" + link + "), since page was set by setBody/setHTML/setDOM so there's no way to access relative URLs");
}
link = null;
}
if ((link != null) && (htmlCallback != null)) {
int linkProps = htmlCallback.getLinkProperties(this, convertURL(link));
if ((linkProps & HTMLCallback.LINK_FORBIDDEN) != 0) {
link = null;
} else if ((linkProps & HTMLCallback.LINK_VISTED) != 0) {
linkVisited = true;
}
}
anchor = child.getAttributeById(HTMLElement.ATTR_NAME);
if (link != null) {
String aKey = child.getAttributeById(HTMLElement.ATTR_ACCESSKEY);
if ((aKey != null) && (aKey.length() == 1)) {
accesskey = aKey.charAt(0);
}
}
break;
case HTMLElement.TAG_H1:
case HTMLElement.TAG_H2:
case HTMLElement.TAG_H3:
case HTMLElement.TAG_H4:
case HTMLElement.TAG_H5:
case HTMLElement.TAG_H6:
font = (HTMLFont) fonts.get(child.getTagName());
if (font == null) {
font = oldFont;
}
// No break here intentionally
case HTMLElement.TAG_P:
curAlign = getHorizAlign(child.getAttributeById(HTMLElement.ATTR_ALIGN), align, true);
adjustAlignment(align, curAlign);
newLineIfNotEmpty(curAlign);
newLineIfLastWasNotEmpty(curAlign);
pushContainer(child);
break;
case HTMLElement.TAG_DIV:
case // CENTER is practically DIV align=CENTER
HTMLElement.TAG_CENTER:
curAlign = child.getTagId() == HTMLElement.TAG_DIV ? getHorizAlign(child.getAttributeById(HTMLElement.ATTR_ALIGN), align, true) : Component.CENTER;
adjustAlignment(align, curAlign);
newLineIfNotEmpty(curAlign);
pushContainer(child);
break;
case HTMLElement.TAG_FIELDSET:
newLineIfNotEmpty(curAlign);
Container newCont = new Container();
newCont.setUIID("HTMLFieldset");
if (fieldsets.size() == 0) {
// First fieldset shouldn't have margin
newCont.getStyle().setMargin(Component.LEFT, 0);
}
newCont.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
curContainer.addComponent(newCont);
fieldsets.addElement(newCont);
curContainer = newCont;
if (loadCSS) {
child.setAssociatedComponents(newCont);
}
break;
case HTMLElement.TAG_BR:
if (loadCSS) {
child.setAssociatedComponents(curLine);
}
newLine(curAlign);
break;
case HTMLElement.TAG_DL:
newLineIfNotEmpty(curAlign);
newLine(curAlign);
pushContainer(child);
break;
case HTMLElement.TAG_DT:
newLineIfNotEmpty(curAlign);
pushContainer(child);
break;
case HTMLElement.TAG_UL:
case HTMLElement.TAG_DIR:
case HTMLElement.TAG_MENU:
newLineIfNotEmpty(curAlign);
ulLevel++;
listIndent += INDENT_UL;
if ((ulLevel == 1) && (olIndex == Integer.MIN_VALUE)) {
// newline only if it's the first list
newLine(curAlign);
} else {
// extra indentation for level 2 and beyond
listIndent += INDENT_UL;
}
pushContainer(child);
break;
case HTMLElement.TAG_OL:
newLineIfNotEmpty(curAlign);
if (olIndex != Integer.MIN_VALUE) {
String indexStr = ORDERED_LIST_TYPE_IDENTIFIERS[listType] + "" + olIndex;
// new Integer(olIndex));
olUpperLevelIndex.addElement(indexStr);
}
// olIndex=1;
olIndex = getInt(child.getAttributeById(HTMLElement.ATTR_START), 1);
listType = getOrderedListType(child);
if ((olUpperLevelIndex.size() == 0) && (ulLevel == 0)) {
// newline only if it's the first list
newLine(curAlign);
} else {
// add indent only for second level - first one already gets it from the numbers alignment to a 4-digit number
listIndent += INDENT_OL;
}
pushContainer(child);
break;
case HTMLElement.TAG_LI:
Container listItemCont = new Container(new BorderLayout());
listItemCont.getStyle().setMargin(Component.LEFT, leftIndent + listIndent);
curContainer.addComponent(listItemCont);
containers.addElement(curContainer);
HTMLListItem bullet = null;
if (((HTMLElement) child.getParent()).getTagId() == HTMLElement.TAG_OL) {
olIndex = getInt(child.getAttributeById(HTMLElement.ATTR_VALUE), olIndex);
int itemListType = getOrderedListType(child, listType);
HTMLListIndex listIndex = new HTMLListIndex(olIndex, itemListType);
listIndex.getUnselectedStyle().setFgColor(textColor);
listIndex.getSelectedStyle().setFgColor(textColor);
listIndex.getUnselectedStyle().setFont(font.getFont());
bullet = listIndex;
// following aligns short and long numbers (assuming a 4-digit number as the maximum, as other browsers do)
bullet.getUnselectedStyle().setAlignment(Component.RIGHT);
bullet.setPreferredW(font.getFont().stringWidth("8888. "));
} else {
bullet = new HTMLBullet(getUnorderedListType(child, ulLevel), font.getFont().getHeight(), textColor, this);
}
Container bulletCont = new Container(new BorderLayout());
bulletCont.addComponent(BorderLayout.NORTH, bullet);
listItemCont.addComponent(BorderLayout.WEST, bulletCont);
Container listItemText = new Container(new BoxLayout(BoxLayout.Y_AXIS));
listItemCont.addComponent(BorderLayout.CENTER, listItemText);
curContainer = listItemText;
if (loadCSS) {
child.setAssociatedComponents(listItemText);
}
break;
case HTMLElement.TAG_BLOCKQUOTE:
newLineIfNotEmpty(curAlign);
updateMargin(INDENT_BLOCKQUOTE);
newLine(curAlign);
pushContainer(child);
break;
case HTMLElement.TAG_DD:
newLineIfNotEmpty(curAlign);
updateMargin(INDENT_DD);
pushContainer(child);
break;
case HTMLElement.TAG_HR:
newLineIfNotEmpty(curAlign);
Label hr = new Label();
hr.setUIID("HTMLHR");
// hr.getStyle().setBorder(Border.createBevelRaised());
int hrWidth = calcSize(width, child.getAttributeById(HTMLElement.ATTR_WIDTH), width, false);
int hrHeight = getInt(child.getAttributeById(HTMLElement.ATTR_SIZE), HR_THICKNESS);
hr.setPreferredW(hrWidth);
hr.setPreferredH(hrHeight);
curLine.addComponent(hr);
newLine(curAlign);
if (loadCSS) {
child.setAssociatedComponents(hr);
}
break;
case HTMLElement.TAG_STYLE:
break;
case HTMLElement.TAG_IMG:
handleImage(child, curAlign, null);
break;
case HTMLElement.TAG_PRE:
preTagCount++;
pushContainer(child);
case HTMLElement.TAG_EM:
case HTMLElement.TAG_STRONG:
case HTMLElement.TAG_DFN:
case HTMLElement.TAG_CODE:
case HTMLElement.TAG_SAMP:
case HTMLElement.TAG_KBD:
case HTMLElement.TAG_VAR:
case HTMLElement.TAG_CITE:
case HTMLElement.TAG_TT:
font = (HTMLFont) fonts.get(child.getTagName());
if (font == null) {
font = oldFont;
}
break;
case HTMLElement.TAG_B:
case HTMLElement.TAG_I:
case HTMLElement.TAG_BIG:
case HTMLElement.TAG_SMALL:
font = getCounterpartFont(child.getTagId(), font);
break;
case HTMLElement.TAG_FORM:
curForm = new HTMLForm(this, child.getAttributeById(HTMLElement.ATTR_ACTION), child.getAttributeById(HTMLElement.ATTR_METHOD), child.getAttributeById(HTMLElement.ATTR_ENCTYPE));
pushContainer(child);
break;
case HTMLElement.TAG_BUTTON:
handleInput(child, curAlign);
break;
case HTMLElement.TAG_INPUT:
handleInput(child, curAlign);
break;
case HTMLElement.TAG_SELECT:
String multi = child.getAttributeById(HTMLElement.ATTR_MULTIPLE);
// If a select tag has size specified, it will be shown as an open list, and not as Codename One combo, even if there's no multiple seection allowed
if ((multi != null) || (child.getAttributeById(HTMLElement.ATTR_SIZE) != null)) {
curComboBox = new MultiComboBox(multi != null);
Container comboCont = new Container(new BorderLayout());
curComboBox.setItemGap(0);
comboCont.setUIID("ComboBox");
curComboBox.setUIID("List");
comboCont.addComponent(BorderLayout.CENTER, curComboBox);
} else {
curComboBox = new HTMLComboBox();
}
String name = child.getAttributeById(HTMLElement.ATTR_NAME);
if (curForm != null) {
curForm.addInput(name, curComboBox, null);
}
// Even if CSS is off, we need to associate it for HTMLElement.getCurentValue
child.setAssociatedComponents(curComboBox);
if (eventsListener != null) {
eventsListener.registerComponent(curComboBox, child);
}
if ((!PROCESS_HTML_MP1_ONLY) && (child.getAttributeById(HTMLElement.ATTR_DISABLED) != null)) {
curComboBox.setEnabled(false);
}
break;
case HTMLElement.TAG_OPTGROUP:
if (curComboBox != null) {
String label = child.getAttributeById(HTMLElement.ATTR_LABEL);
if (label != null) {
curComboBox.addItem(label);
}
}
break;
case HTMLElement.TAG_OPTION:
optionTag = true;
optionValue = child.getAttributeById(HTMLElement.ATTR_VALUE);
if ((curComboBox != null) && (child.getAttributeById(HTMLElement.ATTR_SELECTED) != null)) {
optionSelected = true;
}
break;
case HTMLElement.TAG_TEXTAREA:
curTextArea = new TextArea(getInt(child.getAttributeById(HTMLElement.ATTR_ROWS), DEFAULT_TEXTAREA_ROWS), getInt(child.getAttributeById(HTMLElement.ATTR_COLS), DEFAULT_TEXTAREA_COLS));
if (!PROCESS_HTML_MP1_ONLY) {
if (child.getAttributeById(HTMLElement.ATTR_DISABLED) != null) {
curTextArea.setEnabled(false);
}
if (child.getAttributeById(HTMLElement.ATTR_READONLY) != null) {
curTextArea.setEditable(false);
}
}
addCmp(curTextArea, curAlign);
if (eventsListener != null) {
eventsListener.registerComponent(curTextArea, child);
}
// Even if CSS is off, we need to associate it for HTMLElement.getCurentValue
child.setAssociatedComponents(curTextArea);
String aKey = element.getAttributeById(HTMLElement.ATTR_ACCESSKEY);
if ((aKey != null) && (aKey.length() == 1)) {
// accessKeys.put(new Integer(aKey.charAt(0)), curTextArea);
addAccessKey(aKey.charAt(0), curTextArea, false);
}
break;
case HTMLElement.TAG_Q:
addQuote(child, curAlign, true);
quoteTagCount++;
break;
case HTMLElement.TAG_TABLE:
newLineIfNotEmpty(curAlign);
if (curTable != null) {
tables.addElement(curTable);
HTMLTableModel newTable = new HTMLTableModel();
curTable = newTable;
} else {
curTable = new HTMLTableModel();
}
// In fixed width mode we arbitrarily divide the size by a factor knowing that probably there are several cells (If we don't do it, labels inside the cell will be built up to the full width size, leaving no space for others)
width = width / 2;
break;
case HTMLElement.TAG_TR:
break;
case HTMLElement.TAG_TH:
case HTMLElement.TAG_TD:
if (curTable != null) {
handleTableCell(child, curAlign);
}
break;
case HTMLElement.TAG_LABEL:
labelForID = child.getAttributeById(HTMLElement.ATTR_FOR);
aKey = child.getAttributeById(HTMLElement.ATTR_ACCESSKEY);
if ((aKey != null) && (aKey.length() == 1)) {
accesskey = aKey.charAt(0);
}
break;
// HTML 4 tags
case HTMLElement.TAG_FONT:
// TODO - This will not work for nested font tags, need to either define color as a local parameter or create a vector stack
textColor = HTMLElement.getColor(child.getAttributeById(HTMLElement.ATTR_COLOR), textColor);
String family = child.getAttributeById(HTMLElement.ATTR_FACE);
int size = getInt(child.getAttributeById(HTMLElement.ATTR_SIZE));
if ((family != null) || (size != 0)) {
HTMLFont f = getClosestHTMLFont(family, size, 0, 0);
if (f != null) {
font = f;
}
}
break;
case HTMLElement.TAG_U:
case // INS (Inserted text) is rendered exactly like U (underline) in most browsers
HTMLElement.TAG_INS:
if (underlineCount == 0) {
textDecoration |= Style.TEXT_DECORATION_UNDERLINE;
}
underlineCount++;
break;
case HTMLElement.TAG_S:
case HTMLElement.TAG_STRIKE:
case // DEL (Deleted text) is rendered exactly like S (strikethru) in most browsers
HTMLElement.TAG_DEL:
if (strikethruCount == 0) {
textDecoration |= Style.TEXT_DECORATION_STRIKETHRU;
}
strikethruCount++;
break;
case HTMLElement.TAG_MAP:
String mapName = child.getAttributeById(HTMLElement.ATTR_NAME);
curImageMap = new ImageMapData(mapName);
break;
case HTMLElement.TAG_AREA:
handleImageMapArea(child);
break;
case HTMLElement.TAG_SUP:
superscript++;
break;
case HTMLElement.TAG_SUB:
superscript--;
break;
case HTMLElement.TAG_TBODY:
if (curTable != null) {
curTable.startSegment(HTMLTableModel.SEGMENT_TBODY);
}
break;
case HTMLElement.TAG_THEAD:
if (curTable != null) {
curTable.startSegment(HTMLTableModel.SEGMENT_THEAD);
}
break;
case HTMLElement.TAG_TFOOT:
if (curTable != null) {
curTable.startSegment(HTMLTableModel.SEGMENT_TFOOT);
}
break;
}
if (child.getNumChildren() > 0) {
processTag(child, curAlign);
}
// Process close tag
switch(child.getTagId()) {
case HTMLElement.TAG_H1:
case HTMLElement.TAG_H2:
case HTMLElement.TAG_H3:
case HTMLElement.TAG_H4:
case HTMLElement.TAG_H5:
case HTMLElement.TAG_H6:
font = oldFont;
case HTMLElement.TAG_P:
// Restore previous alignment
curAlign = align;
newLineIfNotEmpty(curAlign);
popContainer();
newLine(curAlign);
break;
case HTMLElement.TAG_DIV:
case HTMLElement.TAG_CENTER:
// Restore previous alignment
curAlign = align;
newLineIfNotEmpty(curAlign);
popContainer();
break;
case HTMLElement.TAG_FIELDSET:
newLineIfNotEmpty(curAlign);
Container fieldsetContainer = (Container) fieldsets.lastElement();
curContainer = fieldsetContainer.getParent();
fieldsets.removeElement(fieldsetContainer);
break;
case HTMLElement.TAG_BLOCKQUOTE:
newLineIfNotEmpty(curAlign);
newLine(curAlign);
updateMargin(-INDENT_BLOCKQUOTE);
popContainer();
break;
case HTMLElement.TAG_DT:
popContainer();
break;
case HTMLElement.TAG_DD:
newLineIfNotEmpty(curAlign);
updateMargin(-INDENT_DD);
popContainer();
break;
case HTMLElement.TAG_DL:
newLine(curAlign);
popContainer();
break;
case HTMLElement.TAG_A:
link = null;
linkVisited = false;
mainLink = null;
anchor = null;
accesskey = '\0';
break;
case HTMLElement.TAG_UL:
case HTMLElement.TAG_DIR:
case HTMLElement.TAG_MENU:
ulLevel--;
if ((ulLevel == 0) && (olIndex == Integer.MIN_VALUE)) {
newLine(curAlign);
} else {
// level 2 and beyond got extra indentation, so we remove it here
listIndent -= INDENT_UL;
}
listIndent -= INDENT_UL;
popContainer();
break;
case HTMLElement.TAG_OL:
if (olUpperLevelIndex.size() != 0) {
String indexStr = (String) olUpperLevelIndex.lastElement();
olUpperLevelIndex.removeElementAt(olUpperLevelIndex.size() - 1);
listType = getOrderedListType(indexStr.charAt(0), HTMLListIndex.LIST_NUMERIC);
olIndex = getInt(indexStr.substring(1));
// First level of ordered list doesn't get indentation, so we substract only if it's nested
listIndent -= INDENT_OL;
} else {
olIndex = Integer.MIN_VALUE;
}
if ((olIndex == Integer.MIN_VALUE) && (ulLevel == 0)) {
// new line only if it is the last nested list
newLine(curAlign);
}
popContainer();
break;
case HTMLElement.TAG_LI:
if (olIndex != Integer.MIN_VALUE) {
olIndex++;
}
newLineIfNotEmpty(curAlign);
// We can't use popContainer, since with LI the container is pushed even when CSS is ignored, to provide the spacing between the list item bullet/number and the text (in a nested way if needed)
Container prevContainer = (Container) containers.lastElement();
curContainer = prevContainer;
containers.removeElement(curContainer);
// curContainer=listItemParentContainer;
break;
case HTMLElement.TAG_PRE:
preTagCount--;
popContainer();
case HTMLElement.TAG_FONT:
textColor = oldFontColor;
case HTMLElement.TAG_EM:
case HTMLElement.TAG_STRONG:
case HTMLElement.TAG_DFN:
case HTMLElement.TAG_CODE:
case HTMLElement.TAG_SAMP:
case HTMLElement.TAG_KBD:
case HTMLElement.TAG_VAR:
case HTMLElement.TAG_CITE:
case HTMLElement.TAG_B:
case HTMLElement.TAG_I:
case HTMLElement.TAG_BIG:
case HTMLElement.TAG_SMALL:
case HTMLElement.TAG_TT:
font = oldFont;
break;
case HTMLElement.TAG_FORM:
if ((curForm != null) && (!curForm.hasSubmitButton) && (curForm.getNumFields() > 0)) {
// This is a fix for forms with no submit buttons which can be resulted due to the fact XHTML-MP doesn't support the BUTTON tag and also input type button with javascript
Button submitButton = new Button(curForm.createSubmitCommand(null, null));
addCmp(submitButton, curAlign);
}
curForm = null;
popContainer();
break;
case HTMLElement.TAG_TEXTAREA:
String name = child.getAttributeById(HTMLElement.ATTR_NAME);
if (curForm != null) {
// This was moved to the end tag to enable auto complete support (i.e. if there's an autocomplete it overrides the default value)
curForm.addInput(name, curTextArea, null);
}
curTextArea = null;
break;
case HTMLElement.TAG_SELECT:
if (curComboBox instanceof MultiComboBox) {
Container comboCont = curComboBox.getParent();
int minSize = Math.min(MIN_MULTI_COMBOBOX_ITEMS, curComboBox.size());
int maxSize = Math.min(curComboBox.size(), MAX_MULTI_COMBOBOX_ITEMS);
int size = Math.min(maxSize, Math.max(getInt(child.getAttributeById(HTMLElement.ATTR_SIZE)), minSize));
Component renderCmp = curComboBox.getRenderer().getListCellRendererComponent(curComboBox, "X", 0, false);
comboCont.setPreferredH((renderCmp.getPreferredH() + renderCmp.getStyle().getMargin(Component.TOP) + renderCmp.getStyle().getMargin(Component.BOTTOM) + curComboBox.getItemGap()) * size + curComboBox.getStyle().getPadding(Component.TOP) + curComboBox.getStyle().getPadding(Component.BOTTOM));
addCmp(comboCont, curAlign);
} else {
addCmp(curComboBox, curAlign);
}
curComboBox = null;
break;
case HTMLElement.TAG_OPTION:
optionTag = false;
optionSelected = false;
optionValue = null;
break;
case HTMLElement.TAG_Q:
quoteTagCount--;
addQuote(child, curAlign, false);
break;
case HTMLElement.TAG_TABLE:
newLineIfNotEmpty(curAlign);
// For a case that TR was not closed properly
curTable.commitRowIfNotEmpty();
if (curTable.getRowCount() != 0) {
// Don't add an empty table (Creates an exception in TableLayout and useless)
/*if (TABLES_LOCK_SIZE) {
for(int r=0;r<curTable.getRowCount();r++) {
for(int c=0;c<curTable.getColumnCount();c++) {
Component cmp=(Component)curTable.getValueAt(r, c);
if (cmp!=null) { // Can be null for cells that are "spanned over"
cmp.setPreferredSize(cmp.getPreferredSize());
}
}
}
}*/
HTMLTable table = new HTMLTable(curTable);
table.getStyle().setBgTransparency(0);
if (loadCSS) {
child.setAssociatedComponents(table);
}
int borderSize = getInt(child.getAttributeById(HTMLElement.ATTR_BORDER));
int[] borderPad = new int[4];
if (borderSize > 0) {
int frame = PROCESS_HTML_MP1_ONLY ? -1 : HTMLUtils.getStringVal(child.getAttributeById(HTMLElement.ATTR_FRAME), HTMLElement.ALLOWED_TABLE_FRAME_STRINGS);
Border border = Border.createLineBorder(borderSize);
if (frame == -1) {
for (int s = 0; s < borderPad.length; s++) {
borderPad[s] = borderSize;
}
} else {
Border[] borders = new Border[4];
for (int j = 0; j < HTMLElement.ALLOWED_TABLE_FRAME_VALS[frame].length; j++) {
int side = HTMLElement.ALLOWED_TABLE_FRAME_VALS[frame][j];
borders[side] = border;
borderPad[side] = borderSize;
}
border = Border.createCompoundBorder(borders[Component.TOP], borders[Component.BOTTOM], borders[Component.LEFT], borders[Component.RIGHT]);
}
table.getUnselectedStyle().setBorder(border);
table.getSelectedStyle().setBorder(border);
table.getUnselectedStyle().setPadding(borderPad[Component.TOP], borderPad[Component.BOTTOM], borderPad[Component.LEFT], borderPad[Component.RIGHT]);
table.getSelectedStyle().setPadding(borderPad[Component.TOP], borderPad[Component.BOTTOM], borderPad[Component.LEFT], borderPad[Component.RIGHT]);
} else {
table.getUnselectedStyle().setBorder(null);
table.getSelectedStyle().setBorder(null);
table.setDrawBorder(false);
}
if (!PROCESS_HTML_MP1_ONLY) {
int rules = HTMLUtils.getStringVal(child.getAttributeById(HTMLElement.ATTR_RULES), HTMLElement.ALLOWED_TABLE_RULES_STRINGS, Table.INNER_BORDERS_ALL);
table.setInnerBorderMode(rules);
int spacing = getInt(child.getAttributeById(HTMLElement.ATTR_CELLSPACING), -1);
if (spacing != -1) {
table.setBorderSpacing(spacing, spacing);
}
int padding = getInt(child.getAttributeById(HTMLElement.ATTR_CELLPADDING), -1);
if (padding != -1) {
for (int r = 0; r < curTable.getRowCount(); r++) {
for (int c = 0; c < curTable.getColumnCount(); c++) {
Component cmp = (Component) curTable.getValueAt(r, c);
if (cmp != null) {
// Can be null for cells that are "spanned over"
cmp.getUnselectedStyle().setPadding(padding, padding, padding, padding);
cmp.getSelectedStyle().setPadding(padding, padding, padding, padding);
}
}
}
}
}
if (curTable.captionTextTag != null) {
Container captionedTable = new Container(new BoxLayout(BoxLayout.Y_AXIS));
TextArea caption = new TextArea(curTable.captionTextTag.getText());
curTable.captionTextTag.setAssociatedComponents(caption);
caption.setUIID("HTMLTableCaption");
caption.setEditable(false);
caption.setFocusable(false);
caption.getStyle().setBorder(null);
caption.getStyle().setAlignment(Component.CENTER);
captionedTable.addComponent(caption);
captionedTable.addComponent(table);
addCmp(captionedTable, curAlign);
} else {
addCmp(table, curAlign);
}
newLineIfNotEmpty(curAlign);
}
if (tables.size() == 0) {
curTable = null;
} else {
curTable = (HTMLTableModel) tables.lastElement();
tables.removeElement(curTable);
}
// In fixed width mode we arbitrarily divide the size by a factor knowing that probably there are several cells - here we restore the size back
width = width * 2;
if (width > displayWidth) {
width = displayWidth;
}
break;
case HTMLElement.TAG_TR:
if (curTable != null) {
curTable.commitRow();
}
break;
case HTMLElement.TAG_TH:
case HTMLElement.TAG_TD:
if (curTable != null) {
newLineIfNotEmpty(curAlign);
curContainer = (Container) tableCells.lastElement();
tableCells.removeElement(curContainer);
}
break;
case HTMLElement.TAG_LABEL:
labelForID = null;
accesskey = '\0';
break;
// HTML 4 tags
case HTMLElement.TAG_U:
case HTMLElement.TAG_INS:
underlineCount--;
if (underlineCount == 0) {
textDecoration -= Style.TEXT_DECORATION_UNDERLINE;
}
break;
case HTMLElement.TAG_S:
case HTMLElement.TAG_STRIKE:
case HTMLElement.TAG_DEL:
strikethruCount--;
if (strikethruCount == 0) {
textDecoration -= Style.TEXT_DECORATION_STRIKETHRU;
}
break;
case HTMLElement.TAG_MAP:
if (curImageMap != null) {
if (imageMapData == null) {
imageMapData = new Hashtable();
}
imageMapData.put(curImageMap.name, curImageMap);
if ((imageMapComponents != null) && (imageMapComponents.containsKey(curImageMap.name))) {
HTMLImageMap imageMap = (HTMLImageMap) imageMapComponents.get(curImageMap.name);
imageMap.mapData = curImageMap;
}
curImageMap = null;
}
break;
case HTMLElement.TAG_SUP:
superscript--;
break;
case HTMLElement.TAG_SUB:
superscript++;
break;
case HTMLElement.TAG_TBODY:
case HTMLElement.TAG_THEAD:
case HTMLElement.TAG_TFOOT:
if (curTable != null) {
curTable.endSegment();
}
break;
}
}
}
Aggregations