use of com.codename1.ui.List in project CodenameOne by codenameone.
the class BarChart method drawChartValuesText.
/**
* The graphical representation of the series values as text.
*
* @param canvas the canvas to paint to
* @param series the series to be painted
* @param renderer the series renderer
* @param paint the paint to be used for drawing
* @param points the array of points to be used for drawing the series
* @param seriesIndex the index of the series currently being drawn
* @param startIndex the start index of the rendering points
*/
protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRenderer renderer, Paint paint, List<Float> points, int seriesIndex, int startIndex) {
int seriesNr = mDataset.getSeriesCount();
int length = points.size();
float halfDiffX = getHalfDiffX(points, length, seriesNr);
for (int i = 0; i < length; i += 2) {
int index = startIndex + i / 2;
double value = series.getY(index);
if (!isNullValue(value)) {
float x = points.get(i);
if (mType == Type.DEFAULT) {
x += seriesIndex * 2 * halfDiffX - (seriesNr - 1.5f) * halfDiffX;
}
if (value >= 0) {
drawText(canvas, getLabel(renderer.getChartValuesFormat(), value), x, points.get(i + 1) - renderer.getChartValuesSpacing(), paint, 0);
} else {
drawText(canvas, getLabel(renderer.getChartValuesFormat(), value), x, points.get(i + 1) + renderer.getChartValuesTextSize() + renderer.getChartValuesSpacing() - 3, paint, 0);
}
}
}
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class BarChart method clickableAreasForPoints.
@Override
protected ClickableArea[] clickableAreasForPoints(List<Float> points, List<Double> values, float yAxisValue, int seriesIndex, int startIndex) {
int seriesNr = mDataset.getSeriesCount();
int length = points.size();
ClickableArea[] ret = new ClickableArea[length / 2];
float halfDiffX = getHalfDiffX(points, length, seriesNr);
for (int i = 0; i < length; i += 2) {
float x = points.get(i);
float y = points.get(i + 1);
if (mType == Type.STACKED || mType == Type.HEAPED) {
ret[i / 2] = new ClickableArea(PkgUtils.makeRect(x - halfDiffX, Math.min(y, yAxisValue), x + halfDiffX, Math.max(y, yAxisValue)), values.get(i), values.get(i + 1));
} else {
float startX = x - seriesNr * halfDiffX + seriesIndex * 2 * halfDiffX;
ret[i / 2] = new ClickableArea(PkgUtils.makeRect(startX, Math.min(y, yAxisValue), startX + 2 * halfDiffX, Math.max(y, yAxisValue)), values.get(i), values.get(i + 1));
}
}
return ret;
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class DoughnutChart method draw.
/**
* The graphical representation of the doughnut chart.
*
* @param canvas the canvas to paint to
* @param x the top left x value of the view to draw to
* @param y the top left y value of the view to draw to
* @param width the width of the view to draw to
* @param height the height of the view to draw to
* @param paint the paint
*/
@Override
public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint) {
paint.setAntiAlias(mRenderer.isAntialiasing());
paint.setStyle(Style.FILL);
paint.setTextSize(mRenderer.getLabelsTextSize());
int legendSize = getLegendSize(mRenderer, height / 5, 0);
int left = x;
int top = y;
int right = x + width;
int cLength = mDataset.getCategoriesCount();
String[] categories = new String[cLength];
for (int category = 0; category < cLength; category++) {
categories[category] = mDataset.getCategory(category);
}
if (mRenderer.isFitLegend()) {
legendSize = drawLegend(canvas, mRenderer, categories, left, right, y, width, height, legendSize, paint, true);
}
int bottom = y + height - legendSize;
drawBackground(mRenderer, canvas, x, y, width, height, paint, false, DefaultRenderer.NO_COLOR);
mStep = SHAPE_WIDTH * 3 / 4;
int mRadius = Math.min(Math.abs(right - left), Math.abs(bottom - top));
double rCoef = 0.35 * mRenderer.getScale();
double decCoef = 0.2 / cLength;
int radius = (int) (mRadius * rCoef);
if (autoCalculateCenter || mCenterX == NO_VALUE) {
mCenterX = (left + right) / 2;
}
if (autoCalculateCenter || mCenterY == NO_VALUE) {
mCenterY = (bottom + top) / 2;
}
float shortRadius = radius * 0.9f;
float longRadius = radius * 1.1f;
List<Rectangle2D> prevLabelsBounds = new ArrayList<Rectangle2D>();
for (int category = 0; category < cLength; category++) {
int sLength = mDataset.getItemCount(category);
double total = 0;
String[] titles = new String[sLength];
for (int i = 0; i < sLength; i++) {
total += mDataset.getValues(category)[i];
titles[i] = mDataset.getTitles(category)[i];
}
float currentAngle = mRenderer.getStartAngle();
Rectangle2D oval = PkgUtils.makeRect(mCenterX - radius, mCenterY - radius, mCenterX + radius, mCenterY + radius);
for (int i = 0; i < sLength; i++) {
paint.setColor(mRenderer.getSeriesRendererAt(i).getColor());
float value = (float) mDataset.getValues(category)[i];
float angle = (float) (value / total * 360);
canvas.drawArc(oval, currentAngle, angle, true, paint);
drawLabel(canvas, mDataset.getTitles(category)[i], mRenderer, prevLabelsBounds, mCenterX, mCenterY, shortRadius, longRadius, currentAngle, angle, left, right, mRenderer.getLabelsColor(), paint, true, false);
currentAngle += angle;
}
radius -= (int) mRadius * decCoef;
shortRadius -= mRadius * decCoef - 2;
if (mRenderer.getBackgroundColor() != 0) {
paint.setColor(mRenderer.getBackgroundColor());
} else {
paint.setColor(ColorUtil.WHITE);
}
paint.setStyle(Style.FILL);
oval = PkgUtils.makeRect(mCenterX - radius, mCenterY - radius, mCenterX + radius, mCenterY + radius);
canvas.drawArc(oval, 0, 360, true, paint);
radius -= 1;
}
prevLabelsBounds.clear();
drawLegend(canvas, mRenderer, categories, left, right, y, width, height, legendSize, paint, false);
drawTitle(canvas, x, y, width, paint);
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class BubbleChart method clickableAreasForPoints.
@Override
protected ClickableArea[] clickableAreasForPoints(List<Float> points, List<Double> values, float yAxisValue, int seriesIndex, int startIndex) {
int length = points.size();
XYValueSeries series = (XYValueSeries) mDataset.getSeriesAt(seriesIndex);
double max = series.getMaxValue();
double coef = MAX_BUBBLE_SIZE / max;
ClickableArea[] ret = new ClickableArea[length / 2];
for (int i = 0; i < length; i += 2) {
double size = series.getValue(startIndex + i / 2) * coef + MIN_BUBBLE_SIZE;
ret[i / 2] = new ClickableArea(PkgUtils.makeRect(points.get(i) - (float) size, points.get(i + 1) - (float) size, points.get(i) + (float) size, points.get(i + 1) + (float) size), values.get(i), values.get(i + 1));
}
return ret;
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class ComboBox method showPopupDialog.
/**
* Shows the popup dialog for the combo box and returns the resulting command.
* This method can be overriden by subclasses to modify the behavior of the class.
*
* @param popupDialog the popup dialog
* @param l the list within
* @return the selected command
*/
protected Command showPopupDialog(Dialog popupDialog, List l) {
if (getUIManager().isThemeConstant("popupTitleBool", false)) {
if (getLabelForComponent() != null) {
popupDialog.setTitle(getLabelForComponent().getText());
}
}
if (includeSelectCancel) {
popupDialog.setBackCommand(popupDialog.getMenuBar().getCancelMenuItem());
if (Display.getInstance().isTouchScreenDevice()) {
if (getUIManager().isThemeConstant("popupCancelBodyBool", false)) {
popupDialog.placeButtonCommands(new Command[] { popupDialog.getMenuBar().getCancelMenuItem() });
}
} else {
if (Display.getInstance().isThirdSoftButton()) {
popupDialog.addCommand(popupDialog.getMenuBar().getSelectMenuItem());
popupDialog.addCommand(popupDialog.getMenuBar().getCancelMenuItem());
} else {
popupDialog.addCommand(popupDialog.getMenuBar().getCancelMenuItem());
popupDialog.addCommand(popupDialog.getMenuBar().getSelectMenuItem());
}
}
}
if (actAsSpinnerDialog) {
l.setFixedSelection(List.FIXED_CENTER);
l.setUIID("Spinner");
l.spinnerOverlay = getUIManager().getComponentStyle("SpinnerOverlay");
l.spinnerOverlay.setMargin(0, 0, 0, 0);
l.setAlwaysTensile(false);
l.installDefaultPainter(l.spinnerOverlay);
popupDialog.setDialogUIID("Container");
popupDialog.setUIID("Container");
popupDialog.getTitleComponent().setUIID("Container");
popupDialog.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 200));
popupDialog.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 200));
return popupDialog.show(Display.getInstance().getDisplayHeight() - popupDialog.getDialogComponent().getPreferredH(), 0, 0, 0, true, true);
}
if (getUIManager().isThemeConstant("centeredPopupBool", false)) {
return popupDialog.showPacked(BorderLayout.CENTER, true);
} else {
int top, bottom, left, right;
Form parentForm = getComponentForm();
int listW = Math.max(getWidth(), l.getPreferredW());
listW = Math.min(listW + l.getSideGap(), parentForm.getContentPane().getWidth());
Component content = popupDialog.getDialogComponent();
Style contentStyle = content.getStyle();
int listH = content.getPreferredH() + contentStyle.getVerticalMargins();
Component title = popupDialog.getTitleArea();
listH += title.getPreferredH() + title.getStyle().getVerticalMargins();
bottom = 0;
top = getAbsoluteY();
int formHeight = parentForm.getHeight();
if (parentForm.getSoftButtonCount() > 1) {
Component c = parentForm.getSoftButton(0).getParent();
formHeight -= c.getHeight();
Style s = c.getStyle();
formHeight -= (s.getVerticalMargins());
}
if (listH < formHeight) {
// pop up or down?
if (top > formHeight / 2) {
bottom = formHeight - top;
top = top - listH;
} else {
top += getHeight();
bottom = formHeight - top - listH;
}
} else {
top = 0;
}
left = getAbsoluteX();
right = parentForm.getWidth() - left - listW;
if (right < 0) {
left += right;
right = 0;
}
popupDialog.setBackCommand(popupDialog.getMenuBar().getCancelMenuItem());
return popupDialog.show(Math.max(top, 0), Math.max(bottom, 0), Math.max(left, 0), Math.max(right, 0), false, true);
}
}
Aggregations