Search in sources :

Example 16 with Constraint

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

the class GridBagLayoutInfo method addLayoutComponent.

public void addLayoutComponent(Object constraints, Component comp, Container c) {
    GridBagConstraints cons;
    if (constraints != null) {
        if (!(constraints instanceof GridBagConstraints)) {
            // $NON-NLS-1$
            throw new IllegalArgumentException("AddLayoutComponent: constraint object must be GridBagConstraints");
        }
        cons = (GridBagConstraints) constraints;
    } else {
        if (comptable.containsKey(comp)) {
            // don't replace constraints with default ones
            return;
        }
        cons = defaultConstraints;
    }
    /*try {
            //cons.verify();
        } catch (IllegalArgumentException e) {
            // awt.81=AddLayoutComponent: {0}
            throw new IllegalArgumentException("AddLayoutComponent: " + e.getMessage()); //$NON-NLS-1$
        }*/
    GridBagConstraints consClone = (GridBagConstraints) cons.clone();
    comptable.put(comp, consClone);
    Container parent = comp.getParent();
    updateParentInfo(parent, consClone);
}
Also used : Container(com.codename1.ui.Container)

Example 17 with Constraint

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

the class LayeredLayout method calcPreferredValues.

private void calcPreferredValues(Component cmp) {
    if (tmpLaidOut.contains(cmp)) {
        return;
    }
    tmpLaidOut.add(cmp);
    LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
    if (constraint != null) {
        constraint.fixDependencies(cmp.getParent());
        for (LayeredLayoutConstraint.Inset inset : constraint.insets) {
            if (inset.referenceComponent != null && inset.referenceComponent.getParent() == cmp.getParent()) {
                calcPreferredValues(inset.referenceComponent);
            }
            inset.calcPreferredValue(cmp.getParent(), cmp);
        }
    }
}
Also used : Inset(com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)

Example 18 with Constraint

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

the class MigLayout method setComponentConstraintsImpl.

/**
 * Sets the component constraint for the component that already must be
 * handled by this layout manager.
 * <p>
 * See the class JavaDocs for information on how this string is formatted.
 *
 * @param constr The component constraints as a String or
 * {@link net.miginfocom.layout.CC}. <code>null</code> is ok.
 * @param comp The component to set the constraints for.
 * @param noCheck Doe not check if the component is handled if true
 * @throws RuntimeException if the constraint was not valid.
 * @throws IllegalArgumentException If the component is not handling the
 * component.
 */
private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck) {
    Container parent = comp.getParent();
    if (noCheck == false && scrConstrMap.containsKey(comp) == false) {
        throw new IllegalArgumentException("Component must already be added to parent!");
    }
    ComponentWrapper cw = new CodenameOneMiGComponentWrapper(comp);
    if (constr == null || constr instanceof String) {
        String cStr = ConstraintParser.prepare((String) constr);
        scrConstrMap.put(comp, constr);
        ccMap.put(cw, ConstraintParser.parseComponentConstraint(cStr));
    } else if (constr instanceof CC) {
        scrConstrMap.put(comp, constr);
        ccMap.put(cw, (CC) constr);
    } else {
        throw new IllegalArgumentException("Constraint must be String or ComponentConstraint: " + constr.getClass().toString());
    }
    dirty = true;
}
Also used : CC(com.codename1.ui.layouts.mig.CC) Container(com.codename1.ui.Container) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Example 19 with Constraint

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

the class IOSImplementation method editString.

public void editString(final Component cmp, final int maxSize, final int constraint, final String text, final int i) {
    // The very first time we try to edit a string, let's determine if the
    // system default is to do async editing.  If the system default
    // is not yet set, we set it here, and it will be used as the default from now on
    // We do this because the nativeInstance.isAsyncEditMode() value changes
    // to reflect the currently edited field so it isn't a good way to keep a
    // system default.
    pendingEditingText = false;
    String defaultAsyncEditingSetting = Display.getInstance().getProperty("ios.VKBAlwaysOpen", null);
    if (defaultAsyncEditingSetting == null) {
        defaultAsyncEditingSetting = nativeInstance.isAsyncEditMode() ? "true" : "false";
        Display.getInstance().setProperty("ios.VKBAlwaysOpen", defaultAsyncEditingSetting);
    }
    boolean asyncEdit = "true".equals(defaultAsyncEditingSetting) ? true : false;
    try {
        if (currentEditing != cmp && currentEditing != null && currentEditing instanceof TextArea) {
            Display.getInstance().onEditingComplete(currentEditing, ((TextArea) currentEditing).getText());
            currentEditing = null;
            callHideTextEditor();
            if (nativeInstance.isAsyncEditMode()) {
                nativeInstance.setNativeEditingComponentVisible(false);
            }
            synchronized (EDITING_LOCK) {
                EDITING_LOCK.notify();
            }
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    pendingEditingText = true;
                    Display.getInstance().editString(cmp, maxSize, constraint, text, i);
                }
            });
            return;
        }
        if (cmp.isFocusable() && !cmp.hasFocus()) {
            doNotHideTextEditorSemaphore++;
            try {
                cmp.requestFocus();
            } finally {
                doNotHideTextEditorSemaphore--;
            }
            // of our upcoming field.
            if (isAsyncEditMode()) {
                // flush the EDT so the focus will work...
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        pendingEditingText = true;
                        Display.getInstance().editString(cmp, maxSize, constraint, text, i);
                    }
                });
                return;
            }
        }
        // Check if the form has any setting for asyncEditing that should override
        // the application defaults.
        Form parentForm = cmp.getComponentForm();
        if (parentForm == null) {
            // Log.p("Attempt to edit text area that is not on a form.  This is not supported");
            return;
        }
        if (parentForm.getClientProperty("asyncEditing") != null) {
            Object async = parentForm.getClientProperty("asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Form overriding asyncEdit due to asyncEditing client property: "+asyncEdit);
            }
        }
        if (parentForm.getClientProperty("ios.asyncEditing") != null) {
            Object async = parentForm.getClientProperty("ios.asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Form overriding asyncEdit due to ios.asyncEditing client property: "+asyncEdit);
            }
        }
        // editing - and should instead revert to legacy editing mode.
        if (asyncEdit && !parentForm.isFormBottomPaddingEditingMode()) {
            Container p = cmp.getParent();
            // A crude estimate of how far the component needs to be able to scroll to make
            // async editing viable.  We start with half-way down the screen.
            int keyboardClippingThresholdY = Display.getInstance().getDisplayWidth() / 2;
            while (p != null) {
                if (Accessor.scrollableYFlag(p) && p.getAbsoluteY() < keyboardClippingThresholdY) {
                    break;
                }
                p = p.getParent();
            }
            // no scrollabel parent automatically configure the text field for legacy mode
            // nativeInstance.setAsyncEditMode(p != null);
            asyncEdit = p != null;
        // Log.p("Overriding asyncEdit due to form scrollability: "+asyncEdit);
        } else if (parentForm.isFormBottomPaddingEditingMode()) {
            // If form uses bottom padding mode, then we will always
            // use async edit (unless the field explicitly overrides it).
            asyncEdit = true;
        // Log.p("Overriding asyncEdit due to form bottom padding edit mode: "+asyncEdit);
        }
        // then this will override all other settings.
        if (cmp.getClientProperty("asyncEditing") != null) {
            Object async = cmp.getClientProperty("asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Overriding asyncEdit due to field asyncEditing client property: "+asyncEdit);
            }
        }
        if (cmp.getClientProperty("ios.asyncEditing") != null) {
            Object async = cmp.getClientProperty("ios.asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Overriding asyncEdit due to field ios.asyncEditing client property: "+asyncEdit);
            }
        }
        // Finally we set the async edit mode for this field.
        // System.out.println("Async edit mode is "+asyncEdit);
        nativeInstance.setAsyncEditMode(asyncEdit);
        textEditorHidden = false;
        currentEditing = (TextArea) cmp;
        // register the edited TextArea to support moving to the next field
        TextEditUtil.setCurrentEditComponent(cmp);
        final NativeFont fnt = f(cmp.getStyle().getFont().getNativeFont());
        boolean forceSlideUpTmp = false;
        final Form current = Display.getInstance().getCurrent();
        if (current instanceof Dialog && !isTablet()) {
            // special case, if we are editing a small dialog we want to move it
            // so the bottom of the dialog shows within the screen. This is
            // described in issue 505
            Dialog dlg = (Dialog) current;
            Component c = dlg.getDialogComponent();
            if (c.getHeight() < Display.getInstance().getDisplayHeight() / 2 && c.getAbsoluteY() + c.getHeight() > Display.getInstance().getDisplayHeight() / 2) {
                forceSlideUpTmp = true;
            }
        }
        final boolean forceSlideUp = forceSlideUpTmp;
        cmp.repaint();
        // give the repaint one cycle to "do its magic...
        final Style stl = currentEditing.getStyle();
        final boolean rtl = UIManager.getInstance().getLookAndFeel().isRTL();
        Display.getInstance().callSerially(new Runnable() {

            @Override
            public void run() {
                int x = cmp.getAbsoluteX() + cmp.getScrollX();
                int y = cmp.getAbsoluteY() + cmp.getScrollY();
                int w = cmp.getWidth();
                int h = cmp.getHeight();
                int pt = stl.getPaddingTop();
                int pb = stl.getPaddingBottom();
                int pl = stl.getPaddingLeft(rtl);
                int pr = stl.getPaddingRight(rtl);
                /*
                    if(currentEditing != null && currentEditing.isSingleLineTextArea()) {
                        switch(currentEditing.getVerticalAlignment()) {
                            case TextArea.CENTER:
                                if(h > cmp.getPreferredH()) {
                                    y += (h / 2 - cmp.getPreferredH() / 2);
                                }
                                break;
                            case TextArea.BOTTOM:
                                if(h > cmp.getPreferredH()) {
                                    y += (h - cmp.getPreferredH());
                                }
                                break;
                        }
                    }
                    */
                String hint = null;
                if (currentEditing != null && currentEditing.getUIManager().isThemeConstant("nativeHintBool", true) && currentEditing.getHint() != null) {
                    hint = currentEditing.getHint();
                }
                if (isAsyncEditMode()) {
                    // request focus triggers a scroll which flicks the textEditorHidden flag
                    doNotHideTextEditorSemaphore++;
                    try {
                        cmp.requestFocus();
                    } finally {
                        doNotHideTextEditorSemaphore--;
                    }
                    textEditorHidden = false;
                }
                boolean showToolbar = cmp.getClientProperty("iosHideToolbar") == null;
                if (showToolbar && Display.getInstance().getProperty("iosHideToolbar", "false").equalsIgnoreCase("true")) {
                    showToolbar = false;
                }
                if (currentEditing != null) {
                    nativeInstance.editStringAt(x, y, w, h, fnt.peer, currentEditing.isSingleLineTextArea(), currentEditing.getRows(), maxSize, constraint, text, forceSlideUp, // peer,
                    stl.getFgColor(), // peer,
                    0, pt, pb, pl, pr, hint, showToolbar, Boolean.TRUE.equals(cmp.getClientProperty("blockCopyPaste")), currentEditing.getStyle().getAlignment(), currentEditing.getVerticalAlignment());
                }
            }
        });
        if (isAsyncEditMode()) {
            return;
        }
        editNext = false;
        Display.getInstance().invokeAndBlock(new Runnable() {

            @Override
            public void run() {
                synchronized (EDITING_LOCK) {
                    while (instance.currentEditing == cmp) {
                        try {
                            EDITING_LOCK.wait(20);
                        } catch (InterruptedException ex) {
                        }
                    }
                }
            }
        });
        if (cmp instanceof TextArea && !((TextArea) cmp).isSingleLineTextArea()) {
            Form form = cmp.getComponentForm();
            if (form != null) {
                form.revalidate();
            }
        }
        if (editNext) {
            editNext = false;
            TextEditUtil.editNextTextArea();
        }
    } finally {
    }
}
Also used : TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) Container(com.codename1.ui.Container) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style) BrowserComponent(com.codename1.ui.BrowserComponent) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 20 with Constraint

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

the class Container method insertComponentAt.

void insertComponentAt(final int index, final Object constraint, final Component cmp) {
    AnimationManager a = getAnimationManager();
    if (a != null && a.isAnimating()) {
        // pretend like the component was already added
        if (cmp.getParent() != null) {
            throw new IllegalArgumentException("Component is already contained in Container: " + cmp.getParent());
        }
        cmp.setParent(this);
        a.addAnimation(new ComponentAnimation() {

            private boolean alreadyAdded;

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

            @Override
            protected void updateState() {
                if (!alreadyAdded) {
                    alreadyAdded = true;
                    cmp.setParent(null);
                    if (constraint != null) {
                        layout.addLayoutComponent(constraint, cmp, Container.this);
                    }
                    insertComponentAtImpl(index, cmp);
                    revalidate();
                }
            }

            @Override
            public void flush() {
                updateState();
            }
        });
    } else {
        if (constraint != null) {
            layout.addLayoutComponent(constraint, cmp, this);
        }
        insertComponentAtImpl(index, cmp);
    }
}
Also used : ComponentAnimation(com.codename1.ui.animations.ComponentAnimation)

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