Search in sources :

Example 36 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class RSSReader method sendRequest.

/**
 * Send the request to the server, will only work once. This is called implicitly
 * when the list is initialized
 */
public void sendRequest() {
    if (service == null) {
        service = new RSSService(url, limit);
        if (iconPlaceholder != null) {
            service.setIconPlaceholder(iconPlaceholder);
        }
        service.addResponseListener(new EventHandler());
        if (blockList) {
            Progress p = new Progress(progressTitle, service, displayProgressPercentage);
            p.setAutoShow(true);
            p.setDisposeOnCompletion(true);
        }
        setHint(progressTitle);
        NetworkManager.getInstance().addToQueue(service);
    }
}
Also used : RSSService(com.codename1.io.services.RSSService)

Example 37 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class AbstractChart method split.

private static String[] split(String input, String sep) {
    if (sep.length() > 1) {
        int clen = stopCharCandidates.length;
        for (int i = 0; i < clen; i++) {
            if (input.indexOf(stopCharCandidates[i]) == -1) {
                input = com.codename1.util.StringUtil.replaceAll(input, sep, String.valueOf(stopCharCandidates[i]));
                sep = String.valueOf(stopCharCandidates[i]);
            }
        }
    }
    if (sep.length() > 1) {
        throw new RuntimeException("Failed to find appropriate stop character");
    }
    List<String> parts = com.codename1.util.StringUtil.tokenize(input, sep);
    String[] out = new String[parts.size()];
    return parts.toArray(out);
}
Also used : Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 38 with List

use of com.codename1.ui.List 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 39 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class AbstractChart method drawLabel.

/**
 * Draws a text label.
 *
 * @param canvas the canvas
 * @param labelText the label text
 * @param renderer the renderer
 * @param prevLabelsBounds the previous rendered label bounds
 * @param centerX the round chart center on X axis
 * @param centerY the round chart center on Y axis
 * @param shortRadius the short radius for the round chart
 * @param longRadius the long radius for the round chart
 * @param currentAngle the current angle
 * @param angle the label extra angle
 * @param left the left side
 * @param right the right side
 * @param color the label color
 * @param paint the paint
 * @param line if a line to the label should be drawn
 * @param display display the label anyway
 */
protected void drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<Rectangle2D> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display) {
    if (renderer.isShowLabels() || display) {
        paint.setColor(color);
        double rAngle = Math.toRadians(90 - (currentAngle + angle / 2));
        double sinValue = Math.sin(rAngle);
        double cosValue = Math.cos(rAngle);
        int x1 = Math.round(centerX + (float) (shortRadius * sinValue));
        int y1 = Math.round(centerY + (float) (shortRadius * cosValue));
        int x2 = Math.round(centerX + (float) (longRadius * sinValue));
        int y2 = Math.round(centerY + (float) (longRadius * cosValue));
        float size = renderer.getLabelsTextSize();
        float extra = Math.max(size / 2, 10);
        paint.setTextAlign(Component.LEFT);
        if (x1 > x2) {
            extra = -extra;
            paint.setTextAlign(Component.RIGHT);
        }
        float xLabel = x2 + extra;
        float yLabel = y2;
        float width = right - xLabel;
        if (x1 > x2) {
            width = xLabel - left;
        }
        labelText = getFitText(labelText, width, paint);
        float widthLabel = paint.measureText(labelText);
        boolean okBounds = false;
        while (!okBounds && line) {
            boolean intersects = false;
            int length = prevLabelsBounds.size();
            for (int j = 0; j < length && !intersects; j++) {
                Rectangle2D prevLabelBounds = prevLabelsBounds.get(j);
                if (prevLabelBounds.intersects(xLabel, yLabel, widthLabel, size)) {
                    intersects = true;
                    yLabel = (float) Math.max(yLabel, prevLabelBounds.getY() + prevLabelBounds.getHeight());
                }
            }
            okBounds = !intersects;
        }
        if (line) {
            y2 = (int) (yLabel - size / 2);
            canvas.drawLine(x1, y1, x2, y2, paint);
            canvas.drawLine(x2, y2, x2 + extra, y2, paint);
        } else {
            paint.setTextAlign(Component.CENTER);
        }
        canvas.drawText(labelText, xLabel, yLabel, paint);
        if (line) {
            prevLabelsBounds.add(PkgUtils.makeRect(xLabel, yLabel, xLabel + widthLabel, yLabel + size));
        }
    }
}
Also used : Rectangle2D(com.codename1.ui.geom.Rectangle2D) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 40 with List

use of com.codename1.ui.List in project CodenameOne by codenameone.

the class BubbleChart 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 renderer, float yAxisValue, int seriesIndex, int startIndex) {
    paint.setColor(renderer.getColor());
    paint.setStyle(Style.FILL);
    int length = points.size();
    XYValueSeries series = (XYValueSeries) mDataset.getSeriesAt(seriesIndex);
    double max = series.getMaxValue();
    double coef = MAX_BUBBLE_SIZE / max;
    for (int i = 0; i < length; i += 2) {
        double size = series.getValue(startIndex + i / 2) * coef + MIN_BUBBLE_SIZE;
        drawCircle(canvas, paint, points.get(i), points.get(i + 1), (float) size);
    }
}
Also used : Paint(com.codename1.charts.compat.Paint) XYValueSeries(com.codename1.charts.models.XYValueSeries)

Aggregations

Paint (com.codename1.charts.compat.Paint)26 ArrayList (java.util.ArrayList)24 Component (com.codename1.ui.Component)16 List (com.codename1.ui.List)13 Point (com.codename1.charts.models.Point)11 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 Hashtable (java.util.Hashtable)11 Container (com.codename1.ui.Container)9 ContainerList (com.codename1.ui.list.ContainerList)9 Button (com.codename1.ui.Button)8 List (java.util.List)8 TextArea (com.codename1.ui.TextArea)7 Dimension (com.codename1.ui.geom.Dimension)7 EncodedImage (com.codename1.ui.EncodedImage)6 Label (com.codename1.ui.Label)6 RadioButton (com.codename1.ui.RadioButton)5 ActionListener (com.codename1.ui.events.ActionListener)5 JList (javax.swing.JList)4 FileEncodedImage (com.codename1.components.FileEncodedImage)3 StorageImage (com.codename1.components.StorageImage)3