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();
}
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();
}
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);
}
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);
}
}
}
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;
}
Aggregations