Search in sources :

Example 16 with TextArea

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());
        }
    }
}
Also used : Container(com.codename1.ui.Container) Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) CheckBox(com.codename1.ui.CheckBox) Label(com.codename1.ui.Label) RadioButton(com.codename1.ui.RadioButton) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) URLImage(com.codename1.ui.URLImage)

Example 17 with TextArea

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;
        }
    }
}
Also used : Container(com.codename1.ui.Container) TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label)

Example 18 with TextArea

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;
}
Also used : TextArea(com.codename1.ui.TextArea) Grid(com.codename1.ui.layouts.mig.Grid) Dimension(com.codename1.ui.geom.Dimension) ContainerWrapper(com.codename1.ui.layouts.mig.ContainerWrapper) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Example 19 with TextArea

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();
}
Also used : Table(com.codename1.ui.table.Table) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) DefaultTableModel(com.codename1.ui.table.DefaultTableModel) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Cursor(com.codename1.db.Cursor) BorderLayout(com.codename1.ui.layouts.BorderLayout) Command(com.codename1.ui.Command) Database(com.codename1.db.Database) Style(com.codename1.ui.plaf.Style) Row(com.codename1.db.Row) FontImage(com.codename1.ui.FontImage)

Example 20 with TextArea

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

Aggregations

TextArea (com.codename1.ui.TextArea)60 Form (com.codename1.ui.Form)23 Component (com.codename1.ui.Component)21 Button (com.codename1.ui.Button)16 Label (com.codename1.ui.Label)16 TextArea (com.vaadin.v7.ui.TextArea)15 Container (com.codename1.ui.Container)13 BorderLayout (com.codename1.ui.layouts.BorderLayout)12 Label (com.vaadin.ui.Label)11 ComboBox (com.vaadin.v7.ui.ComboBox)10 TextField (com.codename1.ui.TextField)9 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)9 DateField (com.vaadin.v7.ui.DateField)8 TextField (com.vaadin.v7.ui.TextField)8 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)7 RadioButton (com.codename1.ui.RadioButton)6 Field (com.vaadin.v7.ui.Field)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 Paint (android.graphics.Paint)4 CheckBox (com.codename1.ui.CheckBox)4