org.opensourcephysics.display2d
Class CellLatticePC

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

public class CellLatticePC
extends MeasuredImage
implements ByteLattice

A CellLattice displays an array where each array element can assume one of 256 values. Array values are drawn using an image raster. Each cell is a single pixel using an image that mathches the the lattice dimension. The image is then scaled so that every pixel is drawn as a rectangle. 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

Field Summary
 
Fields inherited from class org.opensourcephysics.display.MeasuredImage
image, visible, xmax, xmin, ymax, ymin
 
Constructor Summary
CellLatticePC()
          Constructs a cell lattice.
CellLatticePC(int _nx, int _ny)
          Constructs a cell lattice with the given size.
 
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 the lattice and the grid.
 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.
 int indexFromPoint(double x, double y)
          Determines the lattice index (row-major order) from given x and y world coordinates Returns -1 if the world coordinates are outside the lattice.
 void randomize()
          Randomizes the lattice values.
 void resizeLattice(int _nx, int _ny)
          Resizes the lattice using the given number of x and y entries.
 void setAll(byte[][] val)
          Sets a block of data to new values.
 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 byte values.
 void setBlock(int ix_offset, int iy_offset, int[][] val)
          Sets a block of data to 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 color)
          Sets the grid color.
 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 showGridLines)
          Outlines the lattice boundaries with a grid.
 void setValue(int ix, int iy, byte val)
          Sets the given x,y location to a value.
 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 org.opensourcephysics.display.MeasuredImage
getXMax, getXMin, getYMax, getYMin, isMeasured, setImage, setVisible, setXMax, setXMin, setYMax, setYMin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensourcephysics.display2d.ByteLattice
setVisible, setXMax, setXMin, setYMax, setYMin
 
Methods inherited from interface org.opensourcephysics.display.Measurable
getXMax, getXMin, getYMax, getYMin, isMeasured
 

Constructor Detail

CellLatticePC

public CellLatticePC()
Constructs a cell lattice. Cell values are -128 to 127.


CellLatticePC

public CellLatticePC(int _nx,
                     int _ny)
Constructs a cell lattice with the given size. Cell values are -128 to 127.

Parameters:
_nx - the number of values in x direction
_ny - the number of values in y direction
Method Detail

createSiteLattice

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


resizeLattice

public void resizeLattice(int _nx,
                          int _ny)
Resizes the lattice using the given number of x and y entries.

Specified by:
resizeLattice in interface ByteLattice
Parameters:
_nx - the number of x entries
_ny - the number of y entries

getNx

public int getNx()
Gets the number of x entries.

Specified by:
getNx in interface ByteLattice
Returns:
nx

getNy

public int getNy()
Gets the number of y entries.

Specified by:
getNy in interface ByteLattice
Returns:
ny

setMinMax

public void setMinMax(double xmin,
                      double xmax,
                      double ymin,
                      double ymax)
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
Overrides:
setMinMax in class MeasuredImage
Parameters:
xmin -
xmax -
ymin -
ymax -

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics g)
Draws the lattice and the grid.

Specified by:
draw in interface Drawable
Overrides:
draw in class MeasuredImage
Parameters:
panel -
g -

setAll

public void setAll(byte[][] val)
Sets a block of data to new values. The lattice is resized to fit the new data if needed.

Parameters:
val -

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(byte[][] val)
Sets a block of data starting at (0,0) to new values.

Specified by:
setBlock in interface ByteLattice
Parameters:
val -

setBlock

public void setBlock(int ix_offset,
                     int iy_offset,
                     byte[][] val)
Sets a block of data to byte values.

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

setBlock

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

Parameters:
ix_offset - the x offset into the lattice
iy_offset - the y offset into the lattice
val - the new values

setCol

public void setCol(int ix,
                   int iy_offset,
                   byte[] val)
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)
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
val -

setValue

public void setValue(int ix,
                     int iy,
                     byte val)
Sets the given x,y location to a value.

Specified by:
setValue in interface ByteLattice
Parameters:
ix -
iy -
val -

getValue

public byte getValue(int ix,
                     int iy)
Gets a value from the given location.

Specified by:
getValue in interface ByteLattice
Parameters:
ix -
iy -
Returns:
the value.

indexFromPoint

public int indexFromPoint(double x,
                          double y)
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
Parameters:
x -
y -
Returns:
index

xToIndex

public int xToIndex(double x)
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)
Gets closest index from the given y world coordinate.

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

setShowGridLines

public void setShowGridLines(boolean showGridLines)
Outlines the lattice boundaries with a grid.

Specified by:
setShowGridLines in interface ByteLattice
Parameters:
showGridLines -

randomize

public void randomize()
Randomizes the lattice values.

Specified by:
randomize in interface ByteLattice

showLegend

public javax.swing.JFrame showLegend()
Shows the color associated with each value.

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

setColorPalette

public void setColorPalette(java.awt.Color[] colors)
Sets the color palette.

Specified by:
setColorPalette in interface ByteLattice
Parameters:
colors -

setGridLineColor

public void setGridLineColor(java.awt.Color color)
Sets the grid color.

Specified by:
setGridLineColor in interface ByteLattice
Parameters:
color -

setIndexedColor

public void setIndexedColor(int i,
                            java.awt.Color color)
Sets the color for a single index.

Specified by:
setIndexedColor in interface ByteLattice
Parameters:
i -
color -

createDefaultColors

public void createDefaultColors()
Creates the default palette.

Specified by:
createDefaultColors in interface ByteLattice