Search in sources :

Example 51 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class List method getSelectedRect.

/**
 * {@inheritDoc}
 */
public Rectangle getSelectedRect() {
    Style style = getStyle();
    Rectangle pos = new Rectangle();
    int width = getWidth() - style.getHorizontalPadding() - getSideGap();
    Dimension rendererSize = getElementSize(false, true);
    calculateComponentPosition(getSelectedIndex(), width, pos, rendererSize, getElementSize(true, true), true);
    pos.setX(pos.getX() + getParent().getAbsoluteX());
    pos.setY(pos.getY() + getParent().getAbsoluteY());
    return pos;
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 52 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class List method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    getUIManager().getLookAndFeel().drawList(g, this);
    Style style = getStyle();
    int width = getWidth() - style.getHorizontalPadding() - getSideGap();
    if (isScrollableX()) {
        width = Math.max(width, getScrollDimension().getWidth() - style.getHorizontalPadding() - getSideGap());
    }
    int numOfcomponents = model.getSize();
    if (numOfcomponents == 0) {
        paintHint(g);
        return;
    }
    int xTranslate = getX();
    int yTranslate = getY();
    g.translate(xTranslate, yTranslate);
    Rectangle pos = new Rectangle();
    Dimension rendererSize = getElementSize(false, true);
    if (fixedSelection > FIXED_NONE_BOUNDRY) {
        if (animationPosition != 0 || isDragActivated()) {
            if (orientation != HORIZONTAL) {
                yTranslate += (animationPosition + fixedDraggedAnimationPosition);
                g.translate(0, animationPosition + fixedDraggedAnimationPosition);
            } else {
                xTranslate += (animationPosition + fixedDraggedAnimationPosition);
                g.translate(animationPosition + fixedDraggedAnimationPosition, 0);
            }
        }
    }
    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipWidth = g.getClipWidth();
    int clipHeight = g.getClipHeight();
    // this flag is for preformance improvements
    // if we figured out that the list items are not visible anymore
    // we should break from the List loop
    boolean shouldBreak = false;
    // improve performance for browsing the end of a very large list
    int startingPoint = 0;
    if (fixedSelection < FIXED_NONE_BOUNDRY) {
        int startX = clipX + getAbsoluteX();
        if (isRTL()) {
            // In RTL the start of the list is not in the left side of the viewport, but rather the right side
            startX += getWidth();
        }
        startingPoint = Math.max(0, pointerSelect(startX, clipY + getAbsoluteY()) - 1);
    }
    int startOffset = 0;
    int endOffset = numOfcomponents;
    if (mutableRendererBackgrounds) {
        for (int i = startingPoint; i < numOfcomponents; i++) {
            // skip on the selected
            if (i == getCurrentSelected() && animationPosition == 0 && fixedDraggedAnimationPosition == 0) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                shouldBreak = true;
                continue;
            }
            calculateComponentPosition(i, width, pos, rendererSize, getElementSize(true, true), i <= getCurrentSelected());
            // if the renderer is in the clipping region
            if (pos.intersects(clipX, clipY, clipWidth, clipHeight)) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                Dimension size = pos.getSize();
                Component selectionCmp = renderer.getListCellRendererComponent(this, getModel().getItemAt(i), i, i == getCurrentSelected());
                renderComponentBackground(g, selectionCmp, pos.getX(), pos.getY(), size.getWidth(), size.getHeight());
                shouldBreak = true;
            } else {
                // this is relevant only if the List is not fixed.
                if (shouldBreak && (fixedSelection < FIXED_NONE_BOUNDRY)) {
                    break;
                }
            }
        }
    } else {
        T valueAt0 = getModel().getItemAt(0);
        Component selectionCmp;
        int selectedIndex = getSelectedIndex();
        if (selectedIndex > -1 && selectedIndex < numOfcomponents) {
            // this is essential otherwise we constantly ticker based on the value of the first entry
            selectionCmp = renderer.getListCellRendererComponent(this, getModel().getItemAt(selectedIndex), 0, true);
        } else {
            selectionCmp = renderer.getListCellRendererComponent(this, valueAt0, 0, true);
        }
        Component unselectedCmp = renderer.getListCellRendererComponent(this, valueAt0, 0, false);
        for (int i = startingPoint; i < numOfcomponents; i++) {
            // skip on the selected
            if (i == getCurrentSelected() && animationPosition == 0) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                shouldBreak = true;
                continue;
            }
            calculateComponentPosition(i, width, pos, rendererSize, getElementSize(true, true), i <= getCurrentSelected());
            // if the renderer is in the clipping region
            if (pos.intersects(clipX, clipY, clipWidth, clipHeight)) {
                if (!shouldBreak) {
                    startOffset = i;
                }
                endOffset = i;
                if (i == getCurrentSelected()) {
                    Dimension size = pos.getSize();
                    renderComponentBackground(g, selectionCmp, pos.getX(), pos.getY(), size.getWidth(), size.getHeight());
                } else {
                    Dimension size = pos.getSize();
                    renderComponentBackground(g, unselectedCmp, pos.getX(), pos.getY(), size.getWidth(), size.getHeight());
                }
                shouldBreak = true;
            } else {
                // this is relevant only if the List is not fixed.
                if (shouldBreak && (fixedSelection < FIXED_NONE_BOUNDRY)) {
                    break;
                }
            }
        }
    }
    boolean shouldRendererSelectedEntry = (renderer.getListFocusComponent(this) == null && (fixedSelection < FIXED_NONE_BOUNDRY)) || animationPosition == 0 && model.getSize() > 0;
    Rectangle selectedPos = new Rectangle();
    calculateComponentPosition(getCurrentSelected(), width, selectedPos, rendererSize, getElementSize(true, true), true);
    Dimension size = selectedPos.getSize();
    int curSel = getCurrentSelected();
    if (shouldRendererSelectedEntry && curSel > -1 && curSel < model.getSize()) {
        Component selected = renderer.getListCellRendererComponent(this, model.getItemAt(getCurrentSelected()), getCurrentSelected(), true);
        renderComponentBackground(g, selected, selectedPos.getX(), selectedPos.getY(), size.getWidth(), size.getHeight());
    }
    if (paintFocusBehindList) {
        paintFocus(g, width, pos, rendererSize);
    }
    for (int i = startOffset; i <= endOffset; i++) {
        // skip on the selected
        if (i == getCurrentSelected() && animationPosition == 0) {
            continue;
        }
        calculateComponentPosition(i, width, pos, rendererSize, getElementSize(true, true), i <= getCurrentSelected());
        if (pos.intersects(clipX, clipY, clipWidth, clipHeight)) {
            T value = model.getItemAt(i);
            Component cmp = renderer.getListCellRendererComponent(this, value, i, false);
            cmp.setCellRenderer(true);
            Dimension sizeC = pos.getSize();
            renderComponent(g, cmp, pos.getX(), pos.getY(), sizeC.getWidth(), sizeC.getHeight());
        }
    }
    // if the animation has finished draw the selected element
    if (shouldRendererSelectedEntry) {
        Component selected = renderer.getListCellRendererComponent(this, model.getItemAt(getCurrentSelected()), getCurrentSelected(), true);
        renderComponent(g, selected, selectedPos.getX(), selectedPos.getY(), size.getWidth(), size.getHeight());
    }
    if (!paintFocusBehindList) {
        paintFocus(g, width, pos, rendererSize);
    }
    g.translate(-xTranslate, -yTranslate);
    if (spinnerOverlay != null) {
        if (spinnerOverlay.getBorder() != null) {
            spinnerOverlay.getBorder().paintBorderBackground(g, this);
            spinnerOverlay.getBorder().paint(g, this);
        } else {
            spinnerOverlay.getBgPainter().paint(g, getBounds());
        }
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 53 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class Form method createStatusBar.

/**
 * Subclasses can override this method to control the creation of the status bar component.
 * Notice that this method will only be invoked if the paintsTitleBarBool theme constant is true
 * which it is on iOS by default
 * @return a Component that represents the status bar if the OS requires status bar spacing
 */
protected Component createStatusBar() {
    if (getUIManager().isThemeConstant("statusBarScrollsUpBool", true)) {
        Button bar = new Button();
        bar.setShowEvenIfBlank(true);
        bar.setUIID("StatusBar");
        bar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                Component c = findScrollableChild(getContentPane());
                if (c != null) {
                    c.scrollRectToVisible(new Rectangle(0, 0, 10, 10), c);
                }
            }
        });
        return bar;
    } else {
        Container bar = new Container();
        bar.setUIID("StatusBar");
        return bar;
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Rectangle(com.codename1.ui.geom.Rectangle)

Example 54 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class SideMenuBar method setMenuGlassPane.

private void setMenuGlassPane(Form m, final String placement) {
    boolean isRTLValue = m.isRTL();
    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
        isRTLValue = !isRTLValue;
    }
    final boolean isRTL = isRTLValue;
    final Image image = rightPanel.getStyle().getBgImage();
    UIManager uim = rightPanel.getUIManager();
    Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
    if (sh == null) {
        sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
    }
    if (isRTL) {
        sh = sh.flipHorizontally(true);
    }
    final Image shadow = sh;
    if (m.getGlassPane() == null) {
        m.setGlassPane(new Painter() {

            Image img = image;

            public void paint(Graphics g, Rectangle rect) {
                if (img == null) {
                    // will happen for areMutableImagesFast returning false on iOS and Windows Phone
                    Component c = (Component) rightPanel.getClientProperty("$parent");
                    // not sure what is happening here
                    if (c == null) {
                        return;
                    }
                    boolean b = c.isVisible();
                    c.setVisible(true);
                    if (isRTL) {
                        int x = Math.max(draggedX, rightPanel.getWidth()) - c.getWidth();
                        g.translate(x, 0);
                        Container.sidemenuBarTranslation = x;
                        if (shadow != null) {
                            g.tileImage(shadow, x + c.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        c.paintComponent(g, true);
                        Container.sidemenuBarTranslation = 0;
                        g.translate(-x, 0);
                    } else {
                        int x = Math.min(draggedX, rightPanel.getX());
                        g.translate(x, 0);
                        Container.sidemenuBarTranslation = x;
                        if (shadow != null) {
                            g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        c.paintComponent(g, true);
                        Container.sidemenuBarTranslation = 0;
                        g.translate(-x, 0);
                    }
                    c.setVisible(b);
                } else {
                    if (Display.getInstance().areMutableImagesFast()) {
                        if (img.getHeight() != Display.getInstance().getDisplayHeight()) {
                            img = updateRightPanelBgImage(placement, parent);
                        }
                    }
                    if (isRTL) {
                        int x = Math.max(draggedX, rightPanel.getWidth()) - img.getWidth();
                        if (shadow != null) {
                            g.tileImage(shadow, x + img.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        g.drawImage(img, x, 0);
                    } else {
                        int x = Math.min(draggedX, rightPanel.getX());
                        if (shadow != null) {
                            g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        g.drawImage(img, x, 0);
                    }
                }
            }
        });
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) UIManager(com.codename1.ui.plaf.UIManager)

Example 55 with Rectangle

use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.

the class HTMLImageMap method actionPerformed.

public void actionPerformed(ActionEvent evt) {
    if (mapData != null) {
        int x = evt.getX();
        int y = evt.getY();
        if ((mapData.areas != null) && (x != -1)) {
            for (Enumeration e = mapData.areas.keys(); e.hasMoreElements(); ) {
                Rectangle rect = (Rectangle) e.nextElement();
                if (rect.contains(x - getAbsoluteX(), y - getAbsoluteY())) {
                    String link = (String) mapData.areas.get(rect);
                    if (link != null) {
                        HTMLLink.processLink(htmlC, link);
                    }
                    return;
                }
            }
        }
        if (mapData.defaultLink != null) {
            HTMLLink.processLink(htmlC, mapData.defaultLink);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Rectangle(com.codename1.ui.geom.Rectangle)

Aggregations

Rectangle (com.codename1.ui.geom.Rectangle)41 Dimension (com.codename1.ui.geom.Dimension)16 Style (com.codename1.ui.plaf.Style)13 Image (com.codename1.ui.Image)10 ActionEvent (com.codename1.ui.events.ActionEvent)5 Border (com.codename1.ui.plaf.Border)5 Component (com.codename1.ui.Component)4 Graphics (com.codename1.ui.Graphics)4 UIManager (com.codename1.ui.plaf.UIManager)4 Form (com.codename1.ui.Form)3 Label (com.codename1.ui.Label)3 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Paint (com.codename1.charts.compat.Paint)2 Button (com.codename1.ui.Button)2 EncodedImage (com.codename1.ui.EncodedImage)2 Painter (com.codename1.ui.Painter)2 ActionListener (com.codename1.ui.events.ActionListener)2 RoundBorder (com.codename1.ui.plaf.RoundBorder)2