Search in sources :

Example 61 with List

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

the class XYChart method drawXLabels.

/**
 * The graphical representation of the labels on the X axis.
 *
 * @param xLabels the X labels values
 * @param xTextLabelLocations the X text label locations
 * @param canvas the canvas to paint to
 * @param paint the paint to be used for drawing
 * @param left the left value of the labels area
 * @param top the top value of the labels area
 * @param bottom the bottom value of the labels area
 * @param xPixelsPerUnit the amount of pixels per one unit in the chart labels
 * @param minX the minimum value on the X axis in the chart
 * @param maxX the maximum value on the X axis in the chart
 */
protected void drawXLabels(List<Double> xLabels, Double[] xTextLabelLocations, Canvas canvas, Paint paint, int left, int top, int bottom, double xPixelsPerUnit, double minX, double maxX) {
    int length = xLabels.size();
    boolean showLabels = mRenderer.isShowLabels();
    boolean showGridY = mRenderer.isShowGridY();
    boolean showTickMarks = mRenderer.isShowTickMarks();
    for (int i = 0; i < length; i++) {
        double label = xLabels.get(i);
        float xLabel = (float) (left + xPixelsPerUnit * (label - minX));
        if (showLabels) {
            paint.setColor(mRenderer.getXLabelsColor());
            if (showTickMarks) {
                canvas.drawLine(xLabel, bottom, xLabel, bottom + mRenderer.getLabelsTextSize() / 3, paint);
            }
            drawText(canvas, getLabel(mRenderer.getXLabelFormat(), label), xLabel, bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding(), paint, mRenderer.getXLabelsAngle());
        }
        if (showGridY) {
            paint.setColor(mRenderer.getGridColor(0));
            canvas.drawLine(xLabel, bottom, xLabel, top, paint);
        }
    }
    drawXTextLabels(xTextLabelLocations, canvas, paint, showLabels, left, top, bottom, xPixelsPerUnit, minX, maxX);
}
Also used : Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 62 with List

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

the class XYChart method drawSeries.

/**
 * Draws the series.
 *
 * @param series the series
 * @param canvas the canvas
 * @param paint the paint object
 * @param pointsList the points to be rendered
 * @param seriesRenderer the series renderer
 * @param yAxisValue the y axis value in pixels
 * @param seriesIndex the series index
 * @param or the orientation
 * @param startIndex the start index of the rendering points
 */
protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List<Float> pointsList, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, int startIndex) {
    BasicStroke stroke = seriesRenderer.getStroke();
    int cap = paint.getStrokeCap();
    int join = paint.getStrokeJoin();
    float miter = paint.getStrokeMiter();
    // PathEffect pathEffect = paint.getPathEffect();
    Style style = paint.getStyle();
    if (stroke != null) {
        setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, paint);
    }
    // float[] points = MathHelper.getFloats(pointsList);
    drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
    drawPoints(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
    paint.setTextSize(seriesRenderer.getChartValuesTextSize());
    if (or == Orientation.HORIZONTAL) {
        paint.setTextAlign(Align.CENTER);
    } else {
        paint.setTextAlign(Align.LEFT);
    }
    if (seriesRenderer.isDisplayChartValues()) {
        paint.setTextAlign(seriesRenderer.getChartValuesTextAlign());
        drawChartValuesText(canvas, series, seriesRenderer, paint, pointsList, seriesIndex, startIndex);
    }
    if (stroke != null) {
        setStroke(cap, join, miter, style, paint);
    }
}
Also used : BasicStroke(com.codename1.charts.renderers.BasicStroke) Style(com.codename1.charts.compat.Paint.Style) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 63 with List

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

the class GenericListCellRenderer method getCellRendererComponent.

/**
 * {@inheritDoc}
 */
public Component getCellRendererComponent(Component list, Object model, T value, int index, boolean isSelected) {
    Component cmp;
    Component[] entries;
    if (!fisheye && !Display.getInstance().shouldRenderSelection(list)) {
        isSelected = false;
    }
    if (isSelected && (fisheye || list.hasFocus())) {
        cmp = selected;
        entries = selectedEntries;
        if (selectedEven != null && index % 2 == 0) {
            cmp = selectedEven;
            entries = selectedEntriesEven;
            // prevent the list from over-optimizing the background painting
            if (list instanceof List) {
                ((List) list).setMutableRendererBackgrounds(true);
            }
        }
        cmp.setFocus(true);
        boolean lead = false;
        if (cmp instanceof Container) {
            lead = ((Container) cmp).getLeadComponent() != null;
        }
        if (value instanceof Map) {
            Map h = (Map) value;
            Boolean enabled = (Boolean) h.get(ENABLED);
            if (enabled != null) {
                cmp.setEnabled(enabled.booleanValue());
            }
            int elen = entries.length;
            for (int iter = 0; iter < elen; iter++) {
                String currentName = entries[iter].getName();
                Object val;
                if (currentName.equals("$number")) {
                    val = "" + (index + 1);
                } else {
                    // a selected entry might differ in its value to allow for
                    // behavior such as rollover images
                    val = h.get("#" + currentName);
                    if (val == null) {
                        val = h.get(currentName);
                    }
                    val = updateModelValues(h, currentName, entries, iter, val);
                }
                setComponentValueWithTickering(entries[iter], val, list, cmp);
                entries[iter].setFocus(lead || entries[iter].isFocusable());
            }
        } else {
            if (value instanceof CloudObject) {
                CloudObject h = (CloudObject) value;
                Boolean enabled = (Boolean) h.getBoolean(ENABLED);
                if (enabled != null) {
                    cmp.setEnabled(enabled.booleanValue());
                }
                int elen = entries.length;
                for (int iter = 0; iter < elen; iter++) {
                    String currentName = entries[iter].getName();
                    Object val;
                    if (currentName.equals("$number")) {
                        val = "" + (index + 1);
                    } else {
                        // a selected entry might differ in its value to allow for
                        // behavior such as rollover images
                        val = h.getObject("#" + currentName);
                        if (val == null) {
                            val = h.getObject(currentName);
                        }
                    }
                    setComponentValueWithTickering(entries[iter], val, list, cmp);
                    entries[iter].setFocus(entries[iter].isFocusable());
                }
            } else {
                setComponentValueWithTickering(entries[0], value, list, cmp);
                entries[0].setFocus(entries[0].isFocusable());
            }
        }
        return cmp;
    } else {
        cmp = unselected;
        entries = unselectedEntries;
        if (unselectedEven != null && index % 2 == 0) {
            cmp = unselectedEven;
            entries = unselectedEntriesEven;
            // prevent the list from over-optimizing the background painting
            if (list instanceof List) {
                ((List) list).setMutableRendererBackgrounds(true);
            }
        }
        cmp.setFocus(false);
        if (value instanceof Map) {
            Map h = (Map) value;
            Boolean enabled = (Boolean) h.get(ENABLED);
            if (enabled != null) {
                cmp.setEnabled(enabled.booleanValue());
            }
            int elen = entries.length;
            for (int iter = 0; iter < elen; iter++) {
                String currentName = entries[iter].getName();
                if (currentName.equals("$number")) {
                    setComponentValue(entries[iter], "" + (index + 1), list, cmp);
                    continue;
                }
                Object val = h.get(currentName);
                val = updateModelValues(h, currentName, entries, iter, val);
                setComponentValue(entries[iter], val, list, cmp);
            }
        } else {
            if (value instanceof CloudObject) {
                CloudObject h = (CloudObject) value;
                Boolean enabled = h.getBoolean(ENABLED);
                if (enabled != null) {
                    cmp.setEnabled(enabled.booleanValue());
                }
                int elen = entries.length;
                for (int iter = 0; iter < elen; iter++) {
                    String currentName = entries[iter].getName();
                    if (currentName.equals("$number")) {
                        setComponentValue(entries[iter], "" + (index + 1), list, cmp);
                        continue;
                    }
                    setComponentValue(entries[iter], h.getObject(currentName), list, cmp);
                }
            } else {
                if (entries.length > 0) {
                    setComponentValue(entries[0], value, list, cmp);
                }
            }
        }
        return cmp;
    }
}
Also used : Container(com.codename1.ui.Container) CloudObject(com.codename1.cloud.CloudObject) List(com.codename1.ui.List) ArrayList(java.util.ArrayList) CloudObject(com.codename1.cloud.CloudObject) Component(com.codename1.ui.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with List

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

the class DefaultLookAndFeel method drawComboBox.

/**
 * {@inheritDoc}
 */
public void drawComboBox(Graphics g, List cb) {
    int border = 2;
    Style style = cb.getStyle();
    int leftPadding = style.getPaddingLeft(cb.isRTL());
    int rightPadding = style.getPaddingRight(cb.isRTL());
    setFG(g, cb);
    ListModel model = cb.getModel();
    ListCellRenderer renderer = cb.getRenderer();
    Object value = model.getItemAt(model.getSelectedIndex());
    int comboImageWidth;
    if (comboImage != null) {
        comboImageWidth = comboImage.getWidth();
    } else {
        comboImageWidth = style.getFont().getHeight();
    }
    int cellX = cb.getX() + style.getPaddingTop();
    if (cb.isRTL()) {
        cellX += comboImageWidth;
    }
    if (model.getSize() > 0) {
        Component cmp = renderer.getListCellRendererComponent(cb, value, model.getSelectedIndex(), cb.hasFocus());
        cmp.setX(cellX);
        cmp.setY(cb.getY() + style.getPaddingTop());
        cmp.setWidth(cb.getWidth() - comboImageWidth - rightPadding - leftPadding);
        cmp.setHeight(cb.getHeight() - style.getPaddingTop() - style.getPaddingBottom());
        cmp.paint(g);
    }
    g.setColor(style.getBgColor());
    int y = cb.getY();
    int height = cb.getHeight();
    int width = comboImageWidth + border;
    int x = cb.getX();
    if (cb.isRTL()) {
        x += leftPadding;
    } else {
        x += cb.getWidth() - comboImageWidth - rightPadding;
    }
    if (comboImage != null) {
        g.drawImage(comboImage, x, y + height / 2 - comboImage.getHeight() / 2);
    } else {
        int color = g.getColor();
        // brighten or darken the color slightly
        int destColor = findDestColor(color);
        g.fillLinearGradient(g.getColor(), destColor, x, y, width, height, false);
        g.setColor(color);
        g.drawRect(x, y, width, height - 1);
        width--;
        height--;
        // g.drawRect(x, y, width, height);
        g.translate(x + 1, y + 1);
        g.setColor(0x111111);
        int x1 = scaleCoordinate(2.5652081f, 16, width);
        int y1 = scaleCoordinate(4.4753664f, 16, height);
        int x2 = scaleCoordinate(8.2872691f, 16, width);
        int y2 = scaleCoordinate(10f, 16, height);
        int x3 = scaleCoordinate(13.516078f, 16, width);
        int y3 = y1;
        g.fillTriangle(x1, y1, x2, y2, x3, y3);
        g.translate(-1, -1);
        g.setColor(style.getFgColor());
        g.fillTriangle(x1, y1, x2, y2, x3, y3);
        // g.setColor(style.getFgColor());
        // g.fillTriangle(x1 + 2, y1 + 2, x2, y2 - 2, x3 - 2, y3 + 2);
        g.translate(-x, -y);
    }
}
Also used : ListModel(com.codename1.ui.list.ListModel) ListCellRenderer(com.codename1.ui.list.ListCellRenderer) Component(com.codename1.ui.Component)

Example 65 with List

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

the class DefaultLookAndFeel method getComboBoxPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getComboBoxPreferredSize(List cb) {
    Dimension d = getListPreferredSize(cb);
    if (comboImage != null) {
        d.setWidth(d.getWidth() + comboImage.getWidth());
        d.setHeight(Math.max(d.getHeight(), comboImage.getHeight()));
    }
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

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