Search in sources :

Example 6 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint in project CodenameOne by codenameone.

the class BlackBerryImplementation method editString.

public void editString(final Component cmp, final int maxSize, final int constraint, final String text, int keyCode) {
    TextArea txtCmp = (TextArea) cmp;
    String edit = (String) txtCmp.getClientProperty("RIM.nativePopup");
    if (edit != null) {
        EditPopup editpop = new EditPopup(txtCmp, maxSize);
        editpop.startEdit();
    } else {
        nativeEdit(txtCmp, txtCmp.getMaxSize(), txtCmp.getConstraint(), txtCmp.getText(), keyCode);
    }
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 7 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint 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)

Example 8 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint in project CodenameOne by codenameone.

the class JavaSEPort method editStringLegacy.

public void editStringLegacy(final Component cmp, int maxSize, int constraint, String text, int keyCode) {
    checkEDT();
    java.awt.Component awtTf;
    if (cmp instanceof com.codename1.ui.TextField) {
        java.awt.TextField t = new java.awt.TextField();
        awtTf = t;
        t.setSelectionEnd(0);
        t.setSelectionStart(0);
    } else {
        java.awt.TextArea t = new java.awt.TextArea("", 0, 0, java.awt.TextArea.SCROLLBARS_NONE);
        ;
        awtTf = t;
        t.setSelectionEnd(0);
        t.setSelectionStart(0);
    }
    final java.awt.Component tf = awtTf;
    if (keyCode > 0) {
        text += ((char) keyCode);
        setText(tf, text);
        setCaretPosition(tf, text.length());
        ((com.codename1.ui.TextField) cmp).setText(getText(tf));
    } else {
        setText(tf, text);
    }
    canvas.add(tf);
    if (getSkin() != null) {
        tf.setBounds((int) ((cmp.getAbsoluteX() + getScreenCoordinates().x + canvas.x) * zoomLevel), (int) ((cmp.getAbsoluteY() + getScreenCoordinates().y + canvas.y) * zoomLevel), (int) (cmp.getWidth() * zoomLevel), (int) (cmp.getHeight() * zoomLevel));
        java.awt.Font f = font(cmp.getStyle().getFont().getNativeFont());
        tf.setFont(f.deriveFont(f.getSize2D() * zoomLevel));
    } else {
        tf.setBounds(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());
        tf.setFont(font(cmp.getStyle().getFont().getNativeFont()));
    }
    setCaretPosition(tf, getText(tf).length());
    tf.requestFocus();
    class Listener implements ActionListener, FocusListener, KeyListener, TextListener, Runnable {

        public synchronized void run() {
            while (tf.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 (tf instanceof java.awt.TextField) {
                ((java.awt.TextField) tf).removeActionListener(this);
            }
            ((TextComponent) tf).removeTextListener(this);
            tf.removeFocusListener(this);
            canvas.remove(tf);
            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 java.awt.TextField) {
                    actionPerformed(null);
                } else {
                    if (getCaretPosition(tf) >= getText(tf).length() - 1) {
                        actionPerformed(null);
                    }
                }
                return;
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                if (tf instanceof java.awt.TextField) {
                    actionPerformed(null);
                } else {
                    if (getCaretPosition(tf) <= 2) {
                        actionPerformed(null);
                    }
                }
                return;
            }
        }

        public void textValueChanged(TextEvent e) {
            if (cmp instanceof com.codename1.ui.TextField) {
                ((com.codename1.ui.TextField) cmp).setText(getText(tf));
            }
        }
    }
    ;
    final Listener l = new Listener();
    if (tf instanceof java.awt.TextField) {
        ((java.awt.TextField) tf).addActionListener(l);
    }
    ((TextComponent) tf).addTextListener(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 : 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) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) JTextComponent(javax.swing.text.JTextComponent) TextEvent(java.awt.event.TextEvent) TextListener(java.awt.event.TextListener) Point(java.awt.Point) ActionListener(java.awt.event.ActionListener) java.util(java.util) UITimer(com.codename1.ui.util.UITimer) KeyListener(java.awt.event.KeyListener) FocusListener(java.awt.event.FocusListener) java.awt(java.awt)

Example 9 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint in project CodenameOne by codenameone.

the class Container method wrapInLayeredPane.

/**
 * An atomic operation that wraps the current component in a Container with
 * a layered layout.  This prevents us from having to initialize and deinitialize
 * all of the components in a sub-tree because we want to re-root it.  In particular
 * Form.getLayeredPane() re-roots the entire content pane the first time it is
 * called on a form.  If the form contains native peers there is a flicker which
 * is quite annoying.  Providing a way to do this atomically results in a better
 * user experience.
 * @return The Container that is the new parent of this component.
 */
Container wrapInLayeredPane() {
    final Container oldParent = getParent();
    final Container newParent = new Container(new LayeredLayout());
    final Layout parentLayout = oldParent != null && oldParent.layout != null ? oldParent.layout : null;
    final Object constraint = parentLayout != null ? parentLayout.getComponentConstraint(this) : null;
    newParent.setParent(oldParent);
    newParent.components.add(this);
    final Runnable r = new Runnable() {

        public void run() {
            if (parentLayout != null) {
                parentLayout.removeLayoutComponent(Container.this);
                parentLayout.addLayoutComponent(constraint, newParent, oldParent);
            }
            newParent.initComponentImpl();
            if (oldParent != null) {
                int cmpIndex = -1;
                for (int i = 0; i < oldParent.getComponentCount(); i++) {
                    Component c = oldParent.getComponentAt(i);
                    if (c.equals(Container.this)) {
                        cmpIndex = i;
                        break;
                    }
                }
                // int cmpIndex = oldParent.getComponentIndex(Container.this);  <---  WTF... this always returns -1!!
                if (cmpIndex == -1) {
                    throw new RuntimeException("WTF we have parent but no index!!!!");
                }
                oldParent.components.set(cmpIndex, newParent);
            }
            Container.this.setParent(newParent);
            newParent.revalidate();
        }
    };
    AnimationManager a = getAnimationManager();
    if (a != null && a.isAnimating()) {
        a.addAnimation(new ComponentAnimation() {

            @Override
            public boolean isInProgress() {
                return false;
            }

            @Override
            protected void updateState() {
                r.run();
            }
        });
        return newParent;
    } else {
        r.run();
        return newParent;
    }
}
Also used : ComponentAnimation(com.codename1.ui.animations.ComponentAnimation) Layout(com.codename1.ui.layouts.Layout) BoxLayout(com.codename1.ui.layouts.BoxLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 10 with Constraint

use of com.codename1.ui.table.TableLayout.Constraint in project CodenameOne by codenameone.

the class HTMLComponent method handleTableCell.

/**
 * Handles a single table cell (a TD tag)
 *
 * @param tdTag The TD tag element
 * @param align The current alignment
 */
private void handleTableCell(HTMLElement tdTag, int align) {
    newLineIfNotEmpty(align);
    tableCells.addElement(curContainer);
    Container cell = new Container();
    cell.getStyle().setBgTransparency(0);
    cell.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    // int border=0;
    HTMLElement trTag = (HTMLElement) tdTag.getParent();
    while ((trTag != null) && (trTag.getTagId() != HTMLElement.TAG_TR)) {
        // Though in strict XHTML TR can only contain TD/TH - in some HTMLs TR doesn't have to be the direct parent of the tdTag, i.e.: <tr><b><td>...</td>... </b></tr>
        trTag = (HTMLElement) trTag.getParent();
    }
    // Commented since the table border should not affect cell border
    /*if (trTag!=null) { // Null checks to prevent exceptions for a TD tag without table etc.
                HTMLElement tableTag=(HTMLElement)trTag.getParent();
                while ((tableTag!=null) && (tableTag.getTagId()!=HTMLElement.TAG_TABLE)) { // Though in strict XHTML TABLE can only contain TR - in some HTMLs it might be different
                    tableTag=(HTMLElement)tableTag.getParent();
                }

                if (tableTag!=null) {
                    border=getInt(tableTag.getAttributeById(HTMLElement.ATTR_BORDER));
                }
            }
            cell.getUnselectedStyle().setPadding(border, border, border, border);
            cell.getSelectedStyle().setPadding(border, border, border, border);*/
    // Constraint constraint = new Constraint();
    CellConstraint constraint = new CellConstraint();
    int halign = align;
    int valign = Component.CENTER;
    if (trTag != null) {
        HTMLElement tGroupTag = (HTMLElement) trTag.getParent();
        int tagId = tGroupTag.getTagId();
        if ((tagId == HTMLElement.TAG_TBODY) || (tagId == HTMLElement.TAG_THEAD) || (tagId == HTMLElement.TAG_TFOOT)) {
            // Get the default TR alignment
            halign = getHorizAlign(tGroupTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
            // Get the default TR valignment
            valign = getVertAlign(tGroupTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
        }
        // Get the default TR alignment
        halign = getHorizAlign(trTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
        // Get the default TR valignment
        valign = getVertAlign(trTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
    }
    halign = getHorizAlign(tdTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
    valign = getVertAlign(tdTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
    int colspan = getInt(tdTag.getAttributeById(HTMLElement.ATTR_COLSPAN));
    int rowspan = getInt(tdTag.getAttributeById(HTMLElement.ATTR_ROWSPAN));
    String cWidth = tdTag.getAttributeById(HTMLElement.ATTR_WIDTH);
    int pW = getPercentage(cWidth);
    if ((pW > 0) && (pW < 100)) {
    // constraint.setWidthPercentage(pW); //TODO - Setting a width constraint currently makes the field width 0 - needs to be fixed in TableLayout
    } else {
        pW = getInt(cWidth);
        if (pW != 0) {
            cell.setPreferredW(pW);
        }
    }
    String cHeight = tdTag.getAttributeById(HTMLElement.ATTR_HEIGHT);
    int pH = getPercentage(cHeight);
    if ((pH > 0) && (pH < 100)) {
    // constraint.setHeightPercentage(pH); //TODO - Setting a height constraint currently makes the field height 0 - needs to be fixed in TableLayout
    } else {
        pH = getInt(cHeight);
        if (pH != 0) {
            cell.setPreferredH(pH);
        }
    }
    constraint.setHorizontalAlign(halign);
    constraint.setVerticalAlign(valign);
    if (colspan > 1) {
        constraint.setHorizontalSpan(colspan);
    }
    if (rowspan > 1) {
        constraint.setVerticalSpan(rowspan);
    }
    curContainer = cell;
    if (curTable != null) {
        curTable.addCell(cell, (tdTag.getTagId() == HTMLElement.TAG_TH), constraint);
    }
    if (loadCSS) {
        tdTag.setAssociatedComponents(cell);
        if (trTag != null) {
            trTag.addAssociatedComponent(cell);
        }
    }
}
Also used : Container(com.codename1.ui.Container) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Aggregations

Component (com.codename1.ui.Component)8 TextArea (com.codename1.ui.TextArea)6 Style (com.codename1.ui.plaf.Style)5 Container (com.codename1.ui.Container)4 PeerComponent (com.codename1.ui.PeerComponent)4 Point (java.awt.Point)3 BrowserComponent (com.codename1.ui.BrowserComponent)2 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)2 Dimension (com.codename1.ui.geom.Dimension)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 BoxLayout (com.codename1.ui.layouts.BoxLayout)2 Inset (com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)2 UITimer (com.codename1.ui.util.UITimer)2 java.awt (java.awt)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 AdjustmentListener (java.awt.event.AdjustmentListener)2 FocusEvent (java.awt.event.FocusEvent)2 FocusListener (java.awt.event.FocusListener)2 HierarchyBoundsListener (java.awt.event.HierarchyBoundsListener)2