use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class GlassTutorial method showOn.
/**
* Install the glass tutorial on a form and seamlessly dismiss it when no longer necessary
* @param f the form
*/
public void showOn(Form f) {
Painter oldPane = f.getGlassPane();
f.setGlassPane(this);
Dialog dummy = new Dialog() {
public void keyReleased(int i) {
dispose();
}
};
int oldTint = f.getTintColor();
f.setTintColor(0);
dummy.getDialogStyle().setBgTransparency(0);
dummy.setDisposeWhenPointerOutOfBounds(true);
dummy.show(0, Display.getInstance().getDisplayHeight() - 2, 0, Display.getInstance().getDisplayWidth() - 2, true, true);
f.setTintColor(oldTint);
f.setGlassPane(oldPane);
}
use of com.codename1.ui.Dialog 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.Dialog in project CodenameOne by codenameone.
the class ResourceEditorApp method migrateGuiBuilder.
private static void migrateGuiBuilder(File projectDir, EditableResources res, String destPackageName) throws IOException {
File propertiesFile = new File(projectDir, "codenameone_settings.properties");
Properties props = new Properties();
FileInputStream pIn = new FileInputStream(propertiesFile);
props.load(pIn);
pIn.close();
if (props.getProperty("guiResource") == null) {
System.out.println("Not a legacy GUI builder project!\nConversion failed!");
System.exit(1);
return;
}
UserInterfaceEditor.exportToNewGuiBuilderMode = true;
String mainForm = props.getProperty("mainForm");
File stateMachineBase = new File(projectDir, "src" + File.separatorChar + "generated" + File.separator + "StateMachineBase.java");
StringBuilder stateMachineBaseSource = new StringBuilder("/**\n * This class was generated by the migration wizard, ultimately both it and the Statemachine can be removed.\n");
stateMachineBaseSource.append(" * This class is no longer updated automatically\n");
stateMachineBaseSource.append("*/\n");
stateMachineBaseSource.append("package generated;\n");
stateMachineBaseSource.append("\nimport com.codename1.ui.*;\n");
stateMachineBaseSource.append("import com.codename1.ui.util.*;\n");
stateMachineBaseSource.append("import com.codename1.ui.plaf.*;\n");
stateMachineBaseSource.append("import java.util.Hashtable;\n");
stateMachineBaseSource.append("import com.codename1.ui.events.*;\n\n");
stateMachineBaseSource.append("public abstract class StateMachineBase extends UIBuilder {\n");
stateMachineBaseSource.append(" private static final java.util.HashMap<String, Class> formNameToClassHashMap = new java.util.HashMap<String, Class>();");
stateMachineBaseSource.append(" public static StateMachineBase instance;");
stateMachineBaseSource.append(" protected void initVars() {}\n\n");
stateMachineBaseSource.append(" protected void initVars(Resources res) {}\n\n");
stateMachineBaseSource.append(" public StateMachineBase(Resources res, String resPath, boolean loadTheme) {\n instance = this;\n");
stateMachineBaseSource.append(" startApp(res, resPath, loadTheme);\n");
stateMachineBaseSource.append(" }\n\n\n");
stateMachineBaseSource.append(" public Container startApp(Resources res, String resPath, boolean loadTheme) {\n");
stateMachineBaseSource.append(" initVars();\n");
stateMachineBaseSource.append(" if(loadTheme) {\n");
stateMachineBaseSource.append(" if(res == null) {\n");
stateMachineBaseSource.append(" try {\n");
stateMachineBaseSource.append(" if(resPath.endsWith(\".res\")) {\n");
stateMachineBaseSource.append(" res = Resources.open(resPath);\n");
stateMachineBaseSource.append(" System.out.println(\"Warning: you should construct the state machine without the .res extension to allow theme overlays\");\n");
stateMachineBaseSource.append(" } else {\n");
stateMachineBaseSource.append(" res = Resources.openLayered(resPath);\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" } catch(java.io.IOException err) { err.printStackTrace(); }\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" initTheme(res);\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" if(res != null) {\n");
stateMachineBaseSource.append(" setResourceFilePath(resPath);\n");
stateMachineBaseSource.append(" setResourceFile(res);\n");
stateMachineBaseSource.append(" Resources.setGlobalResources(res);");
stateMachineBaseSource.append(" initVars(res);\n");
stateMachineBaseSource.append(" return showForm(getFirstFormName(), null);\n");
stateMachineBaseSource.append(" } else {\n");
stateMachineBaseSource.append(" Form f = (Form)createContainer(resPath, getFirstFormName());\n");
stateMachineBaseSource.append(" Resources.setGlobalResources(fetchResourceFile());");
stateMachineBaseSource.append(" initVars(fetchResourceFile());\n");
stateMachineBaseSource.append(" beforeShow(f);\n");
stateMachineBaseSource.append(" f.show();\n");
stateMachineBaseSource.append(" postShow(f);\n");
stateMachineBaseSource.append(" return f;\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" }\n\n\n");
stateMachineBaseSource.append(" protected String getFirstFormName() {\n");
stateMachineBaseSource.append(" return \"");
stateMachineBaseSource.append(mainForm);
stateMachineBaseSource.append("\";\n");
stateMachineBaseSource.append(" }\n\n\n");
stateMachineBaseSource.append(" protected void initTheme(Resources res) {\n");
stateMachineBaseSource.append(" String[] themes = res.getThemeResourceNames();\n");
stateMachineBaseSource.append(" Resources.setGlobalResources(res);\n");
stateMachineBaseSource.append(" if(themes != null && themes.length > 0) {\n");
stateMachineBaseSource.append(" UIManager.getInstance().setThemeProps(res.getTheme(themes[0]));\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" }\n\n\n");
stateMachineBaseSource.append(" public StateMachineBase() {\n instance = this;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public StateMachineBase(String resPath) {\n");
stateMachineBaseSource.append(" this(null, resPath, true);\n instance = this;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public StateMachineBase(Resources res) {\n");
stateMachineBaseSource.append(" this(res, null, true);\n instance = this;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public StateMachineBase(String resPath, boolean loadTheme) {\n");
stateMachineBaseSource.append(" this(null, resPath, loadTheme);\n instance = this;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public StateMachineBase(Resources res, boolean loadTheme) {\n");
stateMachineBaseSource.append(" this(res, null, loadTheme);\n instance = this;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public Form showForm(String resourceName, Command sourceCommand) {\n");
stateMachineBaseSource.append(" try {\n");
stateMachineBaseSource.append(" Form f = (Form)formNameToClassHashMap.get(resourceName).newInstance();\n");
stateMachineBaseSource.append(" Form current = Display.getInstance().getCurrent();\n");
stateMachineBaseSource.append(" if(current != null && isBackCommandEnabled() && allowBackTo(resourceName)) {\n");
stateMachineBaseSource.append(" f.putClientProperty(\"previousForm\", current);\n");
stateMachineBaseSource.append(" setBackCommand(f, new Command(getBackCommandText(current.getTitle())) {\n");
stateMachineBaseSource.append(" public void actionPerformed(ActionEvent evt) {\n");
stateMachineBaseSource.append(" back(null);\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" });\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" if(sourceCommand != null && current != null && current.getBackCommand() == sourceCommand) {\n");
stateMachineBaseSource.append(" f.showBack();\n");
stateMachineBaseSource.append(" } else {\n");
stateMachineBaseSource.append(" f.show();\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" return f;\n");
stateMachineBaseSource.append(" } catch(Exception err) {\n");
stateMachineBaseSource.append(" err.printStackTrace();\n");
stateMachineBaseSource.append(" throw new RuntimeException(\"Form not found: \" + resourceName);\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" protected void beforeShow(Form f) {\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public final void beforeShow__(Form f) {\n beforeShow(f);\n");
stateMachineBaseSource.append(" if(Display.getInstance().getCurrent() != null) {\n");
stateMachineBaseSource.append(" exitForm(Display.getInstance().getCurrent());\n");
stateMachineBaseSource.append(" invokeFormExit__(Display.getInstance().getCurrent());\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" protected void exitForm(Form f) {\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" protected void postShow(Form f) {\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public final void postShow__(Form f) {\n postShow(f);\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" private Container getRootComponent__(Component rootComponent) {\n");
stateMachineBaseSource.append(" if(rootComponent.getParent() != null) {\n");
stateMachineBaseSource.append(" return getRoot__(rootComponent.getParent());\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" return (Container)rootComponent;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" private Container getRoot__(Container rootComponent) {\n");
stateMachineBaseSource.append(" Container p = rootComponent.getParent();\n");
stateMachineBaseSource.append(" while(p != null) {\n");
stateMachineBaseSource.append(" rootComponent = p;\n");
stateMachineBaseSource.append(" p = rootComponent.getParent();\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" return rootComponent;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public Component findByName(String componentName, Container rootComponent) {\n");
stateMachineBaseSource.append(" Container root = getRoot__(rootComponent);\n");
stateMachineBaseSource.append(" return findByName__(componentName, root);\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public Component findByName__(String componentName, Container root) {\n");
stateMachineBaseSource.append(" int count = root.getComponentCount();\n");
stateMachineBaseSource.append(" for(int iter = 0 ; iter < count ; iter++) {\n");
stateMachineBaseSource.append(" Component c = root.getComponentAt(iter);\n");
stateMachineBaseSource.append(" String n = c.getName();\n");
stateMachineBaseSource.append(" if(n != null && n.equals(componentName)) {\n");
stateMachineBaseSource.append(" return c;\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" if(c instanceof Container && ((Container)c).getLeadComponent() == null) {\n");
stateMachineBaseSource.append(" c = findByName__(componentName, (Container)c);\n");
stateMachineBaseSource.append(" if(c != null) {\n");
stateMachineBaseSource.append(" return c;\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" return null;\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" protected void handleComponentAction(Component c, ActionEvent event) {\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public void handleComponentAction__(Component c, ActionEvent event) {\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public void processCommand__(ActionEvent ev, Command cmd) {\n");
stateMachineBaseSource.append(" processCommand(ev, cmd);\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public void back() {\n");
stateMachineBaseSource.append(" back(null);\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public void back(Component sourceComponent) {\n");
stateMachineBaseSource.append(" Form current = (Form)Display.getInstance().getCurrent().getClientProperty(\"previousForm\");\n");
stateMachineBaseSource.append(" current.showBack();\n");
stateMachineBaseSource.append(" }\n\n");
StringBuilder formNameMapBuilder = new StringBuilder("static {");
StringBuilder invokeFormExitBuilder = new StringBuilder(" private void invokeFormExit__(Form f) {\n");
UserInterfaceEditor.componentNames = new HashMap<String, Class>();
UserInterfaceEditor.commandList = new ArrayList<ActionCommand>();
for (String uiName : res.getUIResourceNames()) {
System.out.println("Processing: " + uiName);
String fileName = convertToVarName(uiName);
formNameMapBuilder.append(" formNameToClassHashMap.put(\"");
formNameMapBuilder.append(uiName);
formNameMapBuilder.append("\", ");
formNameMapBuilder.append(destPackageName);
formNameMapBuilder.append(".");
formNameMapBuilder.append(fileName);
formNameMapBuilder.append(".class);\n");
String normalizedUiName = ResourceEditorView.normalizeFormName(uiName);
if (RESEVERVED_WORDS.contains(fileName)) {
fileName += "X";
} else {
try {
if (Class.forName("java.lang." + fileName) != null) {
fileName += "X";
}
} catch (Throwable t) {
// passed...
}
}
File guiFile = new File(projectDir, "res" + File.separatorChar + "guibuilder" + File.separatorChar + destPackageName.replace('.', File.separatorChar) + File.separatorChar + fileName + ".gui");
guiFile.getParentFile().mkdirs();
File sourcePackageDir = new File(projectDir, "src" + File.separatorChar + destPackageName.replace('.', File.separatorChar));
sourcePackageDir.mkdirs();
File sourceFile = new File(sourcePackageDir, fileName + ".java");
UIBuilderOverride u = new UIBuilderOverride();
com.codename1.ui.Container cnt = u.createContainer(res, uiName);
FileOutputStream fos = new FileOutputStream(guiFile);
Writer w = new OutputStreamWriter(fos, "UTF-8");
w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
StringBuilder bld = new StringBuilder();
UserInterfaceEditor.actionEventNames = new ArrayList<String>();
UserInterfaceEditor.listNames = new ArrayList<String>();
UserInterfaceEditor.persistToXML(cnt, cnt, bld, res, "");
w.write(bld.toString());
w.flush();
w.close();
fos = new FileOutputStream(sourceFile);
w = new OutputStreamWriter(fos, "UTF-8");
w.write("package ");
w.write(destPackageName);
w.write(";\n");
w.write("\n");
w.write("/**\n");
w.write(" * GUI builder created Form\n");
w.write(" */\n");
w.write("public class ");
w.write(fileName);
String prePostCode;
w.write(" extends com.codename1.ui.");
if (cnt instanceof com.codename1.ui.Form) {
invokeFormExitBuilder.append(" if(f.getName().equals(\"");
invokeFormExitBuilder.append(uiName);
invokeFormExitBuilder.append("\")) {\n");
invokeFormExitBuilder.append(" exit");
invokeFormExitBuilder.append(normalizedUiName);
invokeFormExitBuilder.append("(f);\n }\n");
stateMachineBaseSource.append(" protected void before");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("(Form f) {\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public final void before");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("__(Form f) {\n before");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("(f);\n }\n\n");
stateMachineBaseSource.append(" protected void post");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("(Form f) {\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append(" public final void post");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("__(Form f) {\n post");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("(f);\n }\n\n");
stateMachineBaseSource.append(" protected void exit");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("(Form f) {\n");
stateMachineBaseSource.append(" }\n\n");
}
if (cnt instanceof com.codename1.ui.Dialog) {
w.write("Dialog");
prePostCode = "\n public void initComponent() {\n generated.StateMachineBase.instance.beforeShow__(this);\n";
prePostCode += " generated.StateMachineBase.instance.before";
prePostCode += normalizedUiName;
prePostCode += "__(this);\n }\n";
prePostCode = "\n public void onShow() {\n generated.StateMachineBase.instance.postShow__(this);\n";
prePostCode += " generated.StateMachineBase.instance.post";
prePostCode += normalizedUiName;
prePostCode += "__(this);\n }\n";
prePostCode += " protected void actionCommand(com.codename1.ui.Command cmd) {\n";
prePostCode += " generated.StateMachineBase.instance.processCommand__(new com.codename1.ui.events.ActionEvent(cmd), cmd);\n";
prePostCode += " }\n\n";
} else {
if (cnt instanceof com.codename1.ui.Form) {
w.write("Form");
prePostCode = "\n public void show() {\n generated.StateMachineBase.instance.beforeShow__(this);\n";
prePostCode += " generated.StateMachineBase.instance.before";
prePostCode += normalizedUiName;
prePostCode += "__(this);\n super.show();\n generated.StateMachineBase.instance.post";
prePostCode += normalizedUiName;
prePostCode += "__(this);\n }\n";
prePostCode += " protected void actionCommand(com.codename1.ui.Command cmd) {\n";
prePostCode += " generated.StateMachineBase.instance.processCommand__(new com.codename1.ui.events.ActionEvent(cmd), cmd);\n";
prePostCode += " }\n\n";
} else {
w.write("Container");
prePostCode = "";
}
}
w.write(" {\n public ");
w.write(fileName);
w.write("() {\n");
w.write(" this(com.codename1.ui.util.Resources.getGlobalResources());\n");
w.write(" }\n \n public ");
w.write(fileName);
w.write("(com.codename1.ui.util.Resources resourceObjectInstance) {\n");
w.write(" initGuiBuilderComponents(resourceObjectInstance);\n");
w.write(" }\n\n");
w.write("//-- DON'T EDIT BELOW THIS LINE!!!\n\n private void initGuiBuilderComponents(com.codename1.ui.util.Resources resourceObjectInstance) {}\n\n");
w.write("//-- DON'T EDIT ABOVE THIS LINE!!!\n");
for (String actionListenerNames : UserInterfaceEditor.actionEventNames) {
w.write("\n public void on");
w.write(actionListenerNames);
w.write("ActionEvent(com.codename1.ui.events.ActionEvent ev) {\n ");
w.write("generated.StateMachineBase.instance.handleComponentAction__((com.codename1.ui.Component)ev.getSource(), ev);\n ");
w.write("generated.StateMachineBase.instance.on");
w.write(normalizedUiName);
w.write("_");
String normalizedActionListenerName = ResourceEditorView.normalizeFormName(actionListenerNames);
w.write(normalizedActionListenerName);
w.write("Action__((com.codename1.ui.Component)ev.getSource(), ev);\n }\n\n");
stateMachineBaseSource.append(" protected void on");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("_");
stateMachineBaseSource.append(normalizedActionListenerName);
stateMachineBaseSource.append("Action(Component cmp, ActionEvent ev) {\n }\n\n");
stateMachineBaseSource.append(" public void on");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("_");
stateMachineBaseSource.append(normalizedActionListenerName);
stateMachineBaseSource.append("Action__(Component cmp, ActionEvent ev) {\n on");
stateMachineBaseSource.append(normalizedUiName);
stateMachineBaseSource.append("_");
stateMachineBaseSource.append(normalizedActionListenerName);
stateMachineBaseSource.append("Action(cmp, ev);\n }\n\n");
}
w.write(prePostCode);
w.write("}\n");
w.flush();
w.close();
}
formNameMapBuilder.append("}\n");
invokeFormExitBuilder.append("}\n");
stateMachineBaseSource.append(formNameMapBuilder);
stateMachineBaseSource.append(invokeFormExitBuilder);
ArrayList<String> uniqueNames = new ArrayList<String>();
for (String cmpName : UserInterfaceEditor.componentNames.keySet()) {
String nomName = ResourceEditorView.normalizeFormName(cmpName);
if (uniqueNames.contains(nomName)) {
continue;
}
uniqueNames.add(nomName);
stateMachineBaseSource.append(" public ");
stateMachineBaseSource.append(UserInterfaceEditor.componentNames.get(cmpName).getName());
stateMachineBaseSource.append(" find");
stateMachineBaseSource.append(nomName);
stateMachineBaseSource.append("(Component root) {\n return (");
stateMachineBaseSource.append(UserInterfaceEditor.componentNames.get(cmpName).getName());
stateMachineBaseSource.append(")findByName(\"");
stateMachineBaseSource.append(cmpName);
stateMachineBaseSource.append("\", getRootComponent__(root));\n }\n\n");
stateMachineBaseSource.append(" public ");
stateMachineBaseSource.append(UserInterfaceEditor.componentNames.get(cmpName).getName());
stateMachineBaseSource.append(" find");
stateMachineBaseSource.append(nomName);
stateMachineBaseSource.append("() {\n return (");
stateMachineBaseSource.append(UserInterfaceEditor.componentNames.get(cmpName).getName());
stateMachineBaseSource.append(")findByName(\"");
stateMachineBaseSource.append(cmpName);
stateMachineBaseSource.append("\", Display.getInstance().getCurrent());\n }\n\n");
}
ArrayList<Integer> commandIdsAdded = new ArrayList<Integer>();
ArrayList<String> commandNamesAdded = new ArrayList<String>();
for (ActionCommand cmd : UserInterfaceEditor.commandList) {
String formName = (String) cmd.getClientProperty("FORMNAME");
if (formName == null) {
continue;
}
String normalizedCommandName = ResourceEditorView.normalizeFormName(formName) + ResourceEditorView.normalizeFormName(cmd.getCommandName());
if (commandNamesAdded.contains(normalizedCommandName)) {
continue;
}
if (commandIdsAdded.contains(cmd.getId())) {
continue;
}
commandIdsAdded.add(cmd.getId());
commandNamesAdded.add(normalizedCommandName);
stateMachineBaseSource.append(" public static final int COMMAND_");
stateMachineBaseSource.append(normalizedCommandName);
stateMachineBaseSource.append(" = ");
stateMachineBaseSource.append(cmd.getId());
stateMachineBaseSource.append(";\n\n protected boolean on");
stateMachineBaseSource.append(normalizedCommandName);
stateMachineBaseSource.append("() {\n return false;\n }\n\n");
}
stateMachineBaseSource.append(" protected void processCommand(ActionEvent ev, Command cmd) {\n");
stateMachineBaseSource.append(" switch(cmd.getId()) {\n");
commandIdsAdded.clear();
commandNamesAdded.clear();
for (ActionCommand cmd : UserInterfaceEditor.commandList) {
String formName = (String) cmd.getClientProperty("FORMNAME");
if (formName == null) {
continue;
}
String normalizedCommandName = ResourceEditorView.normalizeFormName(formName) + ResourceEditorView.normalizeFormName(cmd.getCommandName());
if (commandNamesAdded.contains(normalizedCommandName)) {
continue;
}
if (commandIdsAdded.contains(cmd.getId())) {
continue;
}
commandIdsAdded.add(cmd.getId());
commandNamesAdded.add(normalizedCommandName);
stateMachineBaseSource.append("\n case COMMAND_");
stateMachineBaseSource.append(normalizedCommandName);
stateMachineBaseSource.append(":\n");
if (cmd.getAction() != null && cmd.getAction().length() > 0) {
if (!cmd.getAction().startsWith("$")) {
stateMachineBaseSource.append(" showForm(\"");
stateMachineBaseSource.append(cmd.getAction());
stateMachineBaseSource.append("\", null);\n");
}
}
stateMachineBaseSource.append(" if(on");
stateMachineBaseSource.append(normalizedCommandName);
stateMachineBaseSource.append("()) {\n");
stateMachineBaseSource.append(" ev.consume();\n");
stateMachineBaseSource.append(" return;\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" break;\n\n");
}
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" if(ev.getComponent() != null) {\n");
stateMachineBaseSource.append(" handleComponentAction(ev.getComponent(), ev);\n");
stateMachineBaseSource.append(" }\n");
stateMachineBaseSource.append(" }\n\n");
stateMachineBaseSource.append("\n}\n");
FileOutputStream sbout = new FileOutputStream(stateMachineBase);
sbout.write(stateMachineBaseSource.toString().getBytes("UTF-8"));
sbout.close();
props.remove("mainForm");
props.remove("package");
props.remove("guiResource");
props.remove("baseClass");
props.remove("userClass");
FileOutputStream pOut = new FileOutputStream(propertiesFile);
props.store(pOut, "Updated by GUI builder migration wizard");
pOut.close();
System.out.println("Conversion completed successfully!");
System.exit(0);
}
use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class CodenameOneImplementation method openGallery.
/**
* Opens the device gallery
* The method returns immediately and the response will be sent asynchronously
* to the given ActionListener Object
*
* use this in the actionPerformed to retrieve the file path
* String path = (String) evt.getSource();
*
* @param response a callback Object to retrieve the file path
* @param type one of the following GALLERY_IMAGE, GALLERY_VIDEO, GALLERY_ALL
* @throws RuntimeException if this feature failed or unsupported on the platform
*/
public void openGallery(final ActionListener response, int type) {
final Dialog d = new Dialog("Select a picture");
d.setLayout(new BorderLayout());
FileTreeModel model = new FileTreeModel(true);
if (type == Display.GALLERY_IMAGE) {
model.addExtensionFilter("jpg");
model.addExtensionFilter("png");
} else if (type == Display.GALLERY_VIDEO) {
model.addExtensionFilter("mp4");
model.addExtensionFilter("3pg");
model.addExtensionFilter("avi");
model.addExtensionFilter("mov");
} else if (type == Display.GALLERY_ALL) {
model.addExtensionFilter("jpg");
model.addExtensionFilter("png");
model.addExtensionFilter("mp4");
model.addExtensionFilter("3pg");
model.addExtensionFilter("avi");
model.addExtensionFilter("mov");
}
FileTree t = new FileTree(model) {
protected Button createNodeComponent(final Object node, int depth) {
if (node == null || !getModel().isLeaf(node)) {
return super.createNodeComponent(node, depth);
}
Hashtable t = (Hashtable) Storage.getInstance().readObject("thumbnails");
if (t == null) {
t = new Hashtable();
}
final Hashtable thumbs = t;
final Button b = super.createNodeComponent(node, depth);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
response.actionPerformed(new ActionEvent(node, ActionEvent.Type.Other));
d.dispose();
}
});
final ImageIO imageio = ImageIO.getImageIO();
if (imageio != null) {
Display.getInstance().scheduleBackgroundTask(new Runnable() {
public void run() {
byte[] data = (byte[]) thumbs.get(node);
if (data == null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
imageio.save(FileSystemStorage.getInstance().openInputStream((String) node), out, ImageIO.FORMAT_JPEG, b.getIcon().getWidth(), b.getIcon().getHeight(), 1);
data = out.toByteArray();
thumbs.put(node, data);
Storage.getInstance().writeObject("thumbnails", thumbs);
} catch (IOException ex) {
Log.e(ex);
}
}
Image im = Image.createImage(data, 0, data.length);
b.setIcon(im);
}
});
}
return b;
}
};
d.addComponent(BorderLayout.CENTER, t);
d.placeButtonCommands(new Command[] { new Command("Cancel") });
Command c = d.showAtPosition(2, 2, 2, 2, true);
if (c != null) {
response.actionPerformed(null);
}
}
use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class Oauth2 method showAuthentication.
/**
* This method shows an authentication for login form
*
* @param al a listener that will receive at its source either a token for
* the service or an exception in case of a failure
* @return a component that should be displayed to the user in order to
* perform the authentication
*/
public void showAuthentication(ActionListener al) {
final Form old = Display.getInstance().getCurrent();
InfiniteProgress inf = new InfiniteProgress();
final Dialog progress = inf.showInifiniteBlocking();
Form authenticationForm = new Form("Login");
authenticationForm.setScrollable(false);
if (old != null) {
Command cancel = new Command("Cancel") {
public void actionPerformed(ActionEvent ev) {
if (Display.getInstance().getCurrent() == progress) {
progress.dispose();
}
old.showBack();
}
};
if (authenticationForm.getToolbar() != null) {
authenticationForm.getToolbar().addCommandToLeftBar(cancel);
} else {
authenticationForm.addCommand(cancel);
}
authenticationForm.setBackCommand(cancel);
}
authenticationForm.setLayout(new BorderLayout());
authenticationForm.addComponent(BorderLayout.CENTER, createLoginComponent(al, authenticationForm, old, progress));
}
Aggregations