Search in sources :

Example 36 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class Component method refreshTheme.

/**
 * Makes sure the component is up to date with the given UIID
 *
 * @param id The Style Id to update the Component with
 * @param merge indicates if the current styles should be merged with the new styles
 */
protected void refreshTheme(String id, boolean merge) {
    UIManager manager = getUIManager();
    if (merge) {
        Style unSelected = getUnselectedStyle();
        if (hasInlineUnselectedStyle()) {
            setUnselectedStyle(mergeStyle(unSelected, manager.parseComponentStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), getInlineUnselectedStyleStrings())));
        } else {
            setUnselectedStyle(mergeStyle(unSelected, manager.getComponentStyle(id)));
        }
        if (selectedStyle != null) {
            if (hasInlineSelectedStyle()) {
                setSelectedStyle(mergeStyle(selectedStyle, manager.parseComponentSelectedStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), getInlineSelectedStyleStrings())));
            } else {
                setSelectedStyle(mergeStyle(selectedStyle, manager.getComponentSelectedStyle(id)));
            }
        }
        if (disabledStyle != null) {
            if (hasInlineDisabledStyle()) {
                setDisabledStyle(mergeStyle(disabledStyle, manager.parseComponentCustomStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), "dis", getInlineDisabledStyleStrings())));
            } else {
                setDisabledStyle(mergeStyle(disabledStyle, manager.getComponentCustomStyle(id, "dis")));
            }
        }
        if (pressedStyle != null) {
            if (hasInlinePressedStyle()) {
                setPressedStyle(mergeStyle(pressedStyle, manager.parseComponentCustomStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), "press", getInlinePressedStyleStrings())));
            } else {
                setPressedStyle(mergeStyle(pressedStyle, manager.getComponentCustomStyle(id, "press")));
            }
        }
    } else {
        unSelectedStyle = null;
        unSelectedStyle = getUnselectedStyle();
        selectedStyle = null;
        disabledStyle = null;
        pressedStyle = null;
        allStyles = null;
    }
    checkAnimation();
    manager.getLookAndFeel().bind(this);
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style)

Example 37 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class Component method deinitializeImpl.

/**
 * Cleansup the initialization flags in the hierachy, notice that paint calls might
 * still occur after deinitilization mostly to perform transitions etc.
 * <p>However interactivity, animation and event tracking code can and probably
 * should be removed by this method.
 */
void deinitializeImpl() {
    if (isInitialized()) {
        hideNativeOverlay();
        paintLockRelease();
        setInitialized(false);
        setDirtyRegion(null);
        Style stl = getStyle();
        Image i = stl.getBgImage();
        if (i != null) {
            i.unlock();
        } else {
            Border b = stl.getBorder();
            if (b != null) {
                b.unlock();
            }
        }
        Painter p = stl.getBgPainter();
        if (p instanceof BGPainter) {
            ((BGPainter) p).radialCache = null;
        }
        deinitialize();
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Border(com.codename1.ui.plaf.Border)

Example 38 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class Component method pointerDragged.

/**
 * If this Component is focused, the pointer dragged event
 * will call this method
 *
 * @param x the pointer x coordinate
 * @param y the pointer y coordinate
 */
public void pointerDragged(final int x, final int y) {
    Form p = getComponentForm();
    if (p == null) {
        return;
    }
    if (pointerDraggedListeners != null && pointerDraggedListeners.hasListeners()) {
        pointerDraggedListeners.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerDrag, x, y));
    }
    if (dragAndDropInitialized) {
        // keep call to pointerDragged to move the parent scroll if needed
        if (dragCallbacks < 2) {
            dragCallbacks++;
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    if (dragActivated) {
                        pointerDragged(x, y);
                    }
                    dragCallbacks--;
                }
            });
        }
        if (!dragActivated) {
            dragActivated = true;
            setVisible(false);
            p.setDraggedComponent(this);
            oldx = x;
            oldy = y;
            draggedx = getAbsoluteX();
            draggedy = getAbsoluteY();
        }
        Component dropTo = findDropTarget(this, x, y);
        if (dropTo != null && dragOverListener != null) {
            ActionEvent ev = new ActionEvent(this, dropTo, x, y);
            dragOverListener.fireActionEvent(ev);
            if (ev.isConsumed()) {
                return;
            }
        }
        if (dropTargetComponent != dropTo) {
            if (dropTargetComponent != null) {
                dropTargetComponent.dragExit(this);
            }
            dropTargetComponent = dropTo;
            if (dropTargetComponent != null) {
                dropTargetComponent.dragEnter(this);
            }
        }
        // we repaint twice to create an intersection of the old and new position
        p.repaint(draggedx, draggedy, getWidth(), getHeight());
        draggedx = draggedx + (x - oldx);
        draggedy = draggedy + (y - oldy);
        oldx = x;
        oldy = y;
        p.repaint(draggedx, draggedy, getWidth(), getHeight());
        Container scrollParent = getParent();
        while (scrollParent != null && !scrollParent.isScrollable()) {
            scrollParent = scrollParent.getParent();
        }
        if (scrollParent != null) {
            Style s = getStyle();
            int w = getWidth() - s.getHorizontalPadding();
            int h = getHeight() - s.getVerticalPadding();
            Rectangle view;
            int invisibleAreaUnderVKB = getInvisibleAreaUnderVKB();
            view = new Rectangle(getScrollX(), getScrollY(), w, h - invisibleAreaUnderVKB);
            // if the dragging component is out of bounds move the scrollable parent
            if (!view.contains(draggedx - scrollParent.getAbsoluteX(), draggedy - scrollParent.getAbsoluteY(), getWidth(), getHeight())) {
                if ((scrollParent.isScrollableY() && scrollParent.getScrollY() >= 0 && scrollParent.getScrollY() + (draggedy + getHeight()) < scrollParent.getScrollDimension().getHeight()) || (scrollParent.isScrollableX() && scrollParent.getScrollX() >= 0 && scrollParent.getScrollX() + (draggedx + getWidth()) < scrollParent.getScrollDimension().getWidth())) {
                    int yposition = draggedy - scrollParent.getAbsoluteY() - 40;
                    if (yposition < 0) {
                        yposition = 0;
                    }
                    int xposition = draggedx - scrollParent.getAbsoluteX() - 40;
                    if (xposition < 0) {
                        xposition = 0;
                    }
                    int height = getHeight() + 80;
                    if (scrollParent.getScrollY() + draggedy + height >= scrollParent.getScrollDimension().getHeight()) {
                        yposition = draggedy - scrollParent.getAbsoluteY();
                        height = scrollParent.getScrollDimension().getHeight() - yposition;
                    }
                    int width = getWidth() + 80;
                    if (scrollParent.getScrollX() + draggedx + width >= scrollParent.getScrollDimension().getWidth()) {
                        xposition = draggedx - scrollParent.getAbsoluteX();
                        width = scrollParent.getScrollDimension().getWidth() - xposition;
                    }
                    scrollParent.scrollRectToVisible(xposition, yposition, width, height, scrollParent);
                }
            }
        }
        return;
    }
    if (dragActivated && p.getDraggedComponent() == null) {
        dragActivated = false;
    }
    if (!dragActivated) {
        boolean draggedOnX = Math.abs(p.initialPressX - x) > Math.abs(p.initialPressY - y);
        shouldGrabScrollEvents = (isScrollableX() && draggedOnX) || isScrollableY() && !draggedOnX;
    }
    if (isScrollable() && isSmoothScrolling() && shouldGrabScrollEvents) {
        if (!dragActivated) {
            dragActivated = true;
            lastScrollY = y;
            lastScrollX = x;
            p.setDraggedComponent(this);
            p.registerAnimatedInternal(this);
            Component fc = p.getFocused();
            if (fc != null && fc != this) {
                fc.dragInitiated();
            }
        }
        // and pulling it in the reverse direction of the drag
        if (isScrollableY()) {
            int tl;
            if (getTensileLength() > -1 && refreshTask == null) {
                tl = getTensileLength();
            } else {
                tl = getHeight() / 2;
            }
            if (!isSmoothScrolling() || !isTensileDragEnabled()) {
                tl = 0;
            }
            int scroll = getScrollY() + (lastScrollY - y);
            if (isAlwaysTensile() && getScrollDimension().getHeight() + getInvisibleAreaUnderVKB() <= getHeight()) {
                if (scroll >= -tl && scroll < getHeight() + tl) {
                    setScrollY(scroll);
                }
            } else {
                if (scroll >= -tl && scroll < getScrollDimension().getHeight() + getInvisibleAreaUnderVKB() - getHeight() + tl) {
                    setScrollY(scroll);
                }
            }
            updateTensileHighlightIntensity(lastScrollY, y, false);
        }
        if (isScrollableX()) {
            int tl;
            if (getTensileLength() > -1) {
                tl = getTensileLength();
            } else {
                tl = getWidth() / 2;
            }
            if (!isSmoothScrolling() || !isTensileDragEnabled()) {
                tl = 0;
            }
            int scroll = getScrollX() + (lastScrollX - x);
            if (scroll >= -tl && scroll < getScrollDimension().getWidth() - getWidth() + tl) {
                setScrollX(scroll);
            }
        }
        lastScrollY = y;
        lastScrollX = x;
    } else {
        // try to find a scrollable element until you reach the Form
        Component parent = getParent();
        if (!(parent instanceof Form)) {
            parent.pointerDragged(x, y);
        }
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Point(com.codename1.ui.geom.Point)

Example 39 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class Component method initComponentImpl.

/**
 * Invoked internally to initialize and bind the component
 */
void initComponentImpl() {
    if (!initialized) {
        initialized = true;
        UIManager manager = getUIManager();
        Style stl = getStyle();
        lockStyleImages(stl);
        manager.getLookAndFeel().bind(this);
        checkAnimation();
        if (isRTL() && isScrollableX()) {
            setScrollX(getScrollDimension().getWidth() - getWidth());
        }
        initComponent();
        showNativeOverlay();
    }
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style)

Example 40 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class Component method createStyleAnimation.

/**
 * Creates an animation that will transform the current component to the styling of the destination UIID when
 * completed. Notice that fonts will only animate within the truetype and native familiy and we recommend that you
 * don't shift weight/typeface/style as this might diminish the effect.<br>
 * <b>Important: </b> Only unselected styles are animated but once the animation completes all styles are applied.
 * @param destUIID the UIID to which this component will gradually shift
 * @param duration the duration of the animation or the number of steps
 * @return an animation component that can either be stepped or played
 */
public ComponentAnimation createStyleAnimation(final String destUIID, final int duration) {
    final Style sourceStyle = getUnselectedStyle();
    final Style destStyle = hasInlineUnselectedStyle() ? getUIManager().parseComponentStyle(getInlineStylesTheme(), destUIID, getInlineStylesUIID(destUIID), getInlineUnselectedStyleStrings()) : getUIManager().getComponentStyle(destUIID);
    return createStyleAnimation(sourceStyle, destStyle, duration, destUIID);
}
Also used : Style(com.codename1.ui.plaf.Style)

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