Search in sources :

Example 96 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class LayeredLayout method layoutContainer.

/**
 * {@inheritDoc}
 */
public void layoutContainer(Container parent) {
    Style s = parent.getStyle();
    int top = s.getPaddingTop();
    int bottom = parent.getLayoutHeight() - parent.getBottomGap() - s.getPaddingBottom();
    int left = s.getPaddingLeft(parent.isRTL());
    int right = parent.getLayoutWidth() - parent.getSideGap() - s.getPaddingRight(parent.isRTL());
    int numOfcomponents = parent.getComponentCount();
    tmpLaidOut.clear();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        layoutComponent(parent, cmp, top, left, bottom, right);
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Example 97 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class IOSImplementation method updateNativeTextEditorFrame.

private static void updateNativeTextEditorFrame() {
    if (instance.currentEditing != null) {
        TextArea cmp = instance.currentEditing;
        final Style stl = cmp.getStyle();
        final boolean rtl = UIManager.getInstance().getLookAndFeel().isRTL();
        instance.doNotHideTextEditorSemaphore++;
        try {
            instance.currentEditing.requestFocus();
        } finally {
            instance.doNotHideTextEditorSemaphore--;
        }
        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(cmp.isSingleLineTextArea()) {
                switch(cmp.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;
                }
            }
            */
        int maxH = Display.getInstance().getDisplayHeight() - nativeInstance.getVKBHeight();
        if (h > maxH) {
            // For text areas, we don't want the keyboard to cover part of the
            // typing region.  So we will try to size the component to
            // to only go up to the top edge of the keyboard
            // that should allow the OS to enable scrolling properly.... at least
            // in theory.
            h = maxH;
        }
        nativeInstance.resizeNativeTextView(x, y, w, h, pt, pr, pb, pl);
    }
}
Also used : TextArea(com.codename1.ui.TextArea) Style(com.codename1.ui.plaf.Style)

Example 98 with Style

use of com.codename1.ui.plaf.Style 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 99 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class ImageDownloadService method createImageToStorage.

/**
 * Constructs an image request that will automatically populate the given list
 * when the response arrives, it will cache the file locally as a file
 * in the file storage.
 * This assumes the GenericListCellRenderer style of
 * list which relies on a map based model approach.
 *
 * @param url the image URL
 * @param targetList the list that should be updated when the data arrives
 * @param targetModel the model
 * @param targetOffset the offset within the list to insert the image
 * @param targetKey the key for the map in the target offset
 * @param cacheId a unique identifier to be used to store the image into storage
 * @param keep if set to true keeps the file in RAM once loaded
 * @param scale the scale of the image to put in the List or null
 */
private static void createImageToStorage(final String url, final Component targetList, final ListModel targetModel, final int targetOffset, final String targetKey, final String cacheId, final boolean keep, final Dimension scale, final byte priority, final Image placeholderImage, final boolean maintainAspectRatio) {
    if (Display.getInstance().isEdt()) {
        Display.getInstance().scheduleBackgroundTask(new Runnable() {

            public void run() {
                createImageToStorage(url, targetList, targetModel, targetOffset, targetKey, cacheId, keep, scale, priority, placeholderImage, maintainAspectRatio);
            }
        });
        return;
    }
    Image im = cacheImage(cacheId, keep, null, scale, placeholderImage, maintainAspectRatio);
    ImageDownloadService i = new ImageDownloadService(url, targetList, targetOffset, targetKey);
    i.targetModel = targetModel;
    i.maintainAspectRatio = maintainAspectRatio;
    if (im != null) {
        i.setEntryInListModel(targetOffset, im);
        targetList.repaint();
        return;
    }
    // image not found on cache go and download from the url
    i.cacheImages = true;
    i.cacheId = cacheId;
    i.keep = keep;
    i.toScale = scale;
    i.placeholder = placeholderImage;
    i.setPriority(priority);
    i.setFailSilently(true);
    NetworkManager.getInstance().addToQueue(i);
}
Also used : EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) FileEncodedImage(com.codename1.components.FileEncodedImage) StorageImage(com.codename1.components.StorageImage)

Example 100 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class Container method calcPreferredSize.

/**
 * {@inheritDoc}
 */
protected Dimension calcPreferredSize() {
    Dimension d = layout.getPreferredSize(this);
    Style style = getStyle();
    if (style.getBorder() != null && d.getWidth() != 0 && d.getHeight() != 0) {
        d.setWidth(Math.max(style.getBorder().getMinimumWidth(), d.getWidth()));
        d.setHeight(Math.max(style.getBorder().getMinimumHeight(), d.getHeight()));
    }
    if (UIManager.getInstance().getLookAndFeel().isBackgroundImageDetermineSize() && style.getBgImage() != null) {
        d.setWidth(Math.max(style.getBgImage().getWidth(), d.getWidth()));
        d.setHeight(Math.max(style.getBgImage().getHeight(), d.getHeight()));
    }
    return d;
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Style (com.codename1.ui.plaf.Style)103 Dimension (com.codename1.ui.geom.Dimension)28 Component (com.codename1.ui.Component)25 Image (com.codename1.ui.Image)20 Rectangle (com.codename1.ui.geom.Rectangle)13 Container (com.codename1.ui.Container)11 Font (com.codename1.ui.Font)11 FontImage (com.codename1.ui.FontImage)11 Border (com.codename1.ui.plaf.Border)8 Form (com.codename1.ui.Form)6 Label (com.codename1.ui.Label)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 IOException (java.io.IOException)6 UIManager (com.codename1.ui.plaf.UIManager)5 Vector (java.util.Vector)5 Dialog (com.codename1.ui.Dialog)4 EncodedImage (com.codename1.ui.EncodedImage)4 Graphics (com.codename1.ui.Graphics)4 TextArea (com.codename1.ui.TextArea)4 SpanButton (com.codename1.components.SpanButton)3