de.enough.polish.ui
Class ChartItem

java.lang.Object
  extended by javax.microedition.lcdui.Item
      extended by javax.microedition.lcdui.CustomItem
          extended by de.enough.polish.ui.FakeCustomItem
              extended by de.enough.polish.ui.ChartItem

public class ChartItem
extends FakeCustomItem

The ChartItem renders numerical integer based data in a diagram.

Copyright Enough Software 2006 - 2008

 history
        Nov 28, 2006 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
 
Fields inherited from class de.enough.polish.ui.FakeCustomItem
_bbField, _bbFieldAdded, appearanceMode, background, backgroundHeight, backgroundWidth, backgroundYOffset, border, borderWidth, BUTTON, colSpan, commands, contentHeight, contentWidth, contentX, contentY, cssSelector, defaultCommand, focusedStyle, HORIZONTAL, HYPERLINK, includeLabel, INTERACTIVE, internalHeight, internalWidth, internalX, internalY, isFocused, isInitialized, isInvisible, isLayoutCenter, isLayoutExpand, isLayoutRight, isPressed, isShown, isStyleInitialised, itemCommandListener, itemHeight, itemWidth, label, labelStyle, layout, LAYOUT_2, LAYOUT_BOTTOM, LAYOUT_CENTER, LAYOUT_DEFAULT, LAYOUT_EXPAND, LAYOUT_LEFT, LAYOUT_NEWLINE_AFTER, LAYOUT_NEWLINE_BEFORE, LAYOUT_RIGHT, LAYOUT_SHRINK, LAYOUT_TOP, LAYOUT_VCENTER, LAYOUT_VEXPAND, LAYOUT_VSHRINK, marginBottom, marginLeft, marginRight, marginTop, maximumHeight, maximumWidth, minimumHeight, minimumWidth, NO_POSITION_SET, paddingBottom, paddingHorizontal, paddingLeft, paddingRight, paddingTop, paddingVertical, parent, PLAIN, preferredHeight, preferredWidth, preserveViewType, relativeX, relativeY, rowSpan, screen, style, TRANSPARENT, VERTICAL, view
 
Fields inherited from class javax.microedition.lcdui.CustomItem
KEY_PRESS, KEY_RELEASE, KEY_REPEAT, NONE, POINTER_DRAG, POINTER_PRESS, POINTER_RELEASE, TRAVERSE_HORIZONTAL, TRAVERSE_VERTICAL
 
Constructor Summary
ChartItem(java.lang.String label, int[][] dataSequences, int[] colors)
          Creates a new ChartItem.
ChartItem(java.lang.String label, int[][] dataSequences, int[] colors, java.lang.String[] labelsData, java.lang.String labelY, java.lang.String labelX, int baseLine, int divider)
          Creates a new ChartItem.
ChartItem(java.lang.String label, int[][] dataSequences, int[] colors, java.lang.String[] labelsData, java.lang.String labelY, java.lang.String labelX, int baseLine, int divider, Style style)
          Creates a new ChartItem.
ChartItem(java.lang.String label, int[][] dataSequences, int[] colors, Style style)
          Creates a new ChartItem.
 
Method Summary
protected  java.lang.String createCssSelector()
          Retrieves the CSS selector for this item.
 int getAxisColor()
           
 int getBaseLine()
           
 int[] getColors()
           
 int getDataMaximum()
           
 int getDataMinimum()
           
 int[][] getDataSequences()
           
 int getDivider()
           
 java.lang.String[] getLabelsData()
           
 java.lang.String getLabelX()
           
 java.lang.String getLabelY()
           
 int getScaleFactorX()
          Retrieves the scale factor used by the default implementation.
 int getScaleFactorY()
          Retrieves the scale factor used by the default implementation.
protected  void initContent(int firstLineWidth, int lineWidth)
          Initialises this item.
protected  void paintContent(int x, int y, int leftBorder, int rightBorder, javax.microedition.lcdui.Graphics g)
          Paints the content of this item.
 int paintGrid(int x, int y, int leftBorder, int rightBorder, int[] inout_params, javax.microedition.lcdui.Graphics g)
          Paints the labels and the axis of this chart.
 void setAxisColor(int axisColor)
           
 void setBaseLine(int baseLine)
           
 void setColors(int[] colors)
           
 void setDataMaximum(int dataMaximum)
           
 void setDataMinimum(int dataMinimum)
           
 void setDataSequences(int[][] dataSequences)
          Sets the data that should be visualized.
 void setDivider(int divider)
           
 void setLabelsData(java.lang.String[] labelsData)
           
 void setLabelX(java.lang.String labelX)
           
 void setLabelY(java.lang.String labelY)
           
 void setStyle(Style style)
          Sets the style of this item.
 
Methods inherited from class de.enough.polish.ui.FakeCustomItem
addCommand, addCommand, addCommands, addRelativeToBackgroundRegion, addRelativeToContentRegion, animate, animate, containsCommand, defocus, focus, getAbsoluteX, getAbsoluteY, getAppearanceMode, getAttribute, getAttributes, getBackgroundHeight, getBackgroundWidth, getBackgroundX, getBackgroundY, getContentHeight, getContentWidth, getContentX, getContentY, getDefaultCommand, getFocusedStyle, getItemAt, getItemCommandListener, getItemHeight, getItemStateListener, getItemWidth, getLabel, getLabelItem, getLayout, getMinContentHeight, getMinContentWidth, getMinimumHeight, getMinimumWidth, getParent, getPrefContentHeight, getPrefContentWidth, getPreferredHeight, getPreferredWidth, getScreen, getStyle, handleCommand, handleKeyPressed, handleKeyReleased, handleKeyRepeated, handlePointerPressed, handlePointerReleased, hideNotify, init, initStyle, isInContentArea, isInItemArea, isVisible, notifyItemPressedEnd, notifyItemPressedStart, notifyStateChanged, paint, paint, paintBackground, paintBackgroundAndBorder, paintBorder, releaseResources, removeCommand, repaintFully, requestInit, setAppearanceMode, setAttribute, setDefaultCommand, setItemCommandListener, setItemCommandListener, setItemStateListener, setLabel, setLayout, setPreferredSize, setVisible, show, showCommands, showNotify, toString
 
Methods inherited from class javax.microedition.lcdui.CustomItem
getGameAction, getInteractionModes, invalidate, keyPressed, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, sizeChanged, traverse, traverseOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChartItem

public ChartItem(java.lang.String label,
                 int[][] dataSequences,
                 int[] colors)
Creates a new ChartItem.

Parameters:
label - the label
dataSequences - the actual data that should be visualized
colors - the colors of each data sequence, can be overridden by the designer for most ChartItemViews

ChartItem

public ChartItem(java.lang.String label,
                 int[][] dataSequences,
                 int[] colors,
                 Style style)
Creates a new ChartItem.

Parameters:
label - the label
dataSequences - the actual data that should be visualized
colors - the colors of each data sequence, can be overridden by the designer for most ChartItemViews
style - the J2ME Polish style of this item

ChartItem

public ChartItem(java.lang.String label,
                 int[][] dataSequences,
                 int[] colors,
                 java.lang.String[] labelsData,
                 java.lang.String labelY,
                 java.lang.String labelX,
                 int baseLine,
                 int divider)
Creates a new ChartItem.

Parameters:
label - the label
dataSequences - the actual data that should be visualized
colors - the colors of each data sequence, can be overridden by the designer for most ChartItemViews
labelsData - optional labels for the legend of this item
labelY - the optional label for the vertical axis (e.g. revenue)
labelX - the optional label for the horizontal axis (e.g. years)
baseLine - the reference point from which the data should be shown. This can be a handy trick for making growth seem more spectacular, for example - just show the difference between a former year and today instead of showing the absolute growth, for example. Set to 0 for playing it clean.
divider - can be used to simulate floating point numbers with integer numbers, a devider of 100 can make eurocents to euros, for example (or cents to dollars). A divider of 1.000.000 could show revenue in million pounds, for example.

ChartItem

public ChartItem(java.lang.String label,
                 int[][] dataSequences,
                 int[] colors,
                 java.lang.String[] labelsData,
                 java.lang.String labelY,
                 java.lang.String labelX,
                 int baseLine,
                 int divider,
                 Style style)
Creates a new ChartItem.

Parameters:
label - the label
dataSequences - the actual data that should be visualized
colors - the colors of each data sequence, can be overridden by the designer for most ChartItemViews
labelsData - optional labels for the legend of this item
labelY - the optional label for the vertical axis (e.g. revenue)
labelX - the optional label for the horizontal axis (e.g. years)
baseLine - the reference point from which the data should be shown. This can be a handy trick for making growth seem more spectacular, for example - just show the difference between a former year and today instead of showing the absolute growth, for example. Set to 0 for playing it clean.
divider - can be used to simulate floating point numbers with integer numbers, a devider of 100 can make eurocents to euros, for example (or cents to dollars). A divider of 1.000.000 could show revenue in million pounds, for example.
style - the J2ME Polish style of this item
Method Detail

createCssSelector

protected java.lang.String createCssSelector()
Description copied from class: FakeCustomItem
Retrieves the CSS selector for this item. The CSS selector is used for the dynamic assignment of styles - that is the styles are assigned by the usage of the item and not by a predefined style-name. With the #style preprocessing command styles are set fix, this method yields in a faster GUI and is recommended. When in a style-sheet dynamic styles are used, e.g. "Form>p", than the selector of the item is needed.
This abstract method needs only be implemented, when dynamic styles are used: #ifdef polish.useDynamicStyles
The returned selector needs to be in lower case.

Specified by:
createCssSelector in class FakeCustomItem
Returns:
the appropriate CSS selector for this item. The selector needs to be in lower case.

initContent

protected void initContent(int firstLineWidth,
                           int lineWidth)
Description copied from class: FakeCustomItem
Initialises this item. The implementation needs to calculate and set the contentWidth and contentHeight fields. The implementation should take the fields preferredWidth and preferredHeight into account.

Specified by:
initContent in class FakeCustomItem
Parameters:
firstLineWidth - the maximum width of the first line
lineWidth - the maximum width of any following lines
See Also:
FakeCustomItem.contentWidth, FakeCustomItem.contentHeight, FakeCustomItem.preferredWidth, FakeCustomItem.preferredHeight

paintGrid

public int paintGrid(int x,
                     int y,
                     int leftBorder,
                     int rightBorder,
                     int[] inout_params,
                     javax.microedition.lcdui.Graphics g)
Paints the labels and the axis of this chart.

Parameters:
x - the left start position
y - the upper start position
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
inout_params - an array with 2 elements for adjusting x and y:
 int[] inout_params = new int[]{ x, y };
 int baseLineY = chart.paintGrid(x, y, leftBorder, rightBorder, inout_params, g); 
 x = inout_params[0];
 y = inout_params[1];
 
g - the Graphics on which this item should be painted.
Returns:
the y position of the baseline

paintContent

protected void paintContent(int x,
                            int y,
                            int leftBorder,
                            int rightBorder,
                            javax.microedition.lcdui.Graphics g)
Description copied from class: FakeCustomItem
Paints the content of this item. The background has already been painted and the border will be added after this method returns.

Specified by:
paintContent in class FakeCustomItem
Parameters:
x - the left start position
y - the upper start position
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
g - the Graphics on which this item should be painted.

setStyle

public void setStyle(Style style)
Description copied from class: FakeCustomItem
Sets the style of this item.

Overrides:
setStyle in class FakeCustomItem
Parameters:
style - the new style for this item.

getBaseLine

public int getBaseLine()
Returns:
the baseLine

setBaseLine

public void setBaseLine(int baseLine)
Parameters:
baseLine - the baseLine to set

getDataMaximum

public int getDataMaximum()
Returns:
the dataMaximum

setDataMaximum

public void setDataMaximum(int dataMaximum)
Parameters:
dataMaximum - the dataMaximum to set

getDataMinimum

public int getDataMinimum()
Returns:
the dataMinimum

setDataMinimum

public void setDataMinimum(int dataMinimum)
Parameters:
dataMinimum - the dataMinimum to set

getDataSequences

public int[][] getDataSequences()
Returns:
the dataSequences

setDataSequences

public void setDataSequences(int[][] dataSequences)
Sets the data that should be visualized. Also the minimum and maximum of the data is calculated here.

Parameters:
dataSequences - the dataSequences to set

getDivider

public int getDivider()
Returns:
the divider

setDivider

public void setDivider(int divider)
Parameters:
divider - the divider to set

getLabelsData

public java.lang.String[] getLabelsData()
Returns:
the labelsData

setLabelsData

public void setLabelsData(java.lang.String[] labelsData)
Parameters:
labelsData - the labelsData to set

getLabelX

public java.lang.String getLabelX()
Returns:
the labelX

setLabelX

public void setLabelX(java.lang.String labelX)
Parameters:
labelX - the labelX to set

getLabelY

public java.lang.String getLabelY()
Returns:
the labelY

setLabelY

public void setLabelY(java.lang.String labelY)
Parameters:
labelY - the labelY to set

getAxisColor

public int getAxisColor()
Returns:
the axisColor

setAxisColor

public void setAxisColor(int axisColor)
Parameters:
axisColor - the axisColor to set

getColors

public int[] getColors()
Returns:
the colors

setColors

public void setColors(int[] colors)
Parameters:
colors - the colors to set

getScaleFactorY

public int getScaleFactorY()
Retrieves the scale factor used by the default implementation. This method is usually only interesting for specifc chart ItemViews.

Returns:
the vertical scale factor

getScaleFactorX

public int getScaleFactorX()
Retrieves the scale factor used by the default implementation. This method is usually only interesting for specifc chart ItemViews.

Returns:
the honrizontal scale factor