Search in sources :

Example 16 with Point

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

the class ChartComponent method pointerPressed.

@Override
public void pointerPressed(int x, int y) {
    Point chartCoord = screenToChartCoord(x, y);
    SeriesSelection sel = chart.getSeriesAndPointForScreenCoordinate(chartCoord);
    if (sel == null) {
        super.pointerPressed(x, y);
        return;
    }
    seriesPressed(sel);
    // To change body of generated methods, choose Tools | Templates.
    super.pointerPressed(x, y);
}
Also used : SeriesSelection(com.codename1.charts.models.SeriesSelection) Point(com.codename1.charts.models.Point)

Example 17 with Point

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

the class AbstractChart method drawPath.

/**
 * The graphical representation of a path.
 *
 * @param canvas the canvas to paint to
 * @param points the points that are contained in the path to paint
 * @param paint the paint to be used for painting
 * @param circular if the path ends with the start point
 */
protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular) {
    GeneralPath path = new GeneralPath();
    int height = canvas.getHeight();
    int width = canvas.getWidth();
    float[] tempDrawPoints;
    if (points.size() < 4) {
        return;
    }
    tempDrawPoints = calculateDrawPoints(points.get(0), points.get(1), points.get(2), points.get(3), height, width);
    path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
    path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    int length = points.size();
    for (int i = 4; i < length; i += 2) {
        if ((points.get(i - 1) < 0 && points.get(i + 1) < 0) || (points.get(i - 1) > height && points.get(i + 1) > height)) {
            continue;
        }
        tempDrawPoints = calculateDrawPoints(points.get(i - 2), points.get(i - 1), points.get(i), points.get(i + 1), height, width);
        if (!circular) {
            path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
        }
        path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    }
    if (circular) {
        path.lineTo(points.get(0), points.get(1));
    }
    canvas.drawPath(path, paint);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 18 with Point

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

the class AbstractChart method drawPath.

/**
 * The graphical representation of a path.
 *
 * @param canvas the canvas to paint to
 * @param points the points that are contained in the path to paint
 * @param paint the paint to be used for painting
 * @param circular if the path ends with the start point
 */
protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular) {
    GeneralPath path = new GeneralPath();
    int height = canvas.getHeight();
    int width = canvas.getWidth();
    float[] tempDrawPoints;
    if (points.length < 4) {
        return;
    }
    tempDrawPoints = calculateDrawPoints(points[0], points[1], points[2], points[3], height, width);
    path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
    path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    int length = points.length;
    for (int i = 4; i < length; i += 2) {
        if ((points[i - 1] < 0 && points[i + 1] < 0) || (points[i - 1] > height && points[i + 1] > height)) {
            continue;
        }
        tempDrawPoints = calculateDrawPoints(points[i - 2], points[i - 1], points[i], points[i + 1], height, width);
        if (!circular) {
            path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
        }
        path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    }
    if (circular) {
        path.lineTo(points[0], points[1]);
    }
    canvas.drawPath(path, paint);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 19 with Point

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

the class BarChart method drawSeries.

/**
 * The graphical representation of a series.
 *
 * @param canvas the canvas to paint to
 * @param paint the paint to be used for drawing
 * @param points the array of points to be used for drawing the series
 * @param seriesRenderer the series renderer
 * @param yAxisValue the minimum value of the y axis
 * @param seriesIndex the index of the series currently being drawn
 * @param startIndex the start index of the rendering points
 */
@Override
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {
    int seriesNr = mDataset.getSeriesCount();
    int length = points.size();
    paint.setColor(seriesRenderer.getColor());
    paint.setStyle(Style.FILL);
    float halfDiffX = getHalfDiffX(points, length, seriesNr);
    Point[] yvals = new Point[length / 2];
    for (int i = 0; i < length; i += 2) {
        Point p = new Point();
        p.seriesIndex = i / 2;
        p.yval = points.get(i + 1);
        yvals[i / 2] = p;
    }
    for (int i = 0; i < length; i += 2) {
        float x = points.get(i);
        float y = points.get(i + 1);
        if (mType == Type.HEAPED && seriesIndex > 0) {
            float lastY = mPreviousSeriesPoints.get(i + 1);
            y = y + (lastY - yAxisValue);
            points.set(i + 1, y);
            drawBar(canvas, x, lastY, x, y, halfDiffX, seriesNr, seriesIndex, paint);
        } else {
            drawBar(canvas, x, yAxisValue, x, y, halfDiffX, seriesNr, seriesIndex, paint);
        }
    }
    paint.setColor(seriesRenderer.getColor());
    mPreviousSeriesPoints = points;
}
Also used : Paint(com.codename1.charts.compat.Paint)

Example 20 with Point

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

the class Dialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param rect the screen rectangle to which the popup should point
 * @return the command that might have been triggered by the user within the dialog if commands are placed in the dialog
 */
public Command showPopupDialog(Rectangle rect) {
    if (getDialogUIID().equals("Dialog")) {
        setDialogUIID("PopupDialog");
        if (getTitleComponent().getUIID().equals("DialogTitle")) {
            getTitleComponent().setUIID("PopupDialogTitle");
        }
        getContentPane().setUIID("PopupContentPane");
    }
    disposeOnRotation = true;
    disposeWhenPointerOutOfBounds = true;
    Command backCommand = null;
    if (getBackCommand() == null) {
        backCommand = new Command("Back");
        setBackCommand(backCommand);
    }
    Component contentPane = super.getContentPane();
    Label title = super.getTitleComponent();
    int menuHeight = calcMenuHeight();
    UIManager manager = getUIManager();
    // preferred size logic of the dialog won't work with large title borders
    if (dialogTitle != null && manager.isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        getTitleArea().setVisible(b);
        getTitleComponent().setVisible(b);
        if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
            getTitleComponent().setPreferredSize(new Dimension(0, 0));
            getTitleComponent().getStyle().setBorder(null);
            getTitleArea().setPreferredSize(new Dimension(0, 0));
            if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
                getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
                int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
                int titlePT = getTitleComponent().getStyle().getPaddingTop();
                byte[] pu = getContentPane().getStyle().getPaddingUnit();
                if (pu == null) {
                    pu = new byte[4];
                }
                pu[0] = Style.UNIT_TYPE_PIXELS;
                getContentPane().getStyle().setPaddingUnit(pu);
                int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
                getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
            }
        }
    }
    // allows a text area to recalculate its preferred size if embedded within a dialog
    revalidate();
    Style contentPaneStyle = getDialogStyle();
    boolean restoreArrow = false;
    if (manager.isThemeConstant(getDialogUIID() + "ArrowBool", false)) {
        Image t = manager.getThemeImageConstant(getDialogUIID() + "ArrowTopImage");
        Image b = manager.getThemeImageConstant(getDialogUIID() + "ArrowBottomImage");
        Image l = manager.getThemeImageConstant(getDialogUIID() + "ArrowLeftImage");
        Image r = manager.getThemeImageConstant(getDialogUIID() + "ArrowRightImage");
        Border border = contentPaneStyle.getBorder();
        if (border != null) {
            border.setImageBorderSpecialTile(t, b, l, r, rect);
            restoreArrow = true;
        }
    }
    int prefHeight = contentPane.getPreferredH();
    int prefWidth = contentPane.getPreferredW();
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    prefWidth += getUIManager().getLookAndFeel().getVerticalScrollWidth();
    int availableHeight = Display.getInstance().getDisplayHeight() - menuHeight - title.getPreferredH();
    int availableWidth = Display.getInstance().getDisplayWidth();
    int width = Math.min(availableWidth, prefWidth);
    int x = 0;
    int y = 0;
    Command result;
    boolean showPortrait;
    if (popupDirectionBiasPortrait != null) {
        showPortrait = popupDirectionBiasPortrait.booleanValue();
    } else {
        showPortrait = Display.getInstance().isPortrait();
    }
    // if we don't have enough space then disregard device orientation
    if (showPortrait) {
        if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
            showPortrait = false;
        }
    } else {
        if (availableHeight / 2 > availableWidth - rect.getWidth()) {
            showPortrait = true;
        }
    }
    if (showPortrait) {
        if (width < availableWidth) {
            int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealX > 0) {
                // if the idealX is too far to the right just align to the right
                if (idealX + width > availableWidth) {
                    x = availableWidth - width;
                } else {
                    x = idealX;
                }
            }
        }
        if (rect.getY() < availableHeight / 2) {
            // popup downwards
            y = rect.getY() + rect.getSize().getHeight();
            int height = Math.min(prefHeight, availableHeight - y);
            result = show(y, availableHeight - height - y, x, availableWidth - width - x, true, true);
        } else {
            // popup upwards
            int height = Math.min(prefHeight, availableHeight - (availableHeight - rect.getY()));
            y = rect.getY() - height;
            result = show(y, availableHeight - height - y, x, availableWidth - width - x, true, true);
        }
    } else {
        int height = Math.min(prefHeight, availableHeight);
        if (height < availableHeight) {
            int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealY > 0) {
                // if the idealY is too far up just align to the top
                if (idealY + height > availableHeight) {
                    y = availableHeight - height;
                } else {
                    y = idealY;
                }
            }
        }
        if (prefWidth > rect.getX()) {
            // popup right
            x = rect.getX() + rect.getSize().getWidth();
            if (x + prefWidth > availableWidth) {
                x = availableWidth - prefWidth;
            }
            width = Math.min(prefWidth, availableWidth - x);
            result = show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x), true, true);
        } else {
            // popup left
            width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
            x = rect.getX() - width;
            result = show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x), true, true);
        }
    }
    if (restoreArrow) {
        contentPaneStyle.getBorder().clearImageBorderSpecialTile();
    }
    if (result == backCommand) {
        return null;
    }
    return result;
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Border(com.codename1.ui.plaf.Border)

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