Search in sources :

Example 96 with Switch

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;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Button(com.codename1.ui.Button) ActionEvent(com.codename1.ui.events.ActionEvent) TextField(com.codename1.ui.TextField) SpanLabel(com.codename1.components.SpanLabel) Sheet(com.codename1.ui.Sheet)

Example 97 with Switch

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);
                    }
                };
            }
    }
}
Also used : com.codename1.ui(com.codename1.ui) ActionSupport(com.codename1.rad.controllers.ActionSupport) Condition(com.codename1.rad.attributes.Condition) Name(com.codename1.rad.models.Property.Name) EntityImageRenderer(com.codename1.rad.ui.image.EntityImageRenderer) ActionEvent(com.codename1.ui.events.ActionEvent) EventContext(com.codename1.rad.events.EventContext) com.codename1.rad.models(com.codename1.rad.models) Map(java.util.Map) MaterialIcon(com.codename1.rad.attributes.MaterialIcon) TextIcon(com.codename1.rad.attributes.TextIcon) Description(com.codename1.rad.models.Property.Description) ActionListener(com.codename1.ui.events.ActionListener) ControllerEvent(com.codename1.rad.controllers.ControllerEvent) com.codename1.rad.ui(com.codename1.rad.ui) ImageIcon(com.codename1.rad.attributes.ImageIcon) Objects(java.util.Objects) ActionStyleAttribute(com.codename1.rad.attributes.ActionStyleAttribute) SelectedCondition(com.codename1.rad.attributes.SelectedCondition) PropertyImageRenderer(com.codename1.rad.ui.image.PropertyImageRenderer) Label(com.codename1.rad.models.Property.Label) Controller(com.codename1.rad.controllers.Controller) SuccessCallback(com.codename1.util.SuccessCallback) BadgeUIID(com.codename1.rad.attributes.BadgeUIID) EventDispatcher(com.codename1.ui.util.EventDispatcher) Badge(com.codename1.rad.attributes.Badge) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 98 with Switch

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);
}
Also used : ComponentImage(ca.weblite.shared.components.ComponentImage) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) IconUIID(com.codename1.rad.attributes.IconUIID) IconUIID(com.codename1.rad.attributes.IconUIID) BadgeUIID(com.codename1.rad.attributes.BadgeUIID) UIID(com.codename1.rad.attributes.UIID)

Example 99 with Switch

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);
}
Also used : ComponentImage(ca.weblite.shared.components.ComponentImage) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) IconUIID(com.codename1.rad.attributes.IconUIID) IconUIID(com.codename1.rad.attributes.IconUIID) BadgeUIID(com.codename1.rad.attributes.BadgeUIID) UIID(com.codename1.rad.attributes.UIID) MultiButton(com.codename1.components.MultiButton)

Example 100 with Switch

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;
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) Columns(com.codename1.rad.attributes.Columns)

Aggregations

Component (com.codename1.ui.Component)19 Font (com.codename1.ui.Font)18 Container (com.codename1.ui.Container)15 Form (com.codename1.ui.Form)14 Style (com.codename1.ui.plaf.Style)12 Button (com.codename1.ui.Button)11 Image (com.codename1.ui.Image)11 TextArea (com.codename1.ui.TextArea)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 IOException (java.io.IOException)10 Hashtable (java.util.Hashtable)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)9 Label (com.codename1.ui.Label)8 FileInputStream (java.io.FileInputStream)8 ActionListener (com.codename1.ui.events.ActionListener)7 TextField (com.codename1.ui.TextField)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 EncodedImage (com.codename1.ui.EncodedImage)5