Search in sources :

Example 1 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class DefaultLookAndFeel method drawTextField.

/**
 * {@inheritDoc}
 */
public void drawTextField(Graphics g, TextArea ta) {
    setFG(g, ta);
    // display ******** if it is a password field
    String displayText = getTextFieldString(ta);
    Style style = ta.getStyle();
    int x = 0;
    // ta.getCursorX();
    int cursorCharPosition = ta.getCursorPosition();
    Font f = style.getFont();
    int cursorX = 0;
    int xPos = 0;
    int align = reverseAlignForBidi(ta);
    int displayX = 0;
    String inputMode = ta.getInputMode();
    int inputModeWidth = f.stringWidth(inputMode);
    // QWERTY devices don't quite have an input mode hide it also when we have a VK
    if (ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) {
        inputMode = "";
        inputModeWidth = 0;
    }
    if (ta.isSingleLineTextArea()) {
        // there is currently no support for CENTER aligned text fields
        if (align == Component.LEFT) {
            if (cursorCharPosition > 0) {
                cursorCharPosition = Math.min(displayText.length(), cursorCharPosition);
                xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
                cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
                // no point in showing the input mode when there is only one input mode...
                if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length == 1) {
                    inputModeWidth = 0;
                }
                if (ta.isEnableInputScroll()) {
                    if (ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL())) {
                        if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2) {
                            x = ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2 - xPos - 1;
                        }
                    }
                }
            }
            displayX = ta.getX() + x + style.getPaddingLeft(ta.isRTL());
        } else {
            x = 0;
            cursorX = getTextFieldCursorX(ta);
            int baseX = ta.getX() + style.getPaddingLeftNoRTL() + inputModeWidth;
            int endX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL();
            if (cursorX < baseX) {
                x = baseX - cursorX;
            } else {
                if (cursorX > endX) {
                    x = endX - cursorX;
                }
            }
            displayX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL() - f.stringWidth(displayText) + x;
        }
        int cx = g.getClipX();
        int cy = g.getClipY();
        int cw = g.getClipWidth();
        int ch = g.getClipHeight();
        int clipx = ta.getX() + style.getPaddingLeft(ta.isRTL());
        int clipw = ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - style.getPaddingRight(ta.isRTL());
        // g.pushClip();
        g.clipRect(clipx, cy, clipw, ch);
        switch(ta.getVerticalAlignment()) {
            case Component.BOTTOM:
                g.drawString(displayText, displayX, ta.getY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight(), style.getTextDecoration());
                break;
            case Component.CENTER:
                g.drawString(displayText, displayX, ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2, style.getTextDecoration());
                break;
            default:
                g.drawString(displayText, displayX, ta.getY() + style.getPaddingTop(), style.getTextDecoration());
                break;
        }
        g.setClip(cx, cy, cw, ch);
    // g.popClip();
    } else {
        drawTextArea(g, ta);
    }
    // no point in showing the input mode when there is only one input mode...
    if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length > 1) {
        if (ta.handlesInput() && ta.getWidth() / 2 > inputModeWidth) {
            int drawXPos = ta.getX() + style.getPaddingLeft(ta.isRTL());
            if ((!ta.isRTL() && style.getAlignment() == Component.LEFT) || (ta.isRTL() && style.getAlignment() == Component.RIGHT)) {
                drawXPos = drawXPos + ta.getWidth() - inputModeWidth - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL();
            }
            g.setColor(style.getFgColor());
            int inputIndicatorY = ta.getY() + ta.getScrollY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight();
            g.fillRect(drawXPos, inputIndicatorY, inputModeWidth, f.getHeight(), (byte) 140);
            g.setColor(style.getBgColor());
            g.drawString(inputMode, drawXPos, inputIndicatorY);
        }
    }
}
Also used : Font(com.codename1.ui.Font)

Example 2 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class LazyValueC method postCreateComponents.

/**
 * Invoked after the components were created to allow properties that require the entire
 * tree to exist to update the component. This is useful for properties that point
 * at other components.
 */
private void postCreateComponents(DataInputStream in, Container parent, Resources res) throws Exception {
    // finds the component whose properties need to update
    String name = in.readUTF();
    Component lastComponent = null;
    while (name.length() > 0) {
        if (lastComponent == null || !lastComponent.getName().equals(name)) {
            lastComponent = findByName(name, parent);
        }
        Component c = lastComponent;
        int property = in.readInt();
        modifyingProperty(c, property);
        switch(property) {
            case PROPERTY_COMMAND_LEGACY:
                {
                    readCommand(in, c, parent, res, true);
                    break;
                }
            case PROPERTY_COMMAND:
                {
                    readCommand(in, c, parent, res, false);
                    break;
                }
            case PROPERTY_LABEL_FOR:
                c.setLabelForComponent((Label) findByName(in.readUTF(), parent));
                break;
            case PROPERTY_LEAD_COMPONENT:
                ((Container) c).setLeadComponent(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_UP:
                c.setNextFocusUp(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_DOWN:
                c.setNextFocusDown(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_LEFT:
                c.setNextFocusLeft(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_RIGHT:
                c.setNextFocusRight(findByName(in.readUTF(), parent));
                break;
        }
        name = in.readUTF();
    }
}
Also used : Container(com.codename1.ui.Container) Component(com.codename1.ui.Component)

Example 3 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class ArrowLinesLayer method paintSegment.

/**
 * Paints arrows on each segment. arrowSegmentLength decides how many
 * arrows will be on each segment.
 * @param g
 * @param segment
 * @param tile
 */
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
    super.paintSegment(g, segment, tile);
    int pointsNo = segment.length;
    for (int i = 1; i < pointsNo; i++) {
        Coord start = segment[i - 1];
        Coord end = segment[i];
        Point s = tile.pointPosition(start);
        Point e = tile.pointPosition(end);
        int noOfSegments = calculateLength(s, e) / arrowSegmentLength;
        if (noOfSegments == 0 && calculateLength(s, e) > minArrowSementLength) {
            noOfSegments = 1;
        }
        for (int j = 1; j <= noOfSegments; j++) {
            if (j == 1) {
                double div = 1.0 / noOfSegments;
                drawArrow(g, new Point(s.getX(), s.getY()), new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))));
            } else if (j == noOfSegments) {
                double div = (noOfSegments - 1) / (noOfSegments * 1.0);
                drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point(e.getX(), e.getY()));
            } else {
                double div = ((j - 1) * 1.0) / noOfSegments;
                double div2 = (j * 1.0) / noOfSegments;
                drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point((int) (div2 * e.getX() + s.getX() * (1 - div2)), (int) (div2 * e.getY() + s.getY() * (1 - div2))));
            }
        }
    }
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point) Point(com.codename1.ui.geom.Point)

Example 4 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class LinesLayer method paintSegment.

/**
 * Paint a segment.
 *
 * @param g a Graphics Object to paint on
 * @param segment array of Coord to draw a Line.
 * @param tile
 */
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
    int pointsNo = segment.length;
    for (int i = 1; i < pointsNo; i++) {
        Coord start = (Coord) segment[i - 1];
        Coord end = (Coord) segment[i];
        Point s = tile.pointPosition(start);
        Point e = tile.pointPosition(end);
        g.drawLine(s.getX(), s.getY(), e.getX(), e.getY());
        // lame & simple way to make line thicker
        g.drawLine(s.getX() - 1, s.getY(), e.getX() - 1, e.getY());
        g.drawLine(s.getX() + 1, s.getY(), e.getX() + 1, e.getY());
        g.drawLine(s.getX(), s.getY() - 1, e.getX(), e.getY() - 1);
        g.drawLine(s.getX(), s.getY() + 1, e.getX(), e.getY() + 1);
    }
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point) Point(com.codename1.ui.geom.Point)

Example 5 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class PointsLayer method addPoint.

/**
 * Adds a point to the PointsLayer
 *
 * @param point a point to add
 */
public void addPoint(PointLayer point) {
    Image pointIcon = point.getIcon();
    if (pointIcon == null) {
        point.setIcon(icon);
    }
    if (!point.isProjected()) {
        Coord c = getProjection().fromWGS84(point);
        point.setLatitude(c.getLatitude());
        point.setLongitude(c.getLongitude());
        point.setProjected(true);
    }
    points.addElement(point);
}
Also used : Coord(com.codename1.maps.Coord) Image(com.codename1.ui.Image)

Aggregations

Point (com.codename1.ui.geom.Point)11 Point (com.codename1.charts.models.Point)10 Coord (com.codename1.maps.Coord)9 Paint (com.codename1.charts.compat.Paint)7 Component (com.codename1.ui.Component)5 TextArea (com.codename1.ui.TextArea)3 Dimension (com.codename1.ui.geom.Dimension)3 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Rectangle (com.codename1.ui.geom.Rectangle)3 Border (com.codename1.ui.plaf.Border)3 ArrayList (java.util.ArrayList)3 SeriesSelection (com.codename1.charts.models.SeriesSelection)2 Container (com.codename1.ui.Container)2 EncodedImage (com.codename1.ui.EncodedImage)2 Form (com.codename1.ui.Form)2 Image (com.codename1.ui.Image)2 Label (com.codename1.ui.Label)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 Style (com.codename1.ui.plaf.Style)2