com.codename1.ui.Button Java Examples

The following examples show how to use com.codename1.ui.Button. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestNatives.java    From CodenameOne with GNU General Public License v2.0 7 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi World"));
    Button test = new Button("Test");
    test.addActionListener(e->{
        MyNativeInterface ni = NativeLookup.create(MyNativeInterface.class);
        System.out.println(Arrays.toString(ni.getBytes()));
        System.out.println(Arrays.toString(ni.getInts()));
        System.out.println(Arrays.toString(ni.getDouble()));
        ni.setBytes(new byte[]{3,2,1});
        ni.setInts(new int[]{6,5,4});
        ni.setDoubles(new double[]{9, 8, 7});
    });
    hi.add(test);
    hi.show();
}
 
Example #2
Source File: PasswordManagerTestCase2741.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form f = new Form("Form 1", BoxLayout.y());
    TextField tf1 = new TextField();
    tf1.setConstraint(TextField.PASSWORD);
    f.add(tf1);
    Button b = new Button("Login");
    b.addActionListener(e->{
        Form f2 = new Form("F2", BoxLayout.y());
        TextField t2 = new TextField();
        ComboBox cb = new ComboBox("Red", "Green", "Blue");
        f2.addAll(t2, cb);
        Button b2 = new Button("Submit");
        f2.add(b2);
        f2.show();
        
    });
    f.add(b);
    f.show();
}
 
Example #3
Source File: AddComponentToRightBarSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    Toolbar toolbar = hi.getToolbar();
    Command cmd = toolbar.addCommandToRightBar("Test", null, evt->{
        System.out.println("Hello");
    });
    
    Component cmp = toolbar.findCommandComponent(cmd);
    cmp.getParent().replace(cmp, new Button("Replaced cmp"), null);
    System.out.println("Command component: "+cmp);
    
    
    hi.add(new Label("Hi World"));
    hi.show();
}
 
Example #4
Source File: PhotoShare.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
Container createToolbar(long imageId) {
    Container toolbar = new Container(new GridLayout(1, 4));
    toolbar.setUIID("Toolbar");
    // notice that the characters in the name of the buttons map to icons in the icon font!
    Button likeButton = new Button("d");
    Button flagButton = new Button("c");
    Button detailsButton = new Button("a");
    final ShareButton shareButton = new ShareButton();
    shareButton.setIcon(null);
    shareButton.setText("b");

    bindShareButtonSelectionListener(shareButton);

    likeButton.setUIID("ToolbarLabel");
    flagButton.setUIID("ToolbarLabel");
    detailsButton.setUIID("ToolbarLabel");
    shareButton.setUIID("ToolbarLabel");
    toolbar.addComponent(likeButton);
    toolbar.addComponent(shareButton);
    toolbar.addComponent(detailsButton);
    toolbar.addComponent(flagButton);

    likeButton.addActionListener(createLikeAction(imageId));
    detailsButton.addActionListener(createDetailsButtonActionListener(imageId));
    return toolbar;
}
 
Example #5
Source File: PhotoShare.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
private void refreshGrid(final Container grid) {
    WebServiceProxy.listPhotosAsync(new Callback<long[]>() {
        public void onSucess(long[] value) {
            grid.removeAll();
            imageList = new ImageList(value);
            for(int iter = 0 ; iter < value.length ; iter++) {
                long p = value[iter];
                final Button btn = createImageButton(p, grid, iter);
                grid.addComponent(btn);
            }
            if(!animating) {
                animating = true;
                grid.animateLayoutAndWait(400);
                animating = false;
            }
        }

        public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
            if(Dialog.show("Error", "There was an error fetching the images", "Retry", "Exit")) {
                showMainForm();
            } else {
                Display.getInstance().exitApplication();
            }
        }
    });
}
 
Example #6
Source File: Validator.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the value of the given component, this can be overriden to add support for custom built components
 * 
 * @param cmp the component
 * @return  the object value
 */
protected Object getComponentValue(Component cmp) {
    if(cmp instanceof InputComponent) {
        cmp = ((InputComponent)cmp).getEditor();
    }
    if(cmp instanceof TextArea) {
        return ((TextArea)cmp).getText();
    }
    if(cmp instanceof Picker) {
        return ((Picker)cmp).getValue();
    }
    if(cmp instanceof RadioButton || cmp instanceof CheckBox) {
        if(((Button)cmp).isSelected()) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
    if(cmp instanceof Label) {
        return ((Label)cmp).getText();
    }
    if(cmp instanceof List) {
        return ((List)cmp).getSelectedItem();
    }
    return null;
}
 
Example #7
Source File: Tree.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a node within the tree, this method is protected allowing tree to be
 * subclassed to replace the rendering logic of individual tree buttons.
 *
 * @param node the node object from the model to display on the button
 * @param depth the depth within the tree (normally represented by indenting the entry)
 * @return a button representing the node within the tree
 * @deprecated replaced with createNode, bindNodeListener and setNodeIcon
 */
protected Button createNodeComponent(Object node, int depth) {
    Button cmp = new Button(childToDisplayLabel(node));
    cmp.setUIID("TreeNode");
    if(model.isLeaf(node)) {
        if(nodeImage == null) {
            FontImage.setMaterialIcon(cmp, FontImage.MATERIAL_DESCRIPTION, 3);
        } else {
            cmp.setIcon(nodeImage);
        }
    } else {
        if(folder == null) {
            FontImage.setMaterialIcon(cmp, FontImage.MATERIAL_FOLDER, 3);
        } else {
            cmp.setIcon(folder);
        }
    }
    updateNodeComponentStyle(cmp.getAllStyles(), depth);
    return cmp;
}
 
Example #8
Source File: IOS13RegressionTest.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public Form1() {
    Toolbar tb = new Toolbar();
    setToolbar(tb);
    tb.addCommandToLeftSideMenu("Form 2", null, ev->{
        new Form2().show();
    });
    
    setTitle("Form 1");
    TextField tf = new TextField();
    tf.setHint("Hint text");
    tf.getHintLabel().getAllStyles().setFgColor(0xff0000);
    add(tf);
    
    Button b = new Button("Test Button");
    b.addActionListener(evt->{
        ToastBar.showInfoMessage("Button worked");
    });
    add(b);
    TextField tf2 = new TextField();
    add(tf2);
    
}
 
Example #9
Source File: DefaultLookAndFeel.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Dimension getCheckBoxPreferredSize(Button cb) {
    if(cb.isToggle()) {
        return getButtonPreferredSize(cb);
    }
    threeImageCache[0] = cb.getMaskedIcon();
    threeImageCache[1] = cb.getRolloverIcon();
    threeImageCache[2] = cb.getPressedIcon();
    if (chkBoxImages != null) {
        return getPreferredSize(cb, threeImageCache, chkBoxImages[0]);
    }
    Dimension d = getPreferredSize(cb, threeImageCache, null);

    // checkbox square needs to be the height and width of the font height even
    // when no text is in the check box this is a good indication of phone DPI
    int checkBoxSquareSize = cb.getStyle().getFont().getHeight();

    // allow for checkboxes without a string within them
    d.setHeight(Math.max(checkBoxSquareSize, d.getHeight()));

    d.setWidth(d.getWidth() + checkBoxSquareSize + cb.getGap());
    return d;
}
 
Example #10
Source File: Progress.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the progress UI to the completion of this request
 *
 * @param title the title of the progress dialog
 * @param request the network request pending
 * @param showPercentage shows percentage on the progress bar
 */
public Progress(String title, ConnectionRequest request, boolean showPercentage) {
    super(title);
    this.request = request;
    SliderBridge b = new SliderBridge(request);
    b.setRenderPercentageOnTop(showPercentage);
    b.setRenderValueOnTop(true);
    setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    addComponent(b);
    Command cancel = new Command(UIManager.getInstance().localize("cancel", "Cancel"));
    if(Display.getInstance().isTouchScreenDevice() || getSoftButtonCount() < 2) {
        // if this is a touch screen device or a blackberry use a centered button
        Button btn = new Button(cancel);
        Container cnt = new Container(new FlowLayout(CENTER));
        cnt.addComponent(btn);
        addComponent(cnt);
    } else {
        // otherwise use a command
        addCommand(cancel);
    }
    setDisposeWhenPointerOutOfBounds(false);
    setAutoDispose(false);
    NetworkManager.getInstance().addProgressListener(this);
}
 
Example #11
Source File: Progress.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void actionCommand(Command cmd) {
    if(Display.getInstance().isTouchScreenDevice() || getSoftButtonCount() < 2) {
        for(int iter = 0 ; iter < getComponentCount() ; iter++) {
            Component c = getComponentAt(iter);
            if(c instanceof Button) {
                c.setEnabled(false);
            }
        }
    } else {
        removeAllCommands();
    }
    // cancel was pressed
    request.kill();
    dispose();
}
 
Example #12
Source File: ClearableTextField.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Wraps the given text field with a UI that will allow us to clear it
 * @param tf the text field
 * @param iconSize size in millimeters for the clear icon, -1 for default size
 * @return a Container that should be added to the UI instead of the actual text field
 */
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
    ClearableTextField cf = new ClearableTextField();
    Button b = new Button("", tf.getUIID());
    if(iconSize > 0) {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
    } else {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
    }
    removeCmpBackground(tf);
    removeCmpBackground(b);
    cf.setUIID(tf.getUIID());
    cf.add(BorderLayout.CENTER, tf);
    cf.add(BorderLayout.EAST, b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            tf.stopEditing();
            tf.setText("");
            tf.startEditingAsync();
        }
    });
    return cf;        
}
 
Example #13
Source File: TestRunnerComponent.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public TestRunnerComponent() {
    super(new BorderLayout());
    Button btn = new Button("Run Tests");
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            CN.callSerially(new Runnable() {
                public void run() {
                    runTests();
                }
            });
        }
    });
    add(CN.NORTH, btn);
    resultsPane.setScrollableY(true);
    add(CN.CENTER, resultsPane);
}
 
Example #14
Source File: ExecuteAndReturnStringTest.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", new BorderLayout());
    final BrowserComponent cmp = new BrowserComponent();
    cmp.setPage("<!doctype html><html><body>Hello World</body></html>", null);
    Button btn = new Button("Get User Agent");
    btn.addActionListener(evt->{
        ToastBar.showInfoMessage(cmp.executeAndReturnString("navigator.userAgent"));
    });
    hi.add(CENTER, cmp);
    hi.add(NORTH, btn);
    hi.show();
}
 
Example #15
Source File: CookiesTest.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Test Cookies", BoxLayout.y());
    Button runTests = new Button("Run Test");
    runTests.addActionListener(e->{
        callSerially(()->{
            runTest(BASE_URL);
            
            // We need to run the test also with explicit port number
            // because https://github.com/codenameone/CodenameOne/issues/2804
            runTest(BASE_URL_WITH_PORT);
            
        });
    });
    hi.add(runTests);
    hi.show();
}
 
Example #16
Source File: SheetSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", new BorderLayout());

    RadioButtonList sheetPos = new RadioButtonList(new DefaultListModel(
            BorderLayout.NORTH, BorderLayout.EAST, BorderLayout.SOUTH, BorderLayout.WEST, BorderLayout.CENTER
    ));
    Button b = new Button("Open Sheet");
    
    b.addActionListener(e->{
        MySheet sheet = new MySheet(null);
        int positionIndex = sheetPos.getModel().getSelectedIndex();
        if (positionIndex >= 0) {
            String pos = (String)sheetPos.getModel().getItemAt(positionIndex);
            sheet.setPosition(pos);
        }
        sheet.show();
        
        
    });
    hi.add(BorderLayout.NORTH, BoxLayout.encloseY(sheetPos, b));
    hi.show();
}
 
Example #17
Source File: SharedJavascriptContextSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", new BorderLayout());
    TextArea input = new TextArea();
    TextArea output = new TextArea();
    output.setEditable(false);
    
    Button execute = new Button("Run");
    execute.addActionListener(evt->{
        BrowserComponent bc = CN.getSharedJavascriptContext().ready().get();
        bc.execute("callback.onSuccess(window.eval(${0}))", new Object[]{input.getText()}, res->{
            output.setText(res.toString());
        });
    });
    SplitPane split = new SplitPane(SplitPane.VERTICAL_SPLIT, input, output, "0", "50%", "99%");
    hi.add(CENTER, split);
    hi.add(NORTH, execute);
    
    hi.show();
}
 
Example #18
Source File: WebSocketsSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
void showLogin() {
    Form f = new Form("Login");
    f.addComponent(new Label("Name: "));
    final TextField nameField = new TextField();
    f.addComponent(nameField);
    f.addComponent(new Button(new Command("Login"){ 

        @Override
        public void actionPerformed(ActionEvent evt) {
            System.out.println("Hello");
            if (sock.getReadyState() == WebSocketState.OPEN) {
                System.out.println("Open");
                sock.send(nameField.getText());
                showChat();
            } else {
                System.out.println("Closed");
                Dialog.show("Dialog", "The socket is not open: "+sock.getReadyState(), "OK", null);
                sock.reconnect();
            }
        }
           
    }));
    f.show();
}
 
Example #19
Source File: LeadComponentScrollingTest3079.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    
    int len = 100;
    for (int i=0; i<len; i++) {
        Container cnt = new Container(new FlowLayout());
        $(cnt).selectAllStyles().setBgTransparency(0xff).setBgColor(0xffffff);
        SwipeableContainer sc = new SwipeableContainer(BoxLayout.encloseX(new Button("This is a button")),BoxLayout.encloseX(new Button("This is another button")), cnt);
        Button b = new Button("Button "+i);
        b.addActionListener(evt->{
            System.out.println("button pressed");
        });
        cnt.add(b);
        cnt.setLeadComponent(b);
        hi.add(sc);
    }
    hi.setScrollableY(true);
    
    hi.add(new Label("Hi World"));
    hi.show();
}
 
Example #20
Source File: SpanButton.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor accepting default text
 */
public SpanButton(String txt) {
    setUIID("Button");
    setLayout(new BorderLayout());
    text = new TextArea(getUIManager().localize(txt, txt));
    text.setColumns(100);
    text.setUIID("Button");
    text.setGrowByContent(true);
    text.setEditable(false);
    text.setFocusable(false);
    text.setActAsLabel(true);
    setFocusable(true);
    removeBackground(text.getUnselectedStyle());
    removeBackground(text.getSelectedStyle());
    removeBackground(text.getPressedStyle());
    removeBackground(text.getDisabledStyle());
    actualButton = new Button();
    actualButton.setUIID("icon");
    addComponent(BorderLayout.WEST, actualButton);
    Container center = BoxLayout.encloseYCenter(text);
    center.getStyle().setMargin(0, 0, 0, 0);
    center.getStyle().setPadding(0, 0, 0, 0);
    addComponent(BorderLayout.CENTER, center);
    setLeadComponent(actualButton);
    updateGap();
}
 
Example #21
Source File: AudioRecorderComponentSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Audio Recorder Sample", BoxLayout.y());
    Button record = new Button("Record Audio");
    record.addActionListener(e->{
        recordAudio().onResult((res, err)->{
            if (err != null) {
                Log.e(err);
                ToastBar.showErrorMessage(err.getMessage());
                return;
            }
            if (res == null) {
                return;
            }
            try {
                MediaManager.createMedia(res, false).play();
            } catch (IOException ex) {
                Log.e(ex);
                ToastBar.showErrorMessage(ex.getMessage());
            }
        });
    });
    hi.add(record);
    hi.show();
}
 
Example #22
Source File: SpanLabelLayeredLayoutPreferredSizeTest3000.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void testBorderLayout() {
    Button showPopUp = new Button("Show PopUp in Border Layout");
    Form f = new Form(BoxLayout.y());
    f.setName("testBorderLayout");
    f.add(showPopUp);

    showPopUp.addActionListener((e) -> {

        SpanLabel messageSpanLabel = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos. Tap the following button to open the gallery. You should be able to select multiple images and videos.");
        messageSpanLabel.setName("messageSpanLabel");
        Container centerContainerOuter = new Container(new BorderLayout(CENTER_BEHAVIOR_CENTER));
        centerContainerOuter.add(CENTER, messageSpanLabel);

        Container layeredPane = getCurrentForm().getLayeredPane();
        layeredPane.setLayout(new LayeredLayout());        
        layeredPane.add(centerContainerOuter);
        layeredPane.setVisible(true);

        getCurrentForm().revalidate();     
    });
    showPopUp.setName("showBorderLayout");
    f.show();
    waitForFormName("testBorderLayout");
    clickButtonByName("showBorderLayout");
    SpanLabel spanLabel = (SpanLabel)findByName("messageSpanLabel");
    Label l = new Label("Tap the following");
    
    assertTrue(spanLabel.getHeight() > l.getPreferredH() * 2, "Span Label height is too small.  Should be at least a few lines.");
    
    
}
 
Example #23
Source File: TestIOSWebView3062.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
ButtonForm() {
    super("ButtonForm", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
    Form back = CN.getCurrentForm();
    getToolbar().addCommandToLeftBar("Back", null, evt->{
        back.showBack();
    });
    Button b = new Button("Back");
    b.addActionListener(evt->{
        back.showBack();
    });
    
    add(CENTER, b);
    
}
 
Example #24
Source File: CameraKitPickerTest7.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void showAnotherForm(){
    Form form = new Form(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));
    form.setScrollable(false);
    Container container = new Container(BoxLayout.y());
    container.add(new Label("Test", "heading5"));
    container.add(new Label("", "newLine"));
    container.add(new Label("", "newLine"));

    final Picker fromDate = new Picker();
    fromDate.setType(Display.PICKER_TYPE_DATE);
    container.add(new Label("From Date", "heading7"));
    container.add(fromDate);
    container.add(new Label("", "newLine"));

    final Picker toDate = new Picker();
    toDate.setType(Display.PICKER_TYPE_DATE);
    container.add(new Label("To Date", "heading7"));
    container.add(toDate);

    Button nextBtn = new Button("Proceed");
    nextBtn.setUIID("loginBtn");
    nextBtn.addActionListener((ev) -> {
        DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
        String fromDateStr = dateFormat.format(fromDate.getDate());
        String toDateStr = dateFormat.format(toDate.getDate());
        
    });
    container.add(new Label("", "newLine"));
    container.add(new Label("", "newLine"));
    container.add(nextBtn);
    form.add(BorderLayout.CENTER, container);
    
    form.show();
}
 
Example #25
Source File: TestComponent.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void testNestedScrollingLabels() {
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("Scrolling Labels");
    Toolbar tb = new Toolbar();
    f.setToolbar(tb);
    final Form backForm = Display.getInstance().getCurrent();
    tb.addCommandToSideMenu(new Command("Back") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (backForm != null) {
                backForm.showBack();
            }
        }
    });
    f.setTitle("Scrolling Labels");
    Container cnt = new Container(BoxLayout.y());
    cnt.setScrollableY(true);
    for (String l : new String[]{"Red", "Green", "Blue", "Orange", "Indigo"}) {
        for (int i=0; i<20; i++) {
            cnt.add(l+i);
        }
    }

    f.setLayout(new BorderLayout());
    f.add(BorderLayout.CENTER, LayeredLayout.encloseIn(new Button("Press me"), BorderLayout.center(BorderLayout.center(cnt))));
    f.show();

    TestUtils.waitForFormTitle("Scrolling Labels", 2000);
    Component res = f.getComponentAt(w/2, h/2);
    assertTrue(res == cnt || res.getParent() == cnt, "getComponentAt(x,y) should return scrollable container on top of button when in layered pane.");

}
 
Example #26
Source File: Mail.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
public Container createDemo() {
    Container message = new Container(new BoxLayout(BoxLayout.Y_AXIS));        
    ComponentGroup gp = new ComponentGroup();
    message.addComponent(gp);
    
    final TextField to = new TextField("");
    to.setHint("TO:");
    gp.addComponent(to);

    final TextField subject = new TextField("Codename One Is Cool");
    subject.setHint("Subject");
    gp.addComponent(subject);
    final TextField body = new TextField("Try it out at http://www.codenameone.com/");
    body.setSingleLineTextArea(false);
    body.setRows(4);
    body.setHint("Message Body");
    gp.addComponent(body);
    
    ComponentGroup buttonGroup = new ComponentGroup();
    Button btn = new Button("Send");
    buttonGroup.addComponent(btn);
    message.addComponent(buttonGroup);
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Message msg = new Message(body.getText());
            Display.getInstance().sendMessage(new String[] {to.getText()}, subject.getText(), msg);
        }
    });
            
    return message;
}
 
Example #27
Source File: DefaultCrashReporter.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void exception(Throwable t) {
    Preferences.set("$CN1_pendingCrash", true);
    if(promptUser) {
        Dialog error = new Dialog("Error");
        error.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        TextArea txt = new TextArea(errorText);
        txt.setEditable(false);
        txt.setUIID("DialogBody");
        error.addComponent(txt);
        CheckBox cb = new CheckBox(checkboxText);
        cb.setUIID("DialogBody");
        error.addComponent(cb);
        Container grid = new Container(new GridLayout(1, 2));
        error.addComponent(grid);
        Command ok = new Command(sendButtonText);
        Command dont = new Command(dontSendButtonText);
        Button send = new Button(ok);
        Button dontSend = new Button(dont);
        grid.addComponent(send);
        grid.addComponent(dontSend);
        Command result = error.showPacked(BorderLayout.CENTER, true);
        if(result == dont) {
            if(cb.isSelected()) {
                Preferences.set("$CN1_crashBlocked", true);
            }
            Preferences.set("$CN1_pendingCrash", false);
            return;
        } else {
            if(cb.isSelected()) {
                Preferences.set("$CN1_prompt", false);
            }
        }
    }
    Log.sendLog();
    Preferences.set("$CN1_pendingCrash", false);
}
 
Example #28
Source File: KitchenSink.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
private Button createDemo(Demo d) {
    Button btn = new Button(d.getDisplayName(), d.getDemoIcon());
    btn.setUIID("DemoButton");
    initDemoButtonMargin(btn.getUnselectedStyle());
    initDemoButtonMargin(btn.getSelectedStyle());
    initDemoButtonMargin(btn.getPressedStyle());
    initDemoButtonMargin(btn.getDisabledStyle());
    btn.setTextPosition(Button.TOP);
    return btn;
}
 
Example #29
Source File: TestComponent.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void getComponentAt_int_int_button() {
    log("Testing getComponentAt(x, y) with button");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();

    Form f = new Form("My Form", new BorderLayout());
    Label l = new Button("Hello");
    f.add(BorderLayout.CENTER, l);

    f.show();
    TestUtils.waitForFormTitle("My Form");
    Component middleComponent = f.getComponentAt(w/2, h/2);
    assertEqual(l, middleComponent, "Found wrong component");
}
 
Example #30
Source File: Contacts.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
public Container createDemo() {
    final Container contactsDemo = new Container(new BorderLayout());
    final Image defaultIcon = getResources().getImage("stock_new-meeting.png");
    
    ContactsModel m = new ContactsModel(Display.getInstance().getAllContacts(true));
    m.setPlaceHolderImage(defaultIcon);
    final List contactsList = new List(m);
    GridLayout grd = new GridLayout(3, 3);
    grd.setAutoFit(true);
    final ContainerList grid = new ContainerList(m);
    grid.setLayout(grd);
    contactsDemo.addComponent(BorderLayout.CENTER, contactsList);
    
    contactsList.setRenderer(createListRenderer());
    grid.setRenderer(createGridRenderer());
    
    final Button asGrid = new Button("As Grid");
    asGrid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            if(contactsList.getParent() != null) {
                contactsDemo.replace(contactsList, grid, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 300));
                asGrid.setText("As List");
            } else {
                contactsDemo.replace(grid, contactsList, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 300));
                asGrid.setText("As Grid");
            }
        }
    });
    
    ComponentGroup gp = new ComponentGroup();
    gp.addComponent(asGrid);
    contactsDemo.addComponent(BorderLayout.SOUTH, gp);
    return contactsDemo;
}