use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.
the class GenericListCellRenderer method setComponentValue.
/**
* Initializes the given component with the given value
*
* @param cmp one of the components that is or is a part of the renderer
* @param value the value to install into the component
*/
private void setComponentValue(Component cmp, Object value, Component parent, Component rootRenderer) {
// process so renderer selected/unselected styles are applied
if (cmp.getName().toLowerCase().endsWith("fixed")) {
return;
}
if (cmp instanceof Label) {
if (value instanceof Image) {
Image i = (Image) value;
if (i.isAnimation()) {
if (pendingAnimations == null) {
pendingAnimations = new ArrayList<Image>();
}
if (!pendingAnimations.contains(i)) {
pendingAnimations.add(i);
if (parentList == null) {
parentList = parent;
}
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
} else {
waitingForRegisterAnimation = true;
}
}
} else {
if (waitingForRegisterAnimation) {
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
}
}
}
}
}
Image oldImage = ((Label) cmp).getIcon();
((Label) cmp).setIcon(i);
((Label) cmp).setText("");
if (oldImage == null || oldImage.getWidth() != i.getWidth() || oldImage.getHeight() != i.getHeight()) {
((Container) rootRenderer).revalidate();
}
return;
} else {
((Label) cmp).setIcon(null);
}
if (cmp instanceof CheckBox) {
((CheckBox) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof RadioButton) {
((RadioButton) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof Slider) {
((Slider) cmp).setProgress(((Integer) value).intValue());
return;
}
Label l = (Label) cmp;
if (value == null) {
l.setText("");
} else {
if (value instanceof Label) {
l.setText(((Label) value).getText());
l.setIcon(((Label) value).getIcon());
} else {
l.setText(value.toString());
}
}
if (firstCharacterRTL) {
String t = l.getText();
if (t.length() > 0) {
l.setRTL(Display.getInstance().isRTL(t.charAt(0)));
}
}
return;
}
if (cmp instanceof TextArea) {
if (value == null) {
((TextArea) cmp).setText("");
} else {
((TextArea) cmp).setText(value.toString());
}
}
}
use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.
the class GenericListCellRenderer method findComponentsOfInterest.
private void findComponentsOfInterest(Component cmp, ArrayList dest) {
if (cmp instanceof Container) {
Container c = (Container) cmp;
int count = c.getComponentCount();
for (int iter = 0; iter < count; iter++) {
findComponentsOfInterest(c.getComponentAt(iter), dest);
}
return;
}
// performance optimization for fixed images in lists
if (cmp.getName() != null) {
if (cmp instanceof Label) {
Label l = (Label) cmp;
if (l.getName().toLowerCase().endsWith("fixed") && l.getIcon() != null) {
l.getIcon().lock();
}
dest.add(cmp);
return;
}
if (cmp instanceof TextArea) {
dest.add(cmp);
return;
}
}
}
use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.
the class MigLayout method checkCache.
/**
* Check if something has changed and if so recreate it to the cached
* objects.
*
* @param parent The parent that is the target for this layout manager.
*/
private void checkCache(Container parent) {
if (parent == null) {
return;
}
if (dirty) {
grid = null;
}
cleanConstraintMaps(parent);
// Check if the grid is valid
int mc = PlatformDefaults.getModCount();
if (lastModCount != mc) {
grid = null;
lastModCount = mc;
}
// if (!parent.isValid()) {
if (!lastWasInvalid) {
lastWasInvalid = true;
int hash = 0;
// Added in 3.7.3 to resolve a timing regression introduced in 3.7.1
boolean resetLastInvalidOnParent = false;
for (ComponentWrapper wrapper : ccMap.keySet()) {
Object component = wrapper.getComponent();
if (component instanceof TextArea) {
resetLastInvalidOnParent = true;
}
hash ^= wrapper.getLayoutHashCode();
hash += 285134905;
}
if (resetLastInvalidOnParent) {
resetLastInvalidOnParent(parent);
}
if (hash != lastHash) {
grid = null;
lastHash = hash;
}
Dimension ps = new Dimension(parent.getWidth(), parent.getHeight());
if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) {
grid = null;
lastInvalidSize = ps;
}
}
/*} else {
lastWasInvalid = false;
}*/
ContainerWrapper par = checkParent(parent);
setDebug(par, getDebugMillis() > 0);
if (grid == null) {
grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList);
}
dirty = false;
}
use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.
the class SQLExplorerSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Toolbar.setGlobalToolbar(true);
Style s = UIManager.getInstance().getComponentStyle("TitleCommand");
FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_QUERY_BUILDER, s);
Form hi = new Form("SQL Explorer", new BorderLayout());
hi.getToolbar().addCommandToRightBar("", icon, (e) -> {
TextArea query = new TextArea(3, 80);
Command ok = new Command("Execute");
Command cancel = new Command("Cancel");
if (Dialog.show("Query", query, ok, cancel) == ok) {
Database db = null;
Cursor cur = null;
try {
db = Display.getInstance().openOrCreate("MyDB.db");
if (query.getText().startsWith("select")) {
cur = db.executeQuery(query.getText());
int columns = cur.getColumnCount();
hi.removeAll();
if (columns > 0) {
boolean next = cur.next();
if (next) {
ArrayList<String[]> data = new ArrayList<>();
String[] columnNames = new String[columns];
for (int iter = 0; iter < columns; iter++) {
columnNames[iter] = cur.getColumnName(iter);
}
while (next) {
Row currentRow = cur.getRow();
String[] currentRowArray = new String[columns];
for (int iter = 0; iter < columns; iter++) {
currentRowArray[iter] = currentRow.getString(iter);
}
data.add(currentRowArray);
next = cur.next();
}
Object[][] arr = new Object[data.size()][];
data.toArray(arr);
hi.add(BorderLayout.CENTER, new Table(new DefaultTableModel(columnNames, arr)));
} else {
hi.add(BorderLayout.CENTER, "Query returned no results");
}
} else {
hi.add(BorderLayout.CENTER, "Query returned no results");
}
} else {
db.execute(query.getText());
hi.add(BorderLayout.CENTER, "Query completed successfully");
}
hi.revalidate();
} catch (IOException err) {
Log.e(err);
hi.removeAll();
hi.add(BorderLayout.CENTER, "Error: " + err);
hi.revalidate();
} finally {
Util.cleanup(db);
Util.cleanup(cur);
}
}
});
hi.show();
}
use of com.vaadin.v7.ui.TextArea 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();
}
Aggregations