use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class JSDialogHandler method onJSDialog.
@Override
public boolean onJSDialog(final CefBrowser browser, final String origin_url, final JSDialogType dialog_type, final String message_text, final String default_prompt_text, final CefJSDialogCallback callback, BoolRef suppress_message) {
switch(dialog_type) {
case JSDIALOGTYPE_ALERT:
CN.callSerially(new Runnable() {
public void run() {
final Sheet sheet = new Sheet(null, origin_url + " says");
sheet.setPosition(com.codename1.ui.layouts.BorderLayout.CENTER);
SpanLabel lbl = new SpanLabel(message_text);
sheet.getContentPane().setLayout(new BorderLayout());
sheet.getContentPane().add(BorderLayout.CENTER, lbl);
sheet.addCloseListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
EventQueue.invokeLater(new Runnable() {
public void run() {
callback.Continue(true, "");
}
});
}
});
Button btn = new Button("OK");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sheet.back();
}
});
sheet.getContentPane().add(BorderLayout.SOUTH, btn);
sheet.show();
// Dialog.show(origin_url+" says", message_text, "OK", null);
// callback.Continue(true, "");
}
});
return true;
case JSDIALOGTYPE_CONFIRM:
CN.callSerially(new Runnable() {
public void run() {
final Sheet sheet = new Sheet(null, origin_url + " says");
sheet.setPosition(com.codename1.ui.layouts.BorderLayout.CENTER);
SpanLabel lbl = new SpanLabel(message_text);
sheet.getContentPane().setLayout(new BorderLayout());
sheet.getContentPane().add(BorderLayout.CENTER, lbl);
final boolean[] callbackComplete = new boolean[1];
sheet.addCloseListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
EventQueue.invokeLater(new Runnable() {
public void run() {
if (callbackComplete[0]) {
return;
}
callbackComplete[0] = true;
callback.Continue(false, "");
}
});
}
});
Button okBtn = new Button("OK");
okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
EventQueue.invokeLater(new Runnable() {
public void run() {
if (callbackComplete[0]) {
return;
}
callbackComplete[0] = true;
callback.Continue(true, "");
}
});
sheet.back();
}
});
Button cancelBtn = new Button("Cancel");
cancelBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sheet.back();
}
});
sheet.getContentPane().add(BorderLayout.SOUTH, GridLayout.encloseIn(2, okBtn, cancelBtn));
sheet.show();
// Dialog.show(origin_url+" says", message_text, "OK", null);
// callback.Continue(true, "");
}
});
return true;
case JSDIALOGTYPE_PROMPT:
CN.callSerially(new Runnable() {
public void run() {
final Sheet sheet = new Sheet(null, origin_url + " says");
sheet.setPosition(com.codename1.ui.layouts.BorderLayout.CENTER);
SpanLabel lbl = new SpanLabel(message_text);
sheet.getContentPane().setLayout(new BorderLayout());
final TextField input = new TextField();
if (default_prompt_text != null) {
input.setText(default_prompt_text);
}
sheet.getContentPane().add(BorderLayout.CENTER, BoxLayout.encloseY(lbl, input));
final boolean[] callbackComplete = new boolean[1];
sheet.addCloseListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
EventQueue.invokeLater(new Runnable() {
public void run() {
if (callbackComplete[0]) {
return;
}
callbackComplete[0] = true;
callback.Continue(false, null);
}
});
}
});
Button okBtn = new Button("OK");
okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
EventQueue.invokeLater(new Runnable() {
public void run() {
if (callbackComplete[0]) {
return;
}
callbackComplete[0] = true;
callback.Continue(true, input.getText());
}
});
sheet.back();
}
});
Button cancelBtn = new Button("Cancel");
cancelBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sheet.back();
}
});
sheet.getContentPane().add(BorderLayout.SOUTH, GridLayout.encloseIn(2, okBtn, cancelBtn));
sheet.show();
input.requestFocus();
// Dialog.show(origin_url+" says", message_text, "OK", null);
// callback.Continue(true, "");
}
});
return true;
}
if (message_text.equalsIgnoreCase("Never displayed")) {
suppress_message.set(true);
System.out.println("The " + dialog_type + " from origin \"" + origin_url + "\" was suppressed.");
System.out.println(" The content of the suppressed dialog was: \"" + message_text + "\"");
}
return false;
}
use of com.codename1.components.Switch in project CodeRAD by shannah.
the class ActionNode method createCommand.
/**
* Creates a command from the action using the given entity and source componentas a context.
* @param entity
* @param source
* @return
*/
public Command createCommand(Entity entity, Component source) {
ActionStyle style = getActionStyle();
if (style == null) {
style = ActionStyle.IconRight;
}
ActionListener l = ev -> {
fireEvent(entity, source);
};
switch(style) {
case IconOnly:
if (getMaterialIcon() != null) {
return Command.createMaterial("", getMaterialIcon().getValue(), l);
} else if (getImageIcon() != null) {
return Command.create("", getImageIcon().getValue(), l);
} else {
return new Command("") {
@Override
public void actionPerformed(ActionEvent evt) {
l.actionPerformed(evt);
}
};
}
case TextOnly:
return Command.create(getLabelText(), null, l);
default:
if (getMaterialIcon() != null) {
return Command.createMaterial(getLabelText(), getMaterialIcon().getValue(), l);
} else if (getImageIcon() != null) {
return Command.create(getLabelText(), getImageIcon().getValue(), l);
} else {
return new Command(str(getLabelText())) {
public void actionPerformed(ActionEvent evt) {
l.actionPerformed(evt);
}
};
}
}
}
use of com.codename1.components.Switch in project CodeRAD by shannah.
the class DefaultActionViewFactory method initUI.
public static void initUI(Button btn, Entity entity, ActionNode action) {
btn.setBlockLead(true);
boolean text = action.isTextStyle();
boolean includeIcon = action.isIconStyle();
UIID uiid = action.getUIID();
if (uiid != null) {
btn.setUIID(uiid.getValue(entity));
}
IconUIID iconUiid = action.getIconUIID();
if (iconUiid != null) {
btn.setIconUIID(iconUiid.getValue());
}
Button button = btn;
if (action.getLabel() != null && text) {
button.setText(action.getLabel().getValue(entity.getEntity()));
}
if (!text && button.getText().length() > 0) {
button.setText("");
}
if (action.getImageIcon() != null && includeIcon) {
button.setIcon(action.getImageIcon().getValue());
if (action.getSelected() != action && action.getSelected().getImageIcon() != action.getImageIcon()) {
button.setRolloverIcon(action.getSelected().getImageIcon().getValue());
}
if (action.getPressed() != action && action.getPressed().getImageIcon() != action.getImageIcon()) {
button.setPressedIcon(action.getPressed().getImageIcon().getValue());
}
if (action.getDisabled() != action && action.getDisabled().getImageIcon() != action.getImageIcon()) {
button.setDisabledIcon(action.getDisabled().getImageIcon().getValue());
}
}
if (action.getMaterialIcon() != null && includeIcon) {
char unselectedIcon = action.getMaterialIcon().getValue();
char selectedIcon = action.getSelected().getMaterialIcon().getValue();
char pressedIcon = action.getPressed().getMaterialIcon().getValue();
char selectedPressed = pressedIcon;
if (action.getPressed() == action) {
selectedPressed = selectedIcon;
}
char disabledIcon = action.getDisabled().getMaterialIcon().getValue();
// button.setMaterialIcon(action.getMaterialIcon().getValue());
FontImage.setMaterialIcon(btn, new char[] { unselectedIcon, selectedIcon, pressedIcon, selectedPressed, disabledIcon }, -1);
}
if (action.getTextIcon() != null && includeIcon) {
String iconText = action.getTextIcon().getValue(entity);
Button iconLabel = new Button(iconText);
if (btn.getIconStyleComponent() != btn) {
iconLabel.setUIID(btn.getIconStyleComponent().getUIID());
} else {
iconLabel.setUIID(btn.getUIID());
// IF the button has a border and padding set, we don't
// want to to also be applied to the icon.
iconLabel.getAllStyles().stripMarginAndPadding();
}
iconLabel.setWidth(iconLabel.getPreferredW());
iconLabel.setHeight(iconLabel.getPreferredH());
btn.setIcon(new ComponentImage(iconLabel, iconLabel.getWidth(), iconLabel.getHeight()));
}
if (includeIcon && text) {
ActionStyle style = action.getActionStyle();
if (style != null) {
switch(style) {
case IconTop:
button.setTextPosition(BOTTOM);
break;
case IconBottom:
button.setTextPosition(TOP);
break;
case IconLeft:
button.setTextPosition(RIGHT);
break;
case IconRight:
button.setTextPosition(LEFT);
}
}
}
button.addActionListener(evt -> {
action.fireEvent(entity, button);
update(button, entity, action);
});
update(button, entity, action);
action.decorateComponent(btn);
}
use of com.codename1.components.Switch in project CodeRAD by shannah.
the class DefaultActionViewFactory method initUI.
public static void initUI(MultiButton btn, Entity entity, ActionNode action) {
btn.setBlockLead(true);
boolean text = action.isTextStyle();
boolean includeIcon = action.isIconStyle();
UIID uiid = action.getUIID();
if (uiid != null) {
btn.setUIID(uiid.getValue(entity));
}
IconUIID iconUiid = action.getIconUIID();
if (iconUiid != null) {
btn.setIconUIID(iconUiid.getValue());
}
MultiButton button = btn;
if (action.getLabel() != null && text) {
button.setTextLines(action.getLabel().getValue(entity.getEntity()));
}
if (action.getImageIcon() != null && includeIcon) {
button.setIcon(action.getImageIcon().getValue());
if (action.getSelected() != action && action.getSelected().getImageIcon() != action.getImageIcon()) {
button.setRolloverIcon(action.getSelected().getImageIcon().getValue());
}
if (action.getPressed() != action && action.getPressed().getImageIcon() != action.getImageIcon()) {
button.setPressedIcon(action.getPressed().getImageIcon().getValue());
}
if (action.getDisabled() != action && action.getDisabled().getImageIcon() != action.getImageIcon()) {
button.setDisabledIcon(action.getDisabled().getImageIcon().getValue());
}
}
if (action.getMaterialIcon() != null && includeIcon) {
char unselectedIcon = action.getMaterialIcon().getValue();
char selectedIcon = action.getSelected().getMaterialIcon().getValue();
char pressedIcon = action.getPressed().getMaterialIcon().getValue();
char selectedPressed = pressedIcon;
if (action.getPressed() == action) {
selectedPressed = selectedIcon;
}
char disabledIcon = action.getDisabled().getMaterialIcon().getValue();
// button.setMaterialIcon(action.getMaterialIcon().getValue());
FontImage.setMaterialIcon(btn, new char[] { unselectedIcon, selectedIcon, pressedIcon, selectedPressed, disabledIcon }, -1);
}
if (action.getTextIcon() != null && includeIcon) {
String iconText = action.getTextIcon().getValue(entity);
Button iconLabel = new Button(iconText);
if (btn.getIconStyleComponent() != btn) {
iconLabel.setUIID(btn.getIconStyleComponent().getUIID());
} else {
iconLabel.setUIID(btn.getUIID());
// IF the button has a border and padding set, we don't
// want to to also be applied to the icon.
iconLabel.getAllStyles().stripMarginAndPadding();
}
iconLabel.setWidth(iconLabel.getPreferredW());
iconLabel.setHeight(iconLabel.getPreferredH());
btn.setIcon(new ComponentImage(iconLabel, iconLabel.getWidth(), iconLabel.getHeight()));
}
if (includeIcon && text) {
ActionStyle style = action.getActionStyle();
if (style != null) {
switch(style) {
case IconTop:
button.setTextPosition(BOTTOM);
break;
case IconBottom:
button.setTextPosition(TOP);
break;
case IconLeft:
button.setTextPosition(RIGHT);
break;
case IconRight:
button.setTextPosition(LEFT);
}
}
}
if (!text) {
button.setText("");
}
button.addActionListener(evt -> {
action.fireEvent(entity, button);
update(button, entity, action);
});
update(button, entity, action);
action.decorateComponent(btn);
}
use of com.codename1.components.Switch in project CodeRAD by shannah.
the class ButtonListPropertyView method decorateButtonList.
private static ButtonList decorateButtonList(FieldNode field, ButtonList bl) {
ButtonListLayoutAttribute att = (ButtonListLayoutAttribute) field.findInheritedAttribute(ButtonListLayoutAttribute.class);
if (att != null) {
switch(att.getValue()) {
case Flow:
bl.setLayout(new FlowLayout());
break;
case Y:
bl.setLayout(BoxLayout.y());
break;
case X:
bl.setLayout(BoxLayout.x());
break;
case Grid:
Columns cols = (Columns) field.findAttribute(Columns.class);
int numCols = 2;
if (cols != null) {
numCols = cols.getValue();
}
bl.setLayout(new GridLayout(numCols));
break;
}
}
String uiid = field.getUIID(null);
if (uiid != null) {
bl.setUIID(uiid);
bl.setCellUIID(uiid + "Cell");
}
return bl;
}
Aggregations