Search in sources :

Example 16 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class BlackBerryCanvas method paint.

public void paint(Graphics g) {
    int f = getFieldCount();
    if (f > 0) {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
        Form currentForm = Display.getInstance().getCurrent();
        for (int iter = 0; iter < f; iter++) {
            Field fld = getField(iter);
            int pops = 0;
            if (currentForm != null) {
                PeerComponent p = findPeer(currentForm.getContentPane(), fld);
                if (p != null) {
                    pops = clipOnLWUITBounds(p, g);
                } else {
                    Component cmp = currentForm.getFocused();
                    // we are now editing an edit field
                    if (cmp != null && cmp instanceof TextArea && cmp.hasFocus() && fld instanceof EditField) {
                        pops = clipOnLWUITBounds(cmp, g);
                        int x = fld.getLeft();
                        int y = fld.getTop();
                        g.clear(x, y, Math.max(cmp.getWidth(), fld.getWidth()), Math.max(cmp.getHeight(), fld.getHeight()));
                    }
                }
            }
            paintChild(g, fld);
            while (pops > 0) {
                g.popContext();
                pops--;
            }
        }
    } else {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
    }
    g.setColor(0);
    g.drawText(debug, 0, 0);
    painted = true;
}
Also used : EditField(net.rim.device.api.ui.component.EditField) Field(net.rim.device.api.ui.Field) PeerComponent(com.codename1.ui.PeerComponent) EditField(net.rim.device.api.ui.component.EditField) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 17 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class BooleanContainer method editNextTextArea.

/**
 * Opens onscreenkeyboard for the next textfield. The method works in EDT if
 * needed.
 */
public static void editNextTextArea() {
    Runnable task = new Runnable() {

        public void run() {
            Component next = getNextEditComponent();
            if (next != null) {
                if (next instanceof TextArea) {
                    TextArea text = (TextArea) next;
                    text.requestFocus();
                    Display.getInstance().editString(next, text.getMaxSize(), text.getConstraint(), text.getText(), 0);
                }
            } else {
                IOSImplementation.foldKeyboard();
            }
        }
    };
    Display.getInstance().callSerially(task);
}
Also used : TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component)

Example 18 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class RSSReader method createRendererContainer.

private Container createRendererContainer() {
    Container entries = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    entries.setUIID("RSSEntry");
    Label title = new Label();
    title.setName("title");
    title.setUIID("RSSTitle");
    entries.addComponent(title);
    TextArea description = new TextArea(2, 30);
    description.setGrowByContent(false);
    description.setName("details");
    description.setUIID("RSSDescription");
    description.setScrollVisible(false);
    entries.addComponent(description);
    if (iconPlaceholder != null) {
        Container wrap = new Container(new BorderLayout());
        wrap.addComponent(BorderLayout.CENTER, entries);
        Label icon = new Label();
        icon.setIcon(iconPlaceholder);
        icon.setUIID("RSSIcon");
        icon.setName("icon");
        wrap.addComponent(BorderLayout.WEST, icon);
        entries = wrap;
    }
    return entries;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) TextArea(com.codename1.ui.TextArea) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label)

Example 19 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class RSSReader method updateComponentValues.

void updateComponentValues(Container root, Hashtable h) {
    int c = root.getComponentCount();
    for (int iter = 0; iter < c; iter++) {
        Component current = root.getComponentAt(iter);
        // subclasses
        if (current.getClass() == com.codename1.ui.Container.class || current.getClass() == com.codename1.ui.Tabs.class) {
            updateComponentValues((Container) current, h);
            continue;
        }
        String n = current.getName();
        if (n != null) {
            String val = (String) h.get(n);
            if (val != null) {
                if (current instanceof Button) {
                    final String url = (String) val;
                    ((Button) current).addActionListener(new Listener(url));
                    continue;
                }
                if (current instanceof Label) {
                    ((Label) current).setText(val);
                    continue;
                }
                if (current instanceof TextArea) {
                    ((TextArea) current).setText(val);
                    continue;
                }
                if (current instanceof WebBrowser) {
                    ((WebBrowser) current).setPage(val, null);
                    continue;
                }
            }
        }
    }
}
Also used : Container(com.codename1.ui.Container) ActionListener(com.codename1.ui.events.ActionListener) Button(com.codename1.ui.Button) TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label) Component(com.codename1.ui.Component)

Example 20 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class JavaSEPort method editString.

/**
 * @inheritDoc
 */
public void editString(final Component cmp, int maxSize, int constraint, String text, int keyCode) {
    if (scrollWheeling) {
        return;
    }
    if (System.getProperty("TextCompatMode") != null) {
        editStringLegacy(cmp, maxSize, constraint, text, keyCode);
        return;
    }
    // a workaround to fix an issue where the previous Text Component wasn't removed properly.
    java.awt.Component[] cmps = canvas.getComponents();
    for (int i = 0; i < cmps.length; i++) {
        java.awt.Component cmp1 = cmps[i];
        if (cmp1 instanceof JScrollPane || cmp1 instanceof javax.swing.text.JTextComponent) {
            canvas.remove(cmp1);
        }
    }
    checkEDT();
    javax.swing.text.JTextComponent swingT;
    if (((com.codename1.ui.TextArea) cmp).isSingleLineTextArea()) {
        JTextComponent t;
        if (isDesktop() && (constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
            t = new JPasswordField() {

                public void repaint(long tm, int x, int y, int width, int height) {
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            cmp.repaint();
                        }
                    });
                }
            };
        } else {
            t = new JTextField() {

                public void repaint(long tm, int x, int y, int width, int height) {
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            cmp.repaint();
                        }
                    });
                }
            };
        /*
                ((JTextField)t).addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (cmp instanceof com.codename1.ui.TextField) {
                            final com.codename1.ui.TextField tf = (com.codename1.ui.TextField)cmp;
                            if (tf.getDoneListener() != null) {
                                Display.getInstance().callSerially(new Runnable() {
                                    public void run() {
                                        if (tf.getDoneListener() != null) {
                                            tf.fireDoneEvent();
                                        }
                                    }
                                });
                            }
                        }
                    }
                    
                });
                */
        }
        swingT = t;
        textCmp = swingT;
    } else {
        final com.codename1.ui.TextArea ta = (com.codename1.ui.TextArea) cmp;
        JTextArea t = new JTextArea(ta.getLines(), ta.getColumns()) {

            public void repaint(long tm, int x, int y, int width, int height) {
                int marginTop = cmp.getSelectedStyle().getPadding(Component.TOP);
                int marginLeft = cmp.getSelectedStyle().getPadding(Component.LEFT);
                int marginRight = cmp.getSelectedStyle().getPadding(Component.RIGHT);
                int marginBottom = cmp.getSelectedStyle().getPadding(Component.BOTTOM);
                Rectangle bounds;
                if (getSkin() != null) {
                    bounds = new Rectangle((int) ((cmp.getAbsoluteX() + cmp.getScrollX() + getScreenCoordinates().x + canvas.x + marginLeft) * zoomLevel), (int) ((cmp.getAbsoluteY() + cmp.getScrollY() + getScreenCoordinates().y + canvas.y + marginTop) * zoomLevel), (int) ((cmp.getWidth() - marginLeft - marginRight) * zoomLevel), (int) ((cmp.getHeight() - marginTop - marginBottom) * zoomLevel));
                } else {
                    bounds = new Rectangle(cmp.getAbsoluteX() + cmp.getScrollX() + marginLeft, cmp.getAbsoluteY() + cmp.getScrollY() + marginTop, cmp.getWidth() - marginRight - marginLeft, cmp.getHeight() - marginTop - marginBottom);
                }
                if (textCmp != null && !textCmp.getBounds().equals(bounds)) {
                    textCmp.setBounds(bounds);
                }
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        cmp.repaint();
                    }
                });
            }
        };
        t.setWrapStyleWord(true);
        t.setLineWrap(true);
        swingT = t;
        JScrollPane pane = new JScrollPane(swingT);
        pane.setBorder(null);
        pane.setOpaque(false);
        pane.getViewport().setOpaque(false);
        pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        textCmp = pane;
    }
    DefaultCaret caret = (DefaultCaret) swingT.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    swingT.setFocusTraversalKeysEnabled(false);
    TextEditUtil.setCurrentEditComponent(cmp);
    final javax.swing.text.JTextComponent txt = swingT;
    txt.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_TAB) {
                TextEditUtil.editNextTextArea();
            }
        }
    });
    swingT.setBorder(null);
    swingT.setOpaque(false);
    swingT.setForeground(new Color(cmp.getUnselectedStyle().getFgColor()));
    final javax.swing.text.JTextComponent tf = swingT;
    if (keyCode > 0) {
        text += ((char) keyCode);
        setText(tf, text);
        setCaretPosition(tf, text.length());
        if (cmp instanceof com.codename1.ui.TextField) {
            ((com.codename1.ui.TextField) cmp).setText(getText(tf));
        }
    } else {
        setText(tf, text);
    }
    textCmp.setBorder(null);
    textCmp.setOpaque(false);
    canvas.add(textCmp);
    int marginTop = cmp.getSelectedStyle().getPadding(Component.TOP);
    int marginLeft = cmp.getSelectedStyle().getPadding(Component.LEFT);
    int marginRight = cmp.getSelectedStyle().getPadding(Component.RIGHT);
    int marginBottom = cmp.getSelectedStyle().getPadding(Component.BOTTOM);
    if (getSkin() != null) {
        textCmp.setBounds((int) ((cmp.getAbsoluteX() + cmp.getScrollX() + getScreenCoordinates().x + canvas.x + marginLeft) * zoomLevel), (int) ((cmp.getAbsoluteY() + cmp.getScrollY() + getScreenCoordinates().y + canvas.y + marginTop) * zoomLevel), (int) ((cmp.getWidth() - marginLeft - marginRight) * zoomLevel), (int) ((cmp.getHeight() - marginTop - marginBottom) * zoomLevel));
        java.awt.Font f = font(cmp.getStyle().getFont().getNativeFont());
        tf.setFont(f.deriveFont(f.getSize2D() * zoomLevel));
    } else {
        textCmp.setBounds(cmp.getAbsoluteX() + cmp.getScrollX() + marginLeft, cmp.getAbsoluteY() + cmp.getScrollY() + marginTop, cmp.getWidth() - marginRight - marginLeft, cmp.getHeight() - marginTop - marginBottom);
        tf.setFont(font(cmp.getStyle().getFont().getNativeFont()));
    }
    setCaretPosition(tf, getText(tf).length());
    tf.requestFocus();
    tf.setSelectionStart(0);
    tf.setSelectionEnd(0);
    class Listener implements ActionListener, FocusListener, KeyListener, TextListener, Runnable, DocumentListener {

        public synchronized void run() {
            while (textCmp.getParent() != null) {
                try {
                    wait(20);
                } catch (InterruptedException ex) {
                }
            }
        }

        public void actionPerformed(ActionEvent e) {
            String txt = getText(tf);
            if (testRecorder != null) {
                testRecorder.editTextFieldCompleted(cmp, txt);
            }
            Display.getInstance().onEditingComplete(cmp, txt);
            if (e != null && cmp instanceof com.codename1.ui.TextField) {
                final com.codename1.ui.TextField cn1Tf = (com.codename1.ui.TextField) cmp;
                if (cmp != null && cn1Tf.getDoneListener() != null) {
                    cn1Tf.fireDoneEvent();
                }
            }
            if (tf instanceof JTextField) {
                ((JTextField) tf).removeActionListener(this);
            }
            ((JTextComponent) tf).getDocument().removeDocumentListener(this);
            tf.removeFocusListener(this);
            canvas.remove(textCmp);
            synchronized (this) {
                notify();
            }
            canvas.repaint();
        }

        public void focusGained(FocusEvent e) {
            setCaretPosition(tf, getText(tf).length());
        }

        public void focusLost(FocusEvent e) {
            actionPerformed(null);
        }

        public void keyTyped(KeyEvent e) {
            String t = getText(tf);
            if (t.length() >= ((TextArea) cmp).getMaxSize()) {
                e.consume();
            }
        }

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                if (tf instanceof JTextField) {
                    actionPerformed(null);
                } else {
                    if (getCaretPosition(tf) >= getText(tf).length() - 1) {
                        actionPerformed(null);
                    }
                }
                return;
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                if (tf instanceof JTextField) {
                    actionPerformed(null);
                } else {
                    if (getCaretPosition(tf) <= 2) {
                        actionPerformed(null);
                    }
                }
                return;
            }
        }

        public void textValueChanged(TextEvent e) {
            if (cmp instanceof com.codename1.ui.TextField) {
                updateText();
            }
        }

        private void updateText() {
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    if (cmp instanceof com.codename1.ui.TextField) {
                        ((com.codename1.ui.TextField) cmp).setText(getText(tf));
                    }
                }
            });
        }

        public void insertUpdate(DocumentEvent e) {
            updateText();
        }

        public void removeUpdate(DocumentEvent e) {
            updateText();
        }

        public void changedUpdate(DocumentEvent e) {
            updateText();
        }
    }
    ;
    final Listener l = new Listener();
    if (tf instanceof JTextField) {
        ((JTextField) tf).addActionListener(l);
    }
    ((JTextComponent) tf).getDocument().addDocumentListener(l);
    tf.addKeyListener(l);
    tf.addFocusListener(l);
    if (simulateAndroidKeyboard) {
        java.util.Timer t = new java.util.Timer();
        TimerTask tt = new TimerTask() {

            @Override
            public void run() {
                if (!Display.getInstance().isEdt()) {
                    Display.getInstance().callSerially(this);
                    return;
                }
                if (tf.getParent() != null) {
                    final int height = getScreenCoordinates().height;
                    JavaSEPort.this.sizeChanged(getScreenCoordinates().width, height / 2);
                    new UITimer(new Runnable() {

                        public void run() {
                            if (tf.getParent() != null) {
                                new UITimer(this).schedule(100, false, Display.getInstance().getCurrent());
                            } else {
                                JavaSEPort.this.sizeChanged(getScreenCoordinates().width, height);
                            }
                        }
                    }).schedule(100, false, Display.getInstance().getCurrent());
                }
            }
        };
        t.schedule(tt, 300);
    }
    Display.getInstance().invokeAndBlock(l);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) FocusListener(java.awt.event.FocusListener) TextListener(java.awt.event.TextListener) KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) AdjustmentListener(java.awt.event.AdjustmentListener) MouseMotionListener(java.awt.event.MouseMotionListener) MouseWheelListener(java.awt.event.MouseWheelListener) DocumentListener(javax.swing.event.DocumentListener) ItemListener(java.awt.event.ItemListener) WindowListener(java.awt.event.WindowListener) MouseListener(java.awt.event.MouseListener) MenuListener(javax.swing.event.MenuListener) HierarchyBoundsListener(java.awt.event.HierarchyBoundsListener) TextArea(com.codename1.ui.TextArea) UITimer(com.codename1.ui.util.UITimer) ActionEvent(java.awt.event.ActionEvent) Rectangle(java.awt.Rectangle) JTextComponent(javax.swing.text.JTextComponent) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) DefaultCaret(javax.swing.text.DefaultCaret) FontRenderContext(java.awt.font.FontRenderContext) BrowserComponent(com.codename1.ui.BrowserComponent) Component(com.codename1.ui.Component) JTextComponent(javax.swing.text.JTextComponent) PeerComponent(com.codename1.ui.PeerComponent) TextEvent(java.awt.event.TextEvent) Color(java.awt.Color) TextListener(java.awt.event.TextListener) DocumentEvent(javax.swing.event.DocumentEvent) JTextComponent(javax.swing.text.JTextComponent) Point(java.awt.Point) ActionListener(java.awt.event.ActionListener) java.util(java.util) UITimer(com.codename1.ui.util.UITimer) KeyListener(java.awt.event.KeyListener) TextArea(com.codename1.ui.TextArea) FocusListener(java.awt.event.FocusListener) java.awt(java.awt)

Aggregations

TextArea (com.codename1.ui.TextArea)46 Component (com.codename1.ui.Component)22 Label (com.codename1.ui.Label)11 Button (com.codename1.ui.Button)10 Container (com.codename1.ui.Container)10 Form (com.codename1.ui.Form)10 RadioButton (com.codename1.ui.RadioButton)8 PeerComponent (com.codename1.ui.PeerComponent)6 TextField (com.codename1.ui.TextField)6 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Font (com.codename1.ui.Font)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 CheckBox (com.codename1.ui.CheckBox)4 Dialog (com.codename1.ui.Dialog)4 List (com.codename1.ui.List)4 Hashtable (java.util.Hashtable)4 Paint (android.graphics.Paint)3 Command (com.codename1.ui.Command)3 Slider (com.codename1.ui.Slider)3 ActionEvent (com.codename1.ui.events.ActionEvent)3