org.hermit.android.instruments
Class TextGauge

java.lang.Object
  extended by org.hermit.android.instruments.Gauge
      extended by org.hermit.android.instruments.TextGauge

public class TextGauge
extends Gauge

A Gauge which displays data in textual form, generally as a grid of numeric values.


Constructor Summary
TextGauge(SurfaceRunner parent)
          Set up this view, and configure the text fields to be displayed in this element.
TextGauge(SurfaceRunner parent, java.lang.String[] template, int rows)
          Set up this view, and configure the text fields to be displayed in this element.
 
Method Summary
protected  void drawBody(Canvas canvas, Paint paint, long now)
          This method is called to ask the element to draw itself.
 char[][][] getBuffer()
          Get the text buffers for the field values.
 int getPreferredHeight()
          Get the minimum height needed to fit all the text.
 int getPreferredWidth()
          Get the minimum width needed to fit all the text.
 int getTextColor()
          Get the text colour of this element.
 float getTextSize()
          Get the text size of this element.
protected  void initializePaint(Paint paint)
          Set up the paint for this element.
 void setGeometry(Rect bounds)
          This is called during layout when the size of this element has changed.
 void setMargins(int left, int top, int right, int bottom)
          Set the margins around the displayed text.
 void setTextColor(int col)
          Set the text colour of this element.
 void setTextFields(java.lang.String[] template, int rows)
          Set up the text fields to be displayed in this element.
 void setTextSize(float size)
          Set the text size of this element.
 
Methods inherited from class org.hermit.android.instruments.Gauge
cacheBackground, draw, drawBackground, drawBackgroundBody, drawFinish, drawStart, error, getBackgroundColor, getBaseTextSize, getBounds, getGridColor, getHeadTextSize, getHeight, getInnerGap, getInterPadding, getMiniTextSize, getPaint, getPlotColor, getSidebarWidth, getSurface, getTextScaleX, getTextTypeface, getTinyTextSize, getWidth, haveBounds, optionSet, setBackgroundColor, setBaseTextSize, setDataColors, setGridColor, setHeadTextSize, setInnerGap, setInterPadding, setMiniTextSize, setPlotColor, setSidebarWidth, setTextScaleX, setTextTypeface, setTinyTextSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextGauge

public TextGauge(SurfaceRunner parent)
Set up this view, and configure the text fields to be displayed in this element. This is equivalent to calling setTextFields() after the basic constructor. We support display of a single field, or a rectangular table of fields. The caller must call setTextFields(String[] template, int rows) to set the table format.

Parameters:
parent - Parent surface.

TextGauge

public TextGauge(SurfaceRunner parent,
                 java.lang.String[] template,
                 int rows)
Set up this view, and configure the text fields to be displayed in this element. This is equivalent to calling setTextFields() after the basic constructor. We support display of a single field, or a rectangular table of fields. The fields are specified by passing in sample text values to be measured; we then allocate the space automatically.

Parameters:
parent - Parent surface.
template - Strings representing the columns to display. Each one should be a sample piece of text which will be measured to determine the required space for each column. Must be provided.
rows - Number of rows of text to display.
Method Detail

initializePaint

protected void initializePaint(Paint paint)
Set up the paint for this element. This is called during initialisation. Subclasses can override this to do class-specific one-time initialisation.

Overrides:
initializePaint in class Gauge
Parameters:
paint - The paint to initialise.

setGeometry

public void setGeometry(Rect bounds)
This is called during layout when the size of this element has changed. This is where we first discover our size, so set our geometry to match.

Overrides:
setGeometry in class Gauge
Parameters:
bounds - The bounding rect of this element within its parent View.

setMargins

public void setMargins(int left,
                       int top,
                       int right,
                       int bottom)
Set the margins around the displayed text. This the total space between the edges of the element and the outside bounds of the text.

Parameters:
left - The left margin.
top - The top margin.
right - The right margin.
bottom - The bottom margin.

setTextFields

public void setTextFields(java.lang.String[] template,
                          int rows)
Set up the text fields to be displayed in this element. If this is never called, there will be no text. We support display of a single field, or a rectangular table of fields. The fields are specified by passing in sample text values to be measured; we then allocate the space automatically. This must be called before setText() can be called.

Parameters:
template - Strings representing the columns to display. Each one should be a sample piece of text which will be measured to determine the required space for each column.
rows - Number of rows of text to display.

getBuffer

public char[][][] getBuffer()
Get the text buffers for the field values. The caller can change a field's content by writing to the appropriate member of the array, as in "buffer[row][col][0] = 'X';".

Returns:
Text buffers for the field values.

getPreferredWidth

public int getPreferredWidth()
Get the minimum width needed to fit all the text.

Overrides:
getPreferredWidth in class Gauge
Returns:
The minimum width needed to fit all the text. Returns zero if setTextFields() hasn't been called.

getPreferredHeight

public int getPreferredHeight()
Get the minimum height needed to fit all the text.

Overrides:
getPreferredHeight in class Gauge
Returns:
The minimum height needed to fit all the text. Returns zero if setTextFields() hasn't been called.

setTextColor

public void setTextColor(int col)
Set the text colour of this element.

Parameters:
col - The new text colour, in ARGB format.

getTextColor

public int getTextColor()
Get the text colour of this element.

Returns:
The text colour, in ARGB format.

setTextSize

public void setTextSize(float size)
Set the text size of this element.

Parameters:
size - The new text size.

getTextSize

public float getTextSize()
Get the text size of this element.

Returns:
The text size.

drawBody

protected void drawBody(Canvas canvas,
                        Paint paint,
                        long now)
This method is called to ask the element to draw itself.

Overrides:
drawBody in class Gauge
Parameters:
canvas - Canvas to draw into.
paint - The Paint which was set up in initializePaint().
now - Nominal system time in ms. of this update.