Search in sources :

Example 16 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class SignatureComponent method setSignatureImage.

/**
 * Sets the signature image for this field.  This will also scale the image and
 * show it as the icon for the button.
 * @param img The image to set as the signature image.
 */
public void setSignatureImage(Image img) {
    if (img != signatureImage) {
        signatureImage = img;
        lead.setText("");
        if (img != null) {
            int maxW = lead.getWidth() - lead.getStyle().getPaddingLeftNoRTL() - lead.getStyle().getPaddingRightNoRTL();
            int maxH = lead.getHeight() - lead.getStyle().getPaddingTop() - lead.getStyle().getPaddingBottom();
            Image icon = img;
            if (icon.getWidth() > maxW || icon.getHeight() > maxH) {
                icon = icon.scaledSmallerRatio(maxW, maxH);
            }
            lead.setIcon(icon);
        } else {
            lead.setText(localize("SignatureComponent.LeadText", "Press to sign"));
            lead.setIcon(null);
        }
    }
}
Also used : Image(com.codename1.ui.Image)

Example 17 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class TestRecorder method eventPointerReleased.

void eventPointerReleased(int x, int y) {
    if (isRecording()) {
        com.codename1.ui.Component cmp = Display.getInstance().getCurrent().getComponentAt(x, y);
        if (isListComponent(cmp)) {
            return;
        }
        if (dragged) {
            if (dragToScroll.isSelected()) {
                com.codename1.ui.Component scrollTo;
                if (y > pointerPressedY) {
                    scrollTo = findLowestVisibleComponent();
                } else {
                    scrollTo = findHighestVisibleComponent();
                }
                if (scrollTo != null && scrollTo != Display.getInstance().getCurrent() && scrollTo != Display.getInstance().getCurrent().getContentPane()) {
                    String name = scrollTo.getName();
                    if (name != null) {
                        generatedCode += "        ensureVisible(\"" + name + "\");\n";
                    } else {
                        String pp = getPathToComponent(scrollTo);
                        if (pp == null) {
                            return;
                        }
                        generatedCode += "        ensureVisible(" + pp + ");\n";
                    }
                    updateTestCode();
                }
            } else {
                addWaitStatement();
                generatedCode += "        pointerRelease" + generatePointerEventArguments(x, y);
                updateTestCode();
            }
        } else {
            if (isToolbarComponent(cmp)) {
                if (cmp instanceof com.codename1.ui.Button) {
                    Command cmd = ((com.codename1.ui.Button) cmp).getCommand();
                    if (cmd != null) {
                        int offset = 0;
                        Command[] commands = TestUtils.getToolbarCommands();
                        for (Command c : commands) {
                            if (c == cmd) {
                                generatedCode += "        assertEqual(getToolbarCommands().length, " + commands.length + ");\n";
                                generatedCode += "        executeToolbarCommandAtOffset(" + offset + ");\n";
                                updateTestCode();
                                return;
                            }
                            offset++;
                        }
                    } else {
                        if (cmp.getUIID().equals("MenuButton")) {
                            // side menu button
                            generatedCode += "        showSidemenu();\n";
                            updateTestCode();
                            return;
                        }
                    }
                }
            }
            if (cmp instanceof com.codename1.ui.Button) {
                com.codename1.ui.Button btn = (com.codename1.ui.Button) cmp;
                // special case for back command on iOS
                if (btn.getCommand() != null && btn.getCommand() == Display.getInstance().getCurrent().getBackCommand()) {
                    generatedCode += "        goBack();\n";
                } else {
                    if (btn.getName() != null && btn.getName().length() > 0) {
                        generatedCode += "        clickButtonByName(\"" + btn.getName() + "\");\n";
                    } else {
                        if (btn.getText() != null && btn.getText().length() > 0) {
                            generatedCode += "        clickButtonByLabel(\"" + btn.getText() + "\");\n";
                        } else {
                            String pp = getPathToComponent(cmp);
                            if (pp == null || pp.equals("(String)null")) {
                                return;
                            }
                            generatedCode += "        clickButtonByPath(" + pp + ");\n";
                        }
                    }
                }
                updateTestCode();
                return;
            }
            if (cmp instanceof com.codename1.ui.TextArea) {
                // ignore this, its probably initiating edit which we will capture soon
                return;
            }
            generatedCode += "        pointerPress" + generatePointerEventArguments(pointerPressedX, pointerPressedY);
            addWaitStatement();
            generatedCode += "        pointerRelease" + generatePointerEventArguments(x, y);
            updateTestCode();
        }
    }
}
Also used : Command(com.codename1.ui.Command) Component(com.codename1.ui.Component)

Example 18 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class BarCodeScanner method startScaning.

private void startScaning(ScanResult callback) {
    this.callback = callback;
    try {
        // Add the listener for scan and cancel
        Container cmdContainer = new Container(new FlowLayout(Component.CENTER));
        Button scanButton = new Button(new Command("Scan") {

            public void actionPerformed(ActionEvent evt) {
                cameraForm.repaint();
                if (snapshotThread != null) {
                    snapshotThread.continueRun();
                }
            }
        });
        Button cancelButton = new Button(new Command("Cancel") {

            public void actionPerformed(ActionEvent evt) {
                if (snapshotThread != null) {
                    snapshotThread.stop();
                    cancelScan();
                }
            }
        });
        cmdContainer.addComponent(scanButton);
        cmdContainer.addComponent(cancelButton);
        cameraForm = new Form();
        cameraForm.setScrollable(false);
        cameraForm.setLayout(new BorderLayout());
        cameraForm.addComponent(BorderLayout.CENTER, media.getVideoComponent());
        cameraForm.addComponent(BorderLayout.SOUTH, cmdContainer);
    } catch (Exception e) {
        // throw new AppException("Image/video capture not supported on this phone", e).setCode(97);
        e.printStackTrace();
    }
    startScan();
}
Also used : Container(com.codename1.ui.Container) FlowLayout(com.codename1.ui.layouts.FlowLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) Command(com.codename1.ui.Command) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 19 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class ComponentSelector method setIcon.

/**
 * Sets the icon of all elements in this set to a material icon.  This will use
 * the foreground color of each label as the icon's foreground color.
 * @param materialIcon The icon charcode.
 * @param size The size of the icon (in mm)
 * @return Self for chaining
 * @see FontImage#createMaterial(char, com.codename1.ui.plaf.Style, float)
 */
public ComponentSelector setIcon(char materialIcon, float size) {
    for (Component c : this) {
        if (c instanceof Label) {
            Label l = (Label) c;
            Style style = new Style();
            Style cStyle = c.getUnselectedStyle();
            style.setBgTransparency(0);
            style.setFgColor(cStyle.getFgColor());
            l.setIcon(FontImage.createMaterial(materialIcon, style, size));
            if (c instanceof Button) {
                Button b = (Button) c;
                style = new Style();
                cStyle = c.getPressedStyle();
                style.setBgTransparency(0);
                style.setFgColor(cStyle.getFgColor());
                b.setPressedIcon(FontImage.createMaterial(materialIcon, style, size));
            }
        }
    }
    return this;
}
Also used : SpanButton(com.codename1.components.SpanButton) SpanLabel(com.codename1.components.SpanLabel) Style(com.codename1.ui.plaf.Style)

Example 20 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class Dialog method placeButtonCommands.

/**
 * Places the given commands in the dialog command area, this is very useful for touch devices.
 *
 * @param cmds the commands to place
 * @deprecated this method shouldn't be invoked externally, it should have been private
 */
public void placeButtonCommands(Command[] cmds) {
    buttonCommands = cmds;
    Container buttonArea;
    if (getUIManager().isThemeConstant("dlgCommandGridBool", false)) {
        buttonArea = new Container(new GridLayout(1, cmds.length));
    } else {
        buttonArea = new Container(new FlowLayout(CENTER));
    }
    buttonArea.setUIID("DialogCommandArea");
    String uiid = getUIManager().getThemeConstant("dlgButtonCommandUIID", null);
    addButtonBar(buttonArea);
    if (cmds.length > 0) {
        String lineColor = getUIManager().getThemeConstant("dlgInvisibleButtons", null);
        if (cmds.length > 3) {
            lineColor = null;
        }
        int largest = Integer.parseInt(getUIManager().getThemeConstant("dlgCommandButtonSizeInt", "0"));
        for (int iter = 0; iter < cmds.length; iter++) {
            Button b = new Button(cmds[iter]);
            if (uiid != null) {
                b.setUIID(uiid);
            }
            // special case for dialog butons uppercase on Android
            if (Button.isCapsTextDefault()) {
                b.setCapsText(true);
            }
            largest = Math.max(b.getPreferredW(), largest);
            if (lineColor != null && lineColor.length() > 0) {
                int color = Integer.parseInt(lineColor, 16);
                Border brd = null;
                if (iter < cmds.length - 1) {
                    brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, Border.createLineBorder(1, color));
                } else {
                    brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, null);
                }
                b.getUnselectedStyle().setBorder(brd);
                b.getSelectedStyle().setBorder(brd);
                b.getPressedStyle().setBorder(brd);
            }
            buttonArea.addComponent(b);
        }
        for (int iter = 0; iter < cmds.length; iter++) {
            buttonArea.getComponentAt(iter).setPreferredW(largest);
        }
        buttonArea.getComponentAt(0).requestFocus();
    }
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) Border(com.codename1.ui.plaf.Border)

Aggregations

Button (com.codename1.ui.Button)31 BorderLayout (com.codename1.ui.layouts.BorderLayout)25 ActionEvent (com.codename1.ui.events.ActionEvent)21 Container (com.codename1.ui.Container)18 ActionListener (com.codename1.ui.events.ActionListener)17 Component (com.codename1.ui.Component)14 RadioButton (com.codename1.ui.RadioButton)14 Form (com.codename1.ui.Form)12 Label (com.codename1.ui.Label)11 BoxLayout (com.codename1.ui.layouts.BoxLayout)11 TextArea (com.codename1.ui.TextArea)10 Hashtable (java.util.Hashtable)9 Command (com.codename1.ui.Command)8 Image (com.codename1.ui.Image)8 TextField (com.codename1.ui.TextField)8 FlowLayout (com.codename1.ui.layouts.FlowLayout)8 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)8 CheckBox (com.codename1.ui.CheckBox)7 Style (com.codename1.ui.plaf.Style)7