Blackberry Bar-Graph (Class 1)


import net.rim.device.api.ui.Field;

/**
 * The base class for which other graph fields are derived from.
 */

public abstract class GraphField extends Field {
 /*
  * The values (data) used to create the graph.
  */
 protected int[] _values;

 /**
  * The colors used to display the data sets.
  */
 protected int[] _colors;

 /**
  * The width of the field.
  */
 protected int _width;

 /**
  * The height of the field.
  */
 protected int _height;

 /**
  * Creates a plain empty graph field.
  */
 GraphField() {
  super();
 }

 /**
  * Retrieves the color at the specified index.
  * 
  * @param index
  *            The index of the color.
  * @return an integer in form 0x00RRGGBB
  */
 public int getColor(int index) {
  return _colors[index];
 }

 /**
  * Retrieves an array of colors.
  * 
  * @return an array of integers in the form 0x00RRGGBB
  */
 public int[] getColors() {
  return _colors;
 }

 /**
  * Retrieves the value at the specified index.
  * 
  * @param index
  *            The index of the value
  * @return the integer value at the specified index
  */
 public int getValue(int index) {
  return _values[index];
 }

 /**
  * Retrieves the array of values (data).
  * 
  * @return an array of graph values
  */
 public int[] getValues() {
  return _values;
 }

 /**
  * Set the graph data
  * 
  * @param values
  *            The graph values (data).
  * @param colors
  *            The colors used to display the graph sets.
  */
 public void setGraphData(int[] values, int[] colors) {
  _values = values;
  _colors = colors;
 }

 public int getPreferredHeight() {
  return _height;
 }

 public int getPreferredWidth() {
  return _width;
 }

 /**
  * Lay out the graph
  * 
  * @param width
  *            The maximum width available.
  * @param height
  *            The maximum height available.
  */
 protected void layout(int width, int height) {
  int w, h;

  if (width >= _width) {
   w = _width;
  } else {
   w = width;

  }

  if (height >= _height) {
   h = _height;
  } else {
   h = height;
  }

  setExtent(w, h);
 }
}

Comments

Popular posts from this blog

Input filter (space not allowed) for EditText

Android Versions details

English - Formal and Informal words