org.opensourcephysics.display2d
Class CellLattice

java.lang.Object
  extended by org.opensourcephysics.display2d.CellLattice
All Implemented Interfaces:
Drawable, Measurable, ByteLattice

public class CellLattice
extends java.lang.Object
implements ByteLattice

A CellLattice that displays an array where each array element can assume one of 256 values. Values can be set between -128 and 127. Because byte values larger than 127 overflow to negative, values can also be set between 0 and 255. The lattice is drawn as an array of rectangles to distinguish between the two possible values.

Version:
1.0
Author:
Wolfgang Christian

Constructor Summary
CellLattice()
          Constructor CellLattice
CellLattice(int nx, int ny)
          Constructor CellLattice
 
Method Summary
 void createDefaultColors()
          Creates the default palette.
 SiteLattice createSiteLattice()
          Creates a new SiteLattice containing the same data as this lattice.
 void draw(DrawingPanel panel, java.awt.Graphics g)
          Draws a representation of an object in a drawing panel.
 int getNx()
          Gets the number of x entries.
 int getNy()
          Gets the number of y entries.
 byte getValue(int ix, int iy)
          Gets a value from the given location.
 double getXMax()
          Gets the maximum x needed to draw this object.
 double getXMin()
          Gets the minimum x needed to draw this object.
 double getYMax()
          Gets the maximum y needed to draw this object.
 double getYMin()
          Gets the minimum y needed to draw this object.
 int indexFromPoint(double x, double y)
          Determines the lattice index (row-major order) from given x and y world coordinates.
 boolean isMeasured()
          Determines if information is available to set min/max values.
 void randomize()
          Randomizes the values.
 void resizeLattice(int nx, int ny)
          Resizes the lattice.
 void setAll(byte[][] val, double xmin, double xmax, double ymin, double ymax)
          Sets the lattice values and scale.
 void setBlock(byte[][] val)
          Sets a block of data starting at (0,0) to new values.
 void setBlock(int ix_offset, int iy_offset, byte[][] val)
          Sets a block of data to new values.
 void setBlock(int ix_offset, int iy_offset, int[][] val)
          Sets a block of cells using integer values.
 void setCol(int ix, int iy_offset, byte[] val)
          Sets a column to new values.
 void setColorPalette(java.awt.Color[] colors)
          Sets the color palette.
 void setGridLineColor(java.awt.Color c)
          Sets the color for grid line boundaries
 void setIndexedColor(int i, java.awt.Color color)
          Sets the color for a single index.
 void setMinMax(double xmin, double xmax, double ymin, double ymax)
          Assigns a scale to the lattice in world units.
 void setRow(int iy, int ix_offset, byte[] val)
          Sets a row to new values.
 void setShowGridLines(boolean show)
          Outlines the lattice boundaries with a grid.
 void setValue(int ix, int iy, byte val)
          Sets the given x,y location to a value.
 void setVisible(boolean isVisible)
          Sets the visibility of the lattice.
 void setXMax(double xmax)
          Sets xmax.
 void setXMin(double xmin)
          Sets xmin.
 void setYMax(double ymax)
          Sets ymax.
 void setYMin(double ymin)
          Sets ymin.
 javax.swing.JFrame showLegend()
          Shows the color associated with each value.
 int xToIndex(double x)
          Gets closest index from the given x world coordinate.
 int yToIndex(double y)
          Gets closest index from the given y world coordinate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CellLattice

public CellLattice()
Constructor CellLattice


CellLattice

public CellLattice(int nx,
                   int ny)
Constructor CellLattice

Parameters:
nx -
ny -
Method Detail

getXMin

public double getXMin()
Description copied from interface: Measurable
Gets the minimum x needed to draw this object.

Specified by:
getXMin in interface Measurable
Returns:
minimum

getXMax

public double getXMax()
Description copied from interface: Measurable
Gets the maximum x needed to draw this object.

Specified by:
getXMax in interface Measurable
Returns:
maximum

getYMin

public double getYMin()
Description copied from interface: Measurable
Gets the minimum y needed to draw this object.

Specified by:
getYMin in interface Measurable
Returns:
minimum

getYMax

public double getYMax()
Description copied from interface: Measurable
Gets the maximum y needed to draw this object.

Specified by:
getYMax in interface Measurable
Returns:
minimum

isMeasured

public boolean isMeasured()
Description copied from interface: Measurable
Determines if information is available to set min/max values. Objects that store data should return false if data is null.

Specified by:
isMeasured in interface Measurable
Returns:
true if min/max values are valid

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics g)
Description copied from interface: Drawable
Draws a representation of an object in a drawing panel.

Specified by:
draw in interface Drawable

getNx

public int getNx()
Description copied from interface: ByteLattice
Gets the number of x entries.

Specified by:
getNx in interface ByteLattice
Returns:
nx

getNy

public int getNy()
Description copied from interface: ByteLattice
Gets the number of y entries.

Specified by:
getNy in interface ByteLattice
Returns:
ny

indexFromPoint

public int indexFromPoint(double x,
                          double y)
Description copied from interface: ByteLattice
Determines the lattice index (row-major order) from given x and y world coordinates. Returns -1 if the world coordinates are outside the lattice.

Specified by:
indexFromPoint in interface ByteLattice
Returns:
index

xToIndex

public int xToIndex(double x)
Description copied from interface: ByteLattice
Gets closest index from the given x world coordinate.

Specified by:
xToIndex in interface ByteLattice
Parameters:
x - double the coordinate
Returns:
int the index

yToIndex

public int yToIndex(double y)
Description copied from interface: ByteLattice
Gets closest index from the given y world coordinate.

Specified by:
yToIndex in interface ByteLattice
Parameters:
y - double the coordinate
Returns:
int the index

getValue

public byte getValue(int ix,
                     int iy)
Description copied from interface: ByteLattice
Gets a value from the given location.

Specified by:
getValue in interface ByteLattice
Returns:
the value.

setValue

public void setValue(int ix,
                     int iy,
                     byte val)
Description copied from interface: ByteLattice
Sets the given x,y location to a value.

Specified by:
setValue in interface ByteLattice

randomize

public void randomize()
Description copied from interface: ByteLattice
Randomizes the values.

Specified by:
randomize in interface ByteLattice

resizeLattice

public void resizeLattice(int nx,
                          int ny)
Description copied from interface: ByteLattice
Resizes the lattice.

Specified by:
resizeLattice in interface ByteLattice

setAll

public void setAll(byte[][] val,
                   double xmin,
                   double xmax,
                   double ymin,
                   double ymax)
Sets the lattice values and scale. The lattice is resized to fit the new data if needed.

Specified by:
setAll in interface ByteLattice
Parameters:
val - int[][] the new values
xmin - double
xmax - double
ymin - double
ymax - double

setBlock

public void setBlock(int ix_offset,
                     int iy_offset,
                     byte[][] val)
Description copied from interface: ByteLattice
Sets a block of data to new values.

Specified by:
setBlock in interface ByteLattice
Parameters:
ix_offset - the x offset into the lattice
iy_offset - the y offset into the lattice

setBlock

public void setBlock(byte[][] val)
Description copied from interface: ByteLattice
Sets a block of data starting at (0,0) to new values.

Specified by:
setBlock in interface ByteLattice

setCol

public void setCol(int ix,
                   int iy_offset,
                   byte[] val)
Description copied from interface: ByteLattice
Sets a column to new values.

Specified by:
setCol in interface ByteLattice
Parameters:
ix - the x index of the column
iy_offset - the y offset in the column
val - values in column

setRow

public void setRow(int iy,
                   int ix_offset,
                   byte[] val)
Description copied from interface: ByteLattice
Sets a row to new values.

Specified by:
setRow in interface ByteLattice
Parameters:
iy - the y index of the row
ix_offset - the x offset in the row

setShowGridLines

public void setShowGridLines(boolean show)
Description copied from interface: ByteLattice
Outlines the lattice boundaries with a grid.

Specified by:
setShowGridLines in interface ByteLattice

setGridLineColor

public void setGridLineColor(java.awt.Color c)
Description copied from interface: ByteLattice
Sets the color for grid line boundaries

Specified by:
setGridLineColor in interface ByteLattice

showLegend

public javax.swing.JFrame showLegend()
Description copied from interface: ByteLattice
Shows the color associated with each value.

Specified by:
showLegend in interface ByteLattice
Returns:
the JFrame containing the legend

setVisible

public void setVisible(boolean isVisible)
Description copied from interface: ByteLattice
Sets the visibility of the lattice. Drawing will be disabled if visible is false.

Specified by:
setVisible in interface ByteLattice

setColorPalette

public void setColorPalette(java.awt.Color[] colors)
Description copied from interface: ByteLattice
Sets the color palette.

Specified by:
setColorPalette in interface ByteLattice

setIndexedColor

public void setIndexedColor(int i,
                            java.awt.Color color)
Description copied from interface: ByteLattice
Sets the color for a single index.

Specified by:
setIndexedColor in interface ByteLattice

setMinMax

public void setMinMax(double xmin,
                      double xmax,
                      double ymin,
                      double ymax)
Description copied from interface: ByteLattice
Assigns a scale to the lattice in world units. This method does not change lattice values; it assigns units corners of the lattice.

Specified by:
setMinMax in interface ByteLattice

createSiteLattice

public SiteLattice createSiteLattice()
Creates a new SiteLattice containing the same data as this lattice.


setBlock

public void setBlock(int ix_offset,
                     int iy_offset,
                     int[][] val)
Sets a block of cells using integer values.

Parameters:
ix_offset - int
iy_offset - int
val - int[][]

setXMin

public void setXMin(double xmin)
Description copied from interface: ByteLattice
Sets xmin.

Specified by:
setXMin in interface ByteLattice
Parameters:
xmin - double

setXMax

public void setXMax(double xmax)
Description copied from interface: ByteLattice
Sets xmax.

Specified by:
setXMax in interface ByteLattice
Parameters:
xmax - double

setYMin

public void setYMin(double ymin)
Description copied from interface: ByteLattice
Sets ymin.

Specified by:
setYMin in interface ByteLattice
Parameters:
ymin - double

setYMax

public void setYMax(double ymax)
Description copied from interface: ByteLattice
Sets ymax.

Specified by:
setYMax in interface ByteLattice
Parameters:
ymax - double

createDefaultColors

public void createDefaultColors()
Description copied from interface: ByteLattice
Creates the default palette.

Specified by:
createDefaultColors in interface ByteLattice