Search in sources :

Example 6 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.

the class SSLCertificatePinningSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World");
    hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    CheckBox allowConnectionsCb = new CheckBox("Allow Connections");
    allowConnectionsCb.setSelected(true);
    allowConnectionsCb.addActionListener(e -> {
        allowConnections = allowConnectionsCb.isSelected();
    });
    hi.add(allowConnectionsCb);
    allowConnections = allowConnectionsCb.isSelected();
    $(hi).append($(new Button("Test Build Request Body")).addActionListener(e -> {
        ConnectionRequest req = new ConnectionRequest() {

            @Override
            protected void buildRequestBody(OutputStream os) throws IOException {
                PrintStream ps = new PrintStream(os);
                ps.print("Key1=Val1");
            }

            @Override
            protected void checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates) {
                /*
                            StringBuilder sb = new StringBuilder();
                            for (SSLCertificate cert : certificates) {
                                System.out.println("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey());
                                sb.append("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey()).append("\n");
                            }
                            
                            $(()->{
                                $("TextArea")
                                        .setText(sb.toString())
                                        .getComponentForm()
                                        .revalidate();
                                
                            });
                                    */
                if (!trust(certificates)) {
                    this.kill();
                }
            }

            @Override
            protected void handleException(Exception err) {
                err.printStackTrace();
            }

            @Override
            protected void handleErrorResponseCode(int code, String message) {
                // To change body of generated methods, choose Tools | Templates.
                super.handleErrorResponseCode(code, message);
            }
        };
        req.setCheckSSLCertificates(true);
        req.setUrl("https://weblite.ca/tmp/postecho.php");
        req.setPost(true);
        req.setHttpMethod("POST");
        req.addArgument("SomeKey", "SomeValue");
        // NetworkManager.getInstance().addErrorListener(ne-> {
        // ne.getError().printStackTrace();
        // });
        // NetworkManager.getInstance().
        NetworkManager.getInstance().addToQueueAndWait(req);
        if (req.getResponseCode() == 200) {
            try {
                String resp = new String(req.getResponseData(), "UTF-8");
                String expected = "Post received:\n" + "Array\n" + "(\n" + "    [Key1] => Val1\n" + ")";
                String passFail = resp.trim().equals(expected.trim()) ? "Test Passed." : "Test Failed";
                // String expected = ""
                // resp += "\nExpected: "
                $(".result", hi).setText(passFail + "\nReceived:\n---------\n" + resp + "\n-----------\nExpected:\n----------\n" + expected + "\n---------\n");
            } catch (Exception ex) {
                Log.e(ex);
            }
        } else {
            $(".result", hi).setText("Request failed: " + req.getResponseErrorMessage());
        }
    }).asComponent());
    $(hi).append($(new Button("Test Post")).addActionListener(e -> {
        ConnectionRequest req = new ConnectionRequest() {

            @Override
            protected void checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates) {
                /*
                            StringBuilder sb = new StringBuilder();
                            for (SSLCertificate cert : certificates) {
                                System.out.println("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey());
                                sb.append("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey()).append("\n");
                            }
                            
                            $(()->{
                                $("TextArea")
                                        .setText(sb.toString())
                                        .getComponentForm()
                                        .revalidate();
                                
                            });
                                    */
                if (!trust(certificates)) {
                    this.kill();
                }
            }

            @Override
            protected void handleException(Exception err) {
                err.printStackTrace();
            }

            @Override
            protected void handleErrorResponseCode(int code, String message) {
                // To change body of generated methods, choose Tools | Templates.
                super.handleErrorResponseCode(code, message);
            }
        };
        req.setCheckSSLCertificates(true);
        req.setUrl("https://weblite.ca/tmp/postecho.php");
        req.setPost(true);
        req.setHttpMethod("POST");
        req.addArgument("SomeKey", "SomeValue");
        // NetworkManager.getInstance().addErrorListener(ne-> {
        // ne.getError().printStackTrace();
        // });
        // NetworkManager.getInstance().
        NetworkManager.getInstance().addToQueueAndWait(req);
        if (req.getResponseCode() == 200) {
            try {
                String resp = new String(req.getResponseData(), "UTF-8");
                String expected = "Post received:\n" + "Array\n" + "(\n" + "    [SomeKey] => SomeValue\n" + ")";
                String passFail = resp.trim().equals(expected.trim()) ? "Test Passed." : "Test Failed";
                // String expected = ""
                // resp += "\nExpected: "
                $(".result", hi).setText(passFail + "\nReceived:\n---------\n" + resp + "\n-----------\nExpected:\n----------\n" + expected + "\n---------\n");
            } catch (Exception ex) {
                Log.e(ex);
            }
        } else {
            $(".result", hi).setText("Request failed: " + req.getResponseErrorMessage());
        }
    }).asComponent());
    $(hi).append($(new Button("Test SSL Certs")).addActionListener(e -> {
        ConnectionRequest req = new ConnectionRequest() {

            @Override
            protected void checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates) {
                /*
                            StringBuilder sb = new StringBuilder();
                            for (SSLCertificate cert : certificates) {
                                System.out.println("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey());
                                sb.append("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey()).append("\n");
                            }
                            
                            $(()->{
                                $("TextArea")
                                        .setText(sb.toString())
                                        .getComponentForm()
                                        .revalidate();
                                
                            });
                                    */
                if (!trust(certificates)) {
                    this.kill();
                }
            }

            @Override
            protected void handleException(Exception err) {
                err.printStackTrace();
            }

            @Override
            protected void handleErrorResponseCode(int code, String message) {
                // To change body of generated methods, choose Tools | Templates.
                super.handleErrorResponseCode(code, message);
            }
        };
        req.setCheckSSLCertificates(true);
        req.setUrl("https://confluence.atlassian.com/kb/unable-to-connect-to-ssl-services-due-to-pkix-path-building-failed-779355358.html");
        // NetworkManager.getInstance().addErrorListener(ne-> {
        // ne.getError().printStackTrace();
        // });
        // NetworkManager.getInstance().
        NetworkManager.getInstance().addToQueue(req);
    }).asComponent()).append($(new TextArea()).each(c -> {
        TextArea ta = (TextArea) c;
        ta.setRows(10);
    }).addTags("result").selectAllStyles().setFgColor(0x0).asComponent());
    hi.show();
}
Also used : OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) Toolbar(com.codename1.ui.Toolbar) BoxLayout(com.codename1.ui.layouts.BoxLayout) Resources(com.codename1.ui.util.Resources) NetworkManager(com.codename1.io.NetworkManager) IOException(java.io.IOException) Form(com.codename1.ui.Form) Log(com.codename1.io.Log) NetworkEvent(com.codename1.io.NetworkEvent) UIManager(com.codename1.ui.plaf.UIManager) ComponentSelector.$(com.codename1.ui.ComponentSelector.$) ConnectionRequest(com.codename1.io.ConnectionRequest) Dialog(com.codename1.ui.Dialog) Display(com.codename1.ui.Display) Label(com.codename1.ui.Label) Button(com.codename1.ui.Button) CN(com.codename1.ui.CN) TextArea(com.codename1.ui.TextArea) CheckBox(com.codename1.ui.CheckBox) PrintStream(java.io.PrintStream) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) BoxLayout(com.codename1.ui.layouts.BoxLayout) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ConnectionRequest(com.codename1.io.ConnectionRequest) Button(com.codename1.ui.Button) CheckBox(com.codename1.ui.CheckBox)

Example 7 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.

the class TabIteratorSample2775 method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new TextField("Text 1"));
    Picker p1 = new Picker();
    p1.setType(Display.PICKER_TYPE_STRINGS);
    p1.setStrings("Red", "Green", "Blue", "Orange");
    hi.add(p1);
    hi.add(new TextField("Text 2"));
    CheckBox enableTabsCheckBox = new CheckBox("Enable Tabbing");
    enableTabsCheckBox.setSelected(true);
    enableTabsCheckBox.addActionListener(e -> {
        $("*", hi).each(c -> {
            c.setPreferredTabIndex(enableTabsCheckBox.isSelected() ? 0 : -1);
        });
    });
    hi.add(enableTabsCheckBox);
    hi.show();
}
Also used : Form(com.codename1.ui.Form) CheckBox(com.codename1.ui.CheckBox) Picker(com.codename1.ui.spinner.Picker) TextField(com.codename1.ui.TextField)

Example 8 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.

the class DefaultCrashReporter method exception.

/**
 * {@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);
}
Also used : Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) TextArea(com.codename1.ui.TextArea) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) Dialog(com.codename1.ui.Dialog) CheckBox(com.codename1.ui.CheckBox) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 9 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project opencms-core by alkacon.

the class CmsCategoryTree method setCategories.

/**
 * Fills the category tree.<p>
 *
 * @param categories the categories
 */
public void setCategories(List<CmsCategory> categories) {
    for (int i = 0; i < categories.size(); i++) {
        CmsCategory cat = categories.get(i);
        m_container.addItem(cat);
        m_checkboxes.put(cat, new CheckBox());
        String parentPath = CmsResource.getParentFolder(cat.getPath());
        if (parentPath.length() > 1) {
            for (int j = i - 1; j >= 0; j--) {
                if (categories.get(j).getPath().equals(parentPath)) {
                    m_container.setParent(cat, categories.get(j));
                    break;
                }
            }
        }
    }
    // hide openers
    for (CmsCategory cat : categories) {
        if ((m_container.getChildren(cat) == null) || (m_container.getChildren(cat).size() == 0)) {
            m_container.setChildrenAllowed(cat, false);
        }
    }
}
Also used : CheckBox(com.vaadin.v7.ui.CheckBox) CmsCategory(org.opencms.relations.CmsCategory)

Example 10 with CheckBox

use of com.vaadin.v7.ui.CheckBox in project opencms-core by alkacon.

the class CmsDeleteSiteDialog method getContent.

/**
 * Creates content of dialog containing CheckBox if resources should be deleted and a messages.<p>
 *
 * @return vertical layout component.
 */
protected VerticalLayout getContent() {
    String message;
    if (m_sitesToDelete.size() == 1) {
        message = CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CONFIRM_DELETE_SITE_1, m_sitesToDelete.get(0).getTitle());
    } else {
        message = "";
        for (CmsSite site : m_sitesToDelete) {
            if (message.length() > 0) {
                message += ", ";
            }
            message += site.getTitle();
        }
        message = CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CONFIRM_DELETE_SITES_1, message);
    }
    VerticalLayout layout = new VerticalLayout();
    m_deleteResources = new CheckBox();
    m_deleteResources.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_DELETE_RESOURCES_0));
    m_deleteResources.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_DELETE_RESOURCES_HELP_0));
    layout.addComponent(m_deleteResources);
    Label label = new Label();
    label.setContentMode(ContentMode.HTML);
    label.setValue(message);
    layout.addComponent(label);
    return layout;
}
Also used : CheckBox(com.vaadin.v7.ui.CheckBox) Label(com.vaadin.v7.ui.Label) VerticalLayout(com.vaadin.v7.ui.VerticalLayout) CmsSite(org.opencms.site.CmsSite)

Aggregations

CheckBox (com.vaadin.v7.ui.CheckBox)40 CheckBox (com.codename1.ui.CheckBox)18 Label (com.vaadin.ui.Label)15 ComboBox (com.vaadin.v7.ui.ComboBox)14 Button (com.codename1.ui.Button)12 TextField (com.vaadin.v7.ui.TextField)12 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)12 Form (com.codename1.ui.Form)11 Disease (de.symeda.sormas.api.Disease)11 Captions (de.symeda.sormas.api.i18n.Captions)11 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)11 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)11 List (java.util.List)11 Container (com.codename1.ui.Container)10 FacadeProvider (de.symeda.sormas.api.FacadeProvider)10 Strings (de.symeda.sormas.api.i18n.Strings)10 Label (com.codename1.ui.Label)9 TextField (com.codename1.ui.TextField)9 HorizontalLayout (com.vaadin.ui.HorizontalLayout)9 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)9