Search in sources :

Example 41 with List

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

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

the class BarChart method getHalfDiffX.

/**
 * Calculates and returns the half-distance in the graphical representation of
 * 2 consecutive points.
 *
 * @param points the points
 * @param length the points length
 * @param seriesNr the series number
 * @return the calculated half-distance value
 */
protected float getHalfDiffX(List<Float> points, int length, int seriesNr) {
    float barWidth = mRenderer.getBarWidth();
    if (barWidth > 0) {
        return barWidth / 2;
    }
    int div = length;
    if (length > 2) {
        div = length - 2;
    }
    float halfDiffX = (points.get(length - 2) - points.get(0)) / div;
    if (halfDiffX == 0) {
        halfDiffX = 10;
    }
    if (mType != Type.STACKED && mType != Type.HEAPED) {
        halfDiffX /= seriesNr;
    }
    return (float) (halfDiffX / (getCoeficient() * (1 + mRenderer.getBarSpacing())));
}
Also used : Paint(com.codename1.charts.compat.Paint)

Example 43 with List

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

the class ComboBox method createPopupDialog.

/**
 * Subclasses can override this method to change the creation of the dialog
 *
 * @param l the list of the popup
 * @return a dialog instance
 */
protected Dialog createPopupDialog(List<T> l) {
    Dialog popupDialog = new Dialog(getUIID() + "Popup", getUIID() + "PopupTitle") {

        void sizeChangedInternal(int w, int h) {
            // resize the popup just resize the parent form
            if (getWidth() == w && getHeight() != h) {
                Form frm = getPreviousForm();
                if (frm != null) {
                    frm.sizeChangedInternal(w, h);
                }
                setSize(new Dimension(w, h));
                repaint();
            } else {
                dispose();
            }
        }
    };
    popupDialog.setScrollable(false);
    popupDialog.getContentPane().setAlwaysTensile(false);
    popupDialog.setAlwaysTensile(false);
    popupDialog.getContentPane().setUIID("PopupContentPane");
    popupDialog.setDisposeWhenPointerOutOfBounds(true);
    popupDialog.setTransitionInAnimator(CommonTransitions.createEmpty());
    popupDialog.setTransitionOutAnimator(CommonTransitions.createEmpty());
    popupDialog.setLayout(new BorderLayout());
    popupDialog.addComponent(BorderLayout.CENTER, l);
    return popupDialog;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Dimension(com.codename1.ui.geom.Dimension)

Example 44 with List

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

the class ComboBox method createPopupList.

/**
 * Creates the list object used within the popup dialog. This method allows subclasses
 * to customize the list creation for the popup dialog shown when the combo box is pressed.
 *
 * @return a newly created list object used when the user presses the combo box.
 */
protected List<T> createPopupList() {
    List<T> l = new List<T>(getModel());
    l.setCommandList(isCommandList());
    l.setSmoothScrolling(isSmoothScrolling());
    l.setFixedSelection(getFixedSelection());
    l.setListCellRenderer(getRenderer());
    l.setItemGap(getItemGap());
    l.setUIID("ComboBoxList");
    if (getUIManager().isThemeConstant("otherPopupRendererBool", false)) {
        DefaultListCellRenderer renderer = new DefaultListCellRenderer();
        renderer.setUIID("PopupItem");
        renderer.getListFocusComponent(l).setUIID("PopupFocus");
        l.setListCellRenderer(renderer);
    }
    return l;
}
Also used : DefaultListCellRenderer(com.codename1.ui.list.DefaultListCellRenderer)

Example 45 with List

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

the class Component method scrollRectToVisible.

/**
 * Makes sure the component is visible in the scroll if this container
 * is scrollable
 *
 * @param x
 * @param y
 * @param width
 * @param height
 * @param coordinateSpace the component according to whose coordinates
 * rect is defined. Rect's x/y are relative to that component
 * (they are not absolute).
 */
public void scrollRectToVisible(int x, int y, int width, int height, Component coordinateSpace) {
    if (isScrollable()) {
        int scrollPosition = getScrollY();
        Style s = getStyle();
        int w = getWidth() - s.getHorizontalPadding();
        int h = getHeight() - s.getVerticalPadding();
        Rectangle view;
        int invisibleAreaUnderVKB = getInvisibleAreaUnderVKB();
        if (isSmoothScrolling() && destScrollY > -1) {
            view = new Rectangle(getScrollX(), destScrollY, w, h - invisibleAreaUnderVKB);
        } else {
            view = new Rectangle(getScrollX(), getScrollY(), w, h - invisibleAreaUnderVKB);
        }
        int relativeX = x;
        int relativeY = y;
        // component needs to be in absolute coordinates...
        Container parent = null;
        if (coordinateSpace != null) {
            parent = coordinateSpace.getParent();
        }
        if (parent == this) {
            if (view.contains(x, y, width, height)) {
                return;
            }
        } else {
            while (parent != this) {
                // mostly a special case for list
                if (parent == null) {
                    relativeX = x;
                    relativeY = y;
                    break;
                }
                relativeX += parent.getX();
                relativeY += parent.getY();
                parent = parent.getParent();
            }
            if (view.contains(relativeX, relativeY, width, height)) {
                return;
            }
        }
        if (isScrollableX()) {
            if (getScrollX() > relativeX) {
                setScrollX(relativeX);
            }
            int rightX = relativeX + width - s.getHorizontalPadding();
            if (getScrollX() + w < rightX) {
                setScrollX(getScrollX() + (rightX - (getScrollX() + w)));
            } else {
                if (getScrollX() > relativeX) {
                    setScrollX(relativeX);
                }
            }
        }
        if (isScrollableY()) {
            if (getScrollY() > relativeY) {
                scrollPosition = relativeY;
            }
            int bottomY = relativeY + height - s.getVerticalPadding();
            if (getScrollY() + h < bottomY + invisibleAreaUnderVKB) {
                scrollPosition = getScrollY() + (bottomY - (getScrollY() + h)) + invisibleAreaUnderVKB;
            } else {
                if (getScrollY() > relativeY) {
                    scrollPosition = relativeY;
                }
            }
            if (isSmoothScrolling() && isInitialized()) {
                initialScrollY = getScrollY();
                destScrollY = scrollPosition;
                initScrollMotion();
            } else {
                setScrollY(scrollPosition);
            }
        }
        repaint();
    } else {
        // try to move parent scroll if you are not scrollable
        Container parent = getParent();
        if (parent != null) {
            parent.scrollRectToVisible(getAbsoluteX() - parent.getAbsoluteX() + x, getAbsoluteY() - parent.getAbsoluteY() + y, width, height, parent);
        }
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Point(com.codename1.ui.geom.Point)

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