JLogView_.datastructs
Class LGLegend

java.lang.Object
  extended by JLogView_.datastructs.LGLegend

public class LGLegend
extends java.lang.Object

LGLegend is a class representing the data structure of a graph legend. It contains one entry for each plot of the graph. Each entry reflet the colour, linestyle and symbol being used (or not) from the overall settings.


Constructor Summary
LGLegend(int nitems)
          This is the constructor LGLegend.
 
Method Summary
 void addLegendItem(java.lang.String text)
          This method appends a new entry to the list of existing items in the legend.
 void addLegendItem(java.lang.String text, java.awt.Color col, java.awt.BasicStroke str, int symb, int symbsize)
          This method appends a new entry to the list of existing items in the legend.
 int countItems()
          This method returns the current number of item of the legend
 void draw(java.awt.Graphics2D g, boolean useColours, boolean useLineStyles, boolean useSymbols)
          This methods draws the legend on the given graphic context.
 java.awt.Font getFont()
          This method returns the font details (font face,style and size) being used to write the legend entries.
 java.lang.String getItemName(int index)
          Given an index, this method return the corresponding legend item name.
 int[] getPosition()
          This method returns the position of the legend on the canvas.
 java.awt.Dimension getSize()
          This method returns size of the legend in pixels.
 void setFont(java.awt.Font f)
          This method sets the font details (font face,style and size) being used to write the legend entries.
 void setInitialPosition(int x, int y, int width, int height)
          This method sets the initial position.
 void setItemName(int index, java.lang.String name)
          This method sets the item name of the item situated at the given index.
 void setPosition(int x, int y)
          This method sets the position of the legend on the canvas.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LGLegend

public LGLegend(int nitems)
This is the constructor LGLegend. The only parameter needed is number of entries of the legend.

Parameters:
nitems - the number of items in the legend
Method Detail

countItems

public int countItems()
This method returns the current number of item of the legend

Returns:
the number of items in the legend

getItemName

public java.lang.String getItemName(int index)
Given an index, this method return the corresponding legend item name.

Parameters:
index - the item index (starting from 0)
Returns:
a String representing the item name
See Also:
String

setItemName

public void setItemName(int index,
                        java.lang.String name)
This method sets the item name of the item situated at the given index.

Parameters:
index - the item index (starting from 0)
name - a String representing the item name
See Also:
String

addLegendItem

public void addLegendItem(java.lang.String text)
This method appends a new entry to the list of existing items in the legend. In this case all default drawing style will be used.

Parameters:
text - a String representing the item name
See Also:
String

addLegendItem

public void addLegendItem(java.lang.String text,
                          java.awt.Color col,
                          java.awt.BasicStroke str,
                          int symb,
                          int symbsize)
This method appends a new entry to the list of existing items in the legend. In this case the colour, linestyle (aka stroke), symbol type and size are specified.

Parameters:
text - a String representing the item name
col - a Color object specifying the colour to use for this item
str - a BasicStroke object specifying the linestyle to use for this item
symb - a integer (value between 0 and 7) specifying the symbol to use for this item
symbsize - an integer giving the size in pixels for the symbol used.
See Also:
String, Color, BasicStroke

setPosition

public void setPosition(int x,
                        int y)
This method sets the position of the legend on the canvas. Coordinates given have to be in pixel coordinates.

Parameters:
x - the x coordinate in pixels
y - the y coordinate in pixels

setInitialPosition

public void setInitialPosition(int x,
                               int y,
                               int width,
                               int height)
This method sets the initial position. This is mainly used when the legend is drawn for the first time. Given a first position and the sizes of the canvas and knowing the number of item it "stick" the legend in one of the corners.

Parameters:
x - the x coordinate in pixels
y - the y coordinate in pixels
width - the width of the canvas in pixels
height - the height of the canvas pixels

getPosition

public int[] getPosition()
This method returns the position of the legend on the canvas. Coordinates given have to be in pixel coordinates.

Returns:
an integer array having the x and y coordinates of the legend in pixels

getSize

public java.awt.Dimension getSize()
This method returns size of the legend in pixels. The width relates to the longest item name in the legend. The height relates to the number of entries in the legend.

Returns:
a Dimension object containing the size information of the legend
See Also:
Dimension

getFont

public java.awt.Font getFont()
This method returns the font details (font face,style and size) being used to write the legend entries.

Returns:
a Font object containing the font information (face+style+size)
See Also:
Font

setFont

public void setFont(java.awt.Font f)
This method sets the font details (font face,style and size) being used to write the legend entries.

Parameters:
f - a Font object containing the font information (face+style+size)
See Also:
Font

draw

public void draw(java.awt.Graphics2D g,
                 boolean useColours,
                 boolean useLineStyles,
                 boolean useSymbols)
This methods draws the legend on the given graphic context. There are 3 options for drawing, whether or not to use colours, whether or not to use line styles and whether or not to use symbols. These are the same drawing parameters used for drawing the plots of the corresponding graph.

Parameters:
g - the graphic context we will draw the annotation on
useColours - a boolean, true -> use colours, false -> use black
useLineStyles - a boolean, true -> use line styles, false -> use plain line
useSymbols - a boolean, true -> use symbols, false -> use only discs
See Also:
Graphics2D