use of com.codename1.charts.compat.GradientDrawable.Orientation 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.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class XYChart method draw.
/**
* The graphical representation of the XY chart.
*
* @param canvas the canvas to paint to
* @param x the top left x value of the view to draw to
* @param y the top left y value of the view to draw to
* @param width the width of the view to draw to
* @param height the height of the view to draw to
* @param paint the paint
*/
public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint) {
paint.setAntiAlias(mRenderer.isAntialiasing());
int legendSize = getLegendSize(mRenderer, height / 5, mRenderer.getAxisTitleTextSize());
int[] margins = mRenderer.getMargins();
int left = x + margins[1] + (int) mRenderer.getAxisTitleTextSize() + (mRenderer.isShowLabels() ? (int) mRenderer.getLabelsTextSize() : 0);
int top = y + margins[0];
int right = x + width - margins[3];
int sLength = mDataset.getSeriesCount();
String[] titles = new String[sLength];
for (int i = 0; i < sLength; i++) {
titles[i] = mDataset.getSeriesAt(i).getTitle();
}
if (mRenderer.isFitLegend() && mRenderer.isShowLegend()) {
legendSize = drawLegend(canvas, mRenderer, titles, left, right, y, width, height, legendSize, paint, true);
}
int bottom = y + height - margins[2] - legendSize - (int) mRenderer.getAxisTitleTextSize() - (mRenderer.isShowLabels() ? (int) mRenderer.getLabelsTextSize() : 0);
if (mScreenR == null) {
mScreenR = new Rectangle();
}
mScreenR.setBounds(left, top, right - left, bottom - top);
drawBackground(mRenderer, canvas, x, y, width, height, paint, false, DefaultRenderer.NO_COLOR);
if (paint.getTypeface() == null || (mRenderer.getTextTypeface() != null && paint.getTypeface().equals(mRenderer.getTextTypeface())) || !paint.getTypeface().toString().equals(mRenderer.getTextTypefaceName()) || paint.getTypeface().getStyle() != mRenderer.getTextTypefaceStyle()) {
if (mRenderer.getTextTypeface() != null) {
paint.setTypeface(mRenderer.getTextTypeface());
} else {
paint.setTypeface(Font.createSystemFont(mRenderer.getTextTypefaceName(), mRenderer.getTextTypefaceStyle(), Font.SIZE_SMALL));
}
}
Orientation or = mRenderer.getOrientation();
if (or == Orientation.VERTICAL) {
right -= legendSize;
bottom += legendSize - 20;
}
int angle = or.getAngle();
boolean rotate = angle == 90;
mScale = (float) (height) / width;
mTranslate = Math.abs(width - height) / 2;
if (mScale < 1) {
mTranslate *= -1;
}
mCenter = new Point((x + width) / 2, (y + height) / 2);
if (rotate) {
transform(canvas, angle, false);
}
int maxScaleNumber = -Integer.MAX_VALUE;
for (int i = 0; i < sLength; i++) {
maxScaleNumber = Math.max(maxScaleNumber, mDataset.getSeriesAt(i).getScaleNumber());
}
maxScaleNumber++;
if (maxScaleNumber < 0) {
return;
}
double[] minX = new double[maxScaleNumber];
double[] maxX = new double[maxScaleNumber];
double[] minY = new double[maxScaleNumber];
double[] maxY = new double[maxScaleNumber];
boolean[] isMinXSet = new boolean[maxScaleNumber];
boolean[] isMaxXSet = new boolean[maxScaleNumber];
boolean[] isMinYSet = new boolean[maxScaleNumber];
boolean[] isMaxYSet = new boolean[maxScaleNumber];
for (int i = 0; i < maxScaleNumber; i++) {
minX[i] = mRenderer.getXAxisMin(i);
maxX[i] = mRenderer.getXAxisMax(i);
minY[i] = mRenderer.getYAxisMin(i);
maxY[i] = mRenderer.getYAxisMax(i);
isMinXSet[i] = mRenderer.isMinXSet(i);
isMaxXSet[i] = mRenderer.isMaxXSet(i);
isMinYSet[i] = mRenderer.isMinYSet(i);
isMaxYSet[i] = mRenderer.isMaxYSet(i);
if (mCalcRange.get(i) == null) {
mCalcRange.put(i, new double[4]);
}
}
double[] xPixelsPerUnit = new double[maxScaleNumber];
double[] yPixelsPerUnit = new double[maxScaleNumber];
for (int i = 0; i < sLength; i++) {
XYSeries series = mDataset.getSeriesAt(i);
int scale = series.getScaleNumber();
if (series.getItemCount() == 0) {
continue;
}
if (!isMinXSet[scale]) {
double minimumX = series.getMinX();
if (minimumX != MathHelper.NULL_VALUE) {
minX[scale] = minX[scale] == MathHelper.NULL_VALUE ? minimumX : Math.min(minX[scale], minimumX);
mCalcRange.get(scale)[0] = minX[scale];
} else {
minX[scale] = 0;
mCalcRange.get(scale)[0] = 0;
}
}
if (!isMaxXSet[scale]) {
double maximumX = series.getMaxX();
if (maximumX != MathHelper.NULL_VALUE) {
maxX[scale] = maxX[scale] == MathHelper.NULL_VALUE ? maximumX : Math.max(maxX[scale], maximumX);
mCalcRange.get(scale)[1] = maxX[scale];
} else {
maxX[scale] = minX[scale] + 1;
mCalcRange.get(scale)[1] = maxX[scale];
}
}
if (!isMinYSet[scale]) {
double minimumY = series.getMinY();
if (minimumY != MathHelper.NULL_VALUE) {
minY[scale] = minY[scale] == MathHelper.NULL_VALUE ? minimumY : Math.min(minY[scale], (float) minimumY);
mCalcRange.get(scale)[2] = minY[scale];
} else {
minY[scale] = 0;
mCalcRange.get(scale)[2] = 0;
}
}
if (!isMaxYSet[scale]) {
double maximumY = series.getMaxY();
if (maximumY != MathHelper.NULL_VALUE) {
maxY[scale] = maxY[scale] == MathHelper.NULL_VALUE ? maximumY : Math.max(maxY[scale], (float) maximumY);
mCalcRange.get(scale)[3] = maxY[scale];
} else {
maxY[scale] = minY[scale] + 1;
mCalcRange.get(scale)[3] = maxY[scale];
}
}
}
for (int i = 0; i < maxScaleNumber; i++) {
if (maxX[i] - minX[i] != 0) {
xPixelsPerUnit[i] = (right - left) / (maxX[i] - minX[i]);
}
if (maxY[i] - minY[i] != 0) {
yPixelsPerUnit[i] = (float) ((bottom - top) / (maxY[i] - minY[i]));
}
// the X axis on multiple scales was wrong without this fix
if (i > 0) {
xPixelsPerUnit[i] = xPixelsPerUnit[0];
minX[i] = minX[0];
maxX[i] = maxX[0];
}
}
boolean hasValues = false;
// use a linked list for these reasons:
// 1) Avoid a large contiguous memory allocation
// 2) We don't need random seeking, only sequential reading/writing, so
// linked list makes sense
clickableAreas = new HashMap<Integer, List<ClickableArea>>();
for (int i = 0; i < sLength; i++) {
XYSeries series = mDataset.getSeriesAt(i);
int scale = series.getScaleNumber();
if (series.getItemCount() == 0) {
continue;
}
hasValues = true;
XYSeriesRenderer seriesRenderer = (XYSeriesRenderer) mRenderer.getSeriesRendererAt(i);
// int originalValuesLength = series.getItemCount();
// int valuesLength = originalValuesLength;
// int length = valuesLength * 2;
List<Float> points = new ArrayList<Float>();
List<Double> values = new ArrayList<Double>();
float yAxisValue = Math.min(bottom, (float) (bottom + yPixelsPerUnit[scale] * minY[scale]));
LinkedList<ClickableArea> clickableArea = new LinkedList<ClickableArea>();
clickableAreas.put(i, clickableArea);
synchronized (series) {
SortedMap<Double, Double> range = series.getRange(minX[scale], maxX[scale], seriesRenderer.isDisplayBoundingPoints());
int startIndex = -1;
for (Double value : range.keySet()) {
double xValue = value;
Double rValue = range.get(value);
double yValue = rValue.doubleValue();
if (startIndex < 0 && (!isNullValue(yValue) || isRenderNullValues())) {
startIndex = series.getIndexForKey(xValue);
}
// points.add((float) (left + xPixelsPerUnit[scale]
// * (value.getKey().floatValue() - minX[scale])));
// points.add((float) (bottom - yPixelsPerUnit[scale]
// * (value.getValue().floatValue() - minY[scale])));
values.add(value);
values.add(rValue);
if (!isNullValue(yValue)) {
points.add((float) (left + xPixelsPerUnit[scale] * (xValue - minX[scale])));
points.add((float) (bottom - yPixelsPerUnit[scale] * (yValue - minY[scale])));
} else if (isRenderNullValues()) {
points.add((float) (left + xPixelsPerUnit[scale] * (xValue - minX[scale])));
points.add((float) (bottom - yPixelsPerUnit[scale] * (-minY[scale])));
} else {
if (points.size() > 0) {
drawSeries(series, canvas, paint, points, seriesRenderer, yAxisValue, i, or, startIndex);
ClickableArea[] clickableAreasForSubSeries = clickableAreasForPoints(points, values, yAxisValue, i, startIndex);
clickableArea.addAll(Arrays.asList(clickableAreasForSubSeries));
points.clear();
values.clear();
startIndex = -1;
}
clickableArea.add(null);
}
}
int count = series.getAnnotationCount();
if (count > 0) {
paint.setColor(seriesRenderer.getAnnotationsColor());
paint.setTextSize(seriesRenderer.getAnnotationsTextSize());
paint.setTextAlign(seriesRenderer.getAnnotationsTextAlign());
Rectangle2D bound = new Rectangle2D();
for (int j = 0; j < count; j++) {
float xS = (float) (left + xPixelsPerUnit[scale] * (series.getAnnotationX(j) - minX[scale]));
float yS = (float) (bottom - yPixelsPerUnit[scale] * (series.getAnnotationY(j) - minY[scale]));
paint.getTextBounds(series.getAnnotationAt(j), 0, series.getAnnotationAt(j).length(), bound);
if (xS < (xS + bound.getWidth()) && yS < canvas.getHeight()) {
drawString(canvas, series.getAnnotationAt(j), xS, yS, paint);
}
}
}
if (points.size() > 0) {
drawSeries(series, canvas, paint, points, seriesRenderer, yAxisValue, i, or, startIndex);
ClickableArea[] clickableAreasForSubSeries = clickableAreasForPoints(points, values, yAxisValue, i, startIndex);
clickableArea.addAll(Arrays.asList(clickableAreasForSubSeries));
}
}
}
// draw stuff over the margins such as data doesn't render on these areas
drawBackground(mRenderer, canvas, x, bottom, width, height - bottom, paint, true, mRenderer.getMarginsColor());
drawBackground(mRenderer, canvas, x, y, width, margins[0], paint, true, mRenderer.getMarginsColor());
if (or == Orientation.HORIZONTAL) {
drawBackground(mRenderer, canvas, x, y, left - x, height - y, paint, true, mRenderer.getMarginsColor());
drawBackground(mRenderer, canvas, right, y, margins[3], height - y, paint, true, mRenderer.getMarginsColor());
} else if (or == Orientation.VERTICAL) {
drawBackground(mRenderer, canvas, right, y, width - right, height - y, paint, true, mRenderer.getMarginsColor());
drawBackground(mRenderer, canvas, x, y, left - x, height - y, paint, true, mRenderer.getMarginsColor());
}
boolean showLabels = mRenderer.isShowLabels() && hasValues;
boolean showGridX = mRenderer.isShowGridX();
boolean showTickMarks = mRenderer.isShowTickMarks();
// boolean showCustomTextGridX = mRenderer.isShowCustomTextGridX();
boolean showCustomTextGridY = mRenderer.isShowCustomTextGridY();
if (showLabels || showGridX) {
List<Double> xLabels = getValidLabels(getXLabels(minX[0], maxX[0], mRenderer.getXLabels()));
Map<Integer, List<Double>> allYLabels = getYLabels(minY, maxY, maxScaleNumber);
int xLabelsLeft = left;
if (showLabels) {
paint.setColor(mRenderer.getXLabelsColor());
paint.setTextSize(mRenderer.getLabelsTextSize());
paint.setTextAlign(mRenderer.getXLabelsAlign());
// if (mRenderer.getXLabelsAlign() == Align.LEFT) {
// xLabelsLeft += mRenderer.getLabelsTextSize() / 4;
// }
}
drawXLabels(xLabels, mRenderer.getXTextLabelLocations(), canvas, paint, xLabelsLeft, top, bottom, xPixelsPerUnit[0], minX[0], maxX[0]);
drawYLabels(allYLabels, canvas, paint, maxScaleNumber, left, right, bottom, yPixelsPerUnit, minY);
if (showLabels) {
paint.setColor(mRenderer.getLabelsColor());
for (int i = 0; i < maxScaleNumber; i++) {
int axisAlign = mRenderer.getYAxisAlign(i);
Double[] yTextLabelLocations = mRenderer.getYTextLabelLocations(i);
for (Double location : yTextLabelLocations) {
if (minY[i] <= location && location <= maxY[i]) {
float yLabel = (float) (bottom - yPixelsPerUnit[i] * (location.doubleValue() - minY[i]));
String label = mRenderer.getYTextLabel(location, i);
paint.setColor(mRenderer.getYLabelsColor(i));
paint.setTextAlign(mRenderer.getYLabelsAlign(i));
if (or == Orientation.HORIZONTAL) {
if (axisAlign == Align.LEFT) {
if (showTickMarks) {
canvas.drawLine(left + getLabelLinePos(axisAlign), yLabel, left, yLabel, paint);
}
drawText(canvas, label, left - mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
} else {
if (showTickMarks) {
canvas.drawLine(right, yLabel, right + getLabelLinePos(axisAlign), yLabel, paint);
}
drawText(canvas, label, right - mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
}
if (showCustomTextGridY) {
paint.setColor(mRenderer.getGridColor(i));
canvas.drawLine(left, yLabel, right, yLabel, paint);
}
} else {
if (showTickMarks) {
canvas.drawLine(right - getLabelLinePos(axisAlign), yLabel, right, yLabel, paint);
}
drawText(canvas, label, right + 10, yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
if (showCustomTextGridY) {
paint.setColor(mRenderer.getGridColor(i));
canvas.drawLine(right, yLabel, left, yLabel, paint);
}
}
}
}
}
}
if (showLabels) {
paint.setColor(mRenderer.getLabelsColor());
float size = mRenderer.getAxisTitleTextSize();
paint.setTextSize(size);
paint.setTextAlign(Align.CENTER);
if (or == Orientation.HORIZONTAL) {
drawText(canvas, mRenderer.getXTitle(), x + width / 2, bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding() + size, paint, 0);
for (int i = 0; i < maxScaleNumber; i++) {
int axisAlign = mRenderer.getYAxisAlign(i);
if (axisAlign == Align.LEFT) {
drawText(canvas, mRenderer.getYTitle(i), x + size, y + height / 2, paint, -90);
} else {
drawText(canvas, mRenderer.getYTitle(i), x + width, y + height / 2, paint, -90);
}
}
paint.setTextSize(mRenderer.getChartTitleTextSize());
drawText(canvas, mRenderer.getChartTitle(), x + width / 2, y + mRenderer.getChartTitleTextSize(), paint, 0);
} else if (or == Orientation.VERTICAL) {
drawText(canvas, mRenderer.getXTitle(), x + width / 2, y + height - size + mRenderer.getXLabelsPadding(), paint, -90);
drawText(canvas, mRenderer.getYTitle(), right + 20, y + height / 2, paint, 0);
paint.setTextSize(mRenderer.getChartTitleTextSize());
drawText(canvas, mRenderer.getChartTitle(), x + size, top + height / 2, paint, 0);
}
}
}
if (or == Orientation.HORIZONTAL) {
drawLegend(canvas, mRenderer, titles, left, right, y + (int) mRenderer.getXLabelsPadding(), width, height, legendSize, paint, false);
} else if (or == Orientation.VERTICAL) {
transform(canvas, angle, true);
drawLegend(canvas, mRenderer, titles, left, right, y + (int) mRenderer.getXLabelsPadding(), width, height, legendSize, paint, false);
transform(canvas, angle, false);
}
if (mRenderer.isShowAxes()) {
paint.setColor(mRenderer.getXAxisColor());
canvas.drawLine(left, bottom, right, bottom, paint);
paint.setColor(mRenderer.getYAxisColor());
boolean rightAxis = false;
for (int i = 0; i < maxScaleNumber && !rightAxis; i++) {
rightAxis = mRenderer.getYAxisAlign(i) == Align.RIGHT;
}
if (or == Orientation.HORIZONTAL) {
canvas.drawLine(left, top, left, bottom, paint);
if (rightAxis) {
canvas.drawLine(right, top, right, bottom, paint);
}
} else if (or == Orientation.VERTICAL) {
canvas.drawLine(right, top, right, bottom, paint);
}
}
if (rotate) {
transform(canvas, angle, true);
}
}
use of com.codename1.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class InteractionDialog method showPopupDialog.
/**
* A popup dialog is shown with the context of a component and its selection, it is disposed seamlessly if the back button is pressed
* or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
* dialog has the PopupDialog style by default.
*
* @param rect the screen rectangle to which the popup should point
*/
public void showPopupDialog(Rectangle rect) {
disposed = false;
if (getUIID().equals("Dialog")) {
setUIID("PopupDialog");
if (getTitleComponent().getUIID().equals("DialogTitle")) {
getTitleComponent().setUIID("PopupDialogTitle");
}
getContentPane().setUIID("PopupContentPane");
}
Component contentPane = getContentPane();
Label title = getTitleComponent();
UIManager manager = getUIManager();
String dialogTitle = title.getText();
// preferred size logic of the dialog won't work with large title borders
if ((dialogTitle != null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", false)) {
boolean b = getTitle().length() > 0;
titleArea.setVisible(b);
getTitleComponent().setVisible(b);
if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
getTitleComponent().setPreferredSize(new Dimension(0, 0));
getTitleComponent().getStyle().setBorder(null);
titleArea.setPreferredSize(new Dimension(0, 0));
if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
int titlePT = getTitleComponent().getStyle().getPaddingTop();
byte[] pu = getContentPane().getStyle().getPaddingUnit();
if (pu == null) {
pu = new byte[4];
}
pu[0] = Style.UNIT_TYPE_PIXELS;
getContentPane().getStyle().setPaddingUnit(pu);
int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
}
}
}
// allows a text area to recalculate its preferred size if embedded within a dialog
revalidate();
Style contentPaneStyle = getStyle();
boolean restoreArrow = false;
if (manager.isThemeConstant(getUIID() + "ArrowBool", false)) {
Image t = manager.getThemeImageConstant(getUIID() + "ArrowTopImage");
Image b = manager.getThemeImageConstant(getUIID() + "ArrowBottomImage");
Image l = manager.getThemeImageConstant(getUIID() + "ArrowLeftImage");
Image r = manager.getThemeImageConstant(getUIID() + "ArrowRightImage");
Border border = contentPaneStyle.getBorder();
if (border != null) {
border.setImageBorderSpecialTile(t, b, l, r, rect);
restoreArrow = true;
}
}
calcPreferredSize();
int prefHeight = getPreferredH();
int prefWidth = getPreferredW();
if (contentPaneStyle.getBorder() != null) {
prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
}
Form f = Display.getInstance().getCurrent();
int availableHeight = getLayeredPane(f).getParent().getHeight();
int availableWidth = getLayeredPane(f).getParent().getWidth();
int width = Math.min(availableWidth, prefWidth);
int x = 0;
int y = 0;
boolean showPortrait = Display.getInstance().isPortrait();
// if we don't have enough space then disregard device orientation
if (showPortrait) {
if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
showPortrait = false;
}
} else {
if (availableHeight / 2 > availableWidth - rect.getWidth()) {
showPortrait = true;
}
}
if (showPortrait) {
if (width < availableWidth) {
int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
// if the ideal position is less than 0 just use 0
if (idealX > 0) {
// if the idealX is too far to the right just align to the right
if (idealX + width > availableWidth) {
x = availableWidth - width;
} else {
x = idealX;
}
}
}
if (rect.getY() < availableHeight / 2) {
// popup downwards
y = rect.getY();
int height = Math.min(prefHeight, availableHeight - y);
show(y, Math.max(0, availableHeight - height - y), x, Math.max(0, availableWidth - width - x));
} else {
// popup upwards
int height = Math.min(prefHeight, rect.getY() - getLayeredPane(f).getAbsoluteY());
y = rect.getY() - height - getLayeredPane(f).getAbsoluteY();
show(y, Math.max(0, getLayeredPane(f).getComponentForm().getHeight() - rect.getY()), x, Math.max(0, availableWidth - width - x));
}
} else {
int height = Math.min(prefHeight, availableHeight);
if (height < availableHeight) {
int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
// if the ideal position is less than 0 just use 0
if (idealY > 0) {
// if the idealY is too far up just align to the top
if (idealY + height > availableHeight) {
y = availableHeight - height;
} else {
y = idealY;
}
}
}
if (prefWidth > rect.getX()) {
// popup right
x = rect.getX() + rect.getSize().getWidth();
if (x + prefWidth > availableWidth) {
x = availableWidth - prefWidth;
}
width = Math.min(prefWidth, availableWidth - x);
show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
} else {
// popup left
width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
x = rect.getX() - width;
show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
}
}
/*if(restoreArrow) {
contentPaneStyle.getBorder().clearImageBorderSpecialTile();
}*/
}
use of com.codename1.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class Canvas method drawGradient.
void drawGradient(GradientDrawable gradient) {
Orientation o = gradient.orientation;
Rectangle r = gradient.bounds;
int[] colors = gradient.colors;
int clen = colors.length;
if (Orientation.TOP_BOTTOM.equals(o) || Orientation.BOTTOM_TOP.equals(o)) {
if (Orientation.BOTTOM_TOP.equals(o)) {
colors = new int[clen];
for (int i = 0; i < clen; i++) {
colors[i] = gradient.colors[clen - i - 1];
}
}
g.fillLinearGradient(colors[0], colors[clen - 1], r.getX(), r.getY(), r.getWidth(), r.getHeight(), false);
} else if (Orientation.LEFT_RIGHT.equals(o)) {
g.fillLinearGradient(gradient.colors[0], gradient.colors[clen - 1], r.getX(), r.getY(), r.getWidth(), r.getHeight(), true);
} else {
Log.p("Gradient with type " + o + " not implemented yet. Just filling solid rect");
g.setColor(gradient.colors[0]);
g.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
}
use of com.codename1.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class Dialog method showPopupDialog.
/**
* A popup dialog is shown with the context of a component and its selection, it is disposed seamlessly if the back button is pressed
* or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
* dialog has the PopupDialog style by default.
*
* @param rect the screen rectangle to which the popup should point
* @return the command that might have been triggered by the user within the dialog if commands are placed in the dialog
*/
public Command showPopupDialog(Rectangle rect) {
if (getDialogUIID().equals("Dialog")) {
setDialogUIID("PopupDialog");
if (getTitleComponent().getUIID().equals("DialogTitle")) {
getTitleComponent().setUIID("PopupDialogTitle");
}
getContentPane().setUIID("PopupContentPane");
}
disposeOnRotation = true;
disposeWhenPointerOutOfBounds = true;
Command backCommand = null;
if (getBackCommand() == null) {
backCommand = new Command("Back");
setBackCommand(backCommand);
}
Component contentPane = super.getContentPane();
Label title = super.getTitleComponent();
int menuHeight = calcMenuHeight();
UIManager manager = getUIManager();
// preferred size logic of the dialog won't work with large title borders
if (dialogTitle != null && manager.isThemeConstant("hideEmptyTitleBool", false)) {
boolean b = getTitle().length() > 0;
getTitleArea().setVisible(b);
getTitleComponent().setVisible(b);
if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
getTitleComponent().setPreferredSize(new Dimension(0, 0));
getTitleComponent().getStyle().setBorder(null);
getTitleArea().setPreferredSize(new Dimension(0, 0));
if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
int titlePT = getTitleComponent().getStyle().getPaddingTop();
byte[] pu = getContentPane().getStyle().getPaddingUnit();
if (pu == null) {
pu = new byte[4];
}
pu[0] = Style.UNIT_TYPE_PIXELS;
getContentPane().getStyle().setPaddingUnit(pu);
int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
}
}
}
// allows a text area to recalculate its preferred size if embedded within a dialog
revalidate();
Style contentPaneStyle = getDialogStyle();
boolean restoreArrow = false;
if (manager.isThemeConstant(getDialogUIID() + "ArrowBool", false)) {
Image t = manager.getThemeImageConstant(getDialogUIID() + "ArrowTopImage");
Image b = manager.getThemeImageConstant(getDialogUIID() + "ArrowBottomImage");
Image l = manager.getThemeImageConstant(getDialogUIID() + "ArrowLeftImage");
Image r = manager.getThemeImageConstant(getDialogUIID() + "ArrowRightImage");
Border border = contentPaneStyle.getBorder();
if (border != null) {
border.setImageBorderSpecialTile(t, b, l, r, rect);
restoreArrow = true;
}
}
int prefHeight = contentPane.getPreferredH();
int prefWidth = contentPane.getPreferredW();
if (contentPaneStyle.getBorder() != null) {
prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
}
prefWidth += getUIManager().getLookAndFeel().getVerticalScrollWidth();
int availableHeight = Display.getInstance().getDisplayHeight() - menuHeight - title.getPreferredH();
int availableWidth = Display.getInstance().getDisplayWidth();
int width = Math.min(availableWidth, prefWidth);
int x = 0;
int y = 0;
Command result;
boolean showPortrait;
if (popupDirectionBiasPortrait != null) {
showPortrait = popupDirectionBiasPortrait.booleanValue();
} else {
showPortrait = Display.getInstance().isPortrait();
}
// if we don't have enough space then disregard device orientation
if (showPortrait) {
if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
showPortrait = false;
}
} else {
if (availableHeight / 2 > availableWidth - rect.getWidth()) {
showPortrait = true;
}
}
if (showPortrait) {
if (width < availableWidth) {
int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
// if the ideal position is less than 0 just use 0
if (idealX > 0) {
// if the idealX is too far to the right just align to the right
if (idealX + width > availableWidth) {
x = availableWidth - width;
} else {
x = idealX;
}
}
}
if (rect.getY() < availableHeight / 2) {
// popup downwards
y = rect.getY() + rect.getSize().getHeight();
int height = Math.min(prefHeight, availableHeight - y);
result = show(y, availableHeight - height - y, x, availableWidth - width - x, true, true);
} else {
// popup upwards
int height = Math.min(prefHeight, availableHeight - (availableHeight - rect.getY()));
y = rect.getY() - height;
result = show(y, availableHeight - height - y, x, availableWidth - width - x, true, true);
}
} else {
int height = Math.min(prefHeight, availableHeight);
if (height < availableHeight) {
int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
// if the ideal position is less than 0 just use 0
if (idealY > 0) {
// if the idealY is too far up just align to the top
if (idealY + height > availableHeight) {
y = availableHeight - height;
} else {
y = idealY;
}
}
}
if (prefWidth > rect.getX()) {
// popup right
x = rect.getX() + rect.getSize().getWidth();
if (x + prefWidth > availableWidth) {
x = availableWidth - prefWidth;
}
width = Math.min(prefWidth, availableWidth - x);
result = show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x), true, true);
} else {
// popup left
width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
x = rect.getX() - width;
result = show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x), true, true);
}
}
if (restoreArrow) {
contentPaneStyle.getBorder().clearImageBorderSpecialTile();
}
if (result == backCommand) {
return null;
}
return result;
}
Aggregations