org.opensourcephysics.display2d
Class BinaryLattice

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

public class BinaryLattice
extends MeasuredImage
implements ByteLattice

A BinaryLattice is an array where each array element has a value of 0 or 1. 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, xmax, xmin, ymax, ymin
 
Constructor Summary
BinaryLattice(int _nx, int _ny)
          Constructs a binary lattice with the given size.
 
Method Summary
 void createDefaultColors()
          Creates the default palette.
 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)
          Resize the lattice.
 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 cells to new values.
 void setBlock(int x_offset, int y_offset, int[][] val)
          Sets a block of cells to new values.
 void setCol(int ix, int iy_offset, byte[] val)
          Sets a column of cells to new values.
 void setCol(int ix, int iy_offset, int[] val)
          Sets a column of cells to new values.
 void setColorPalette(java.awt.Color[] colors)
          Sets 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)
          Scales the grid to the given values in world units.
 void setRow(int iy, int ix_offset, byte[] val)
          Sets a row of cells to new values starting at the given column.
 void setRow(int iy, int ix_offset, int[] val)
          Sets a row of cells to new values starting at the given column.
 void setShowGrid(boolean showGrid)
          Sets the show grid option.
 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.
 void setValue(int ix, int iy, int val)
          Sets a cell at the given location to a new value.
 void setXMax(double _value)
          Sets xmax.
 void setXMin(double _value)
          Sets xmin.
 void setYMax(double _value)
          Sets ymax.
 void setYMin(double _value)
          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 org.opensourcephysics.display.MeasuredImage
getImage, getXMax, getXMin, getYMax, getYMin, isMeasured, setImage, setVisible
 
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
 
Methods inherited from interface org.opensourcephysics.display.Measurable
getXMax, getXMin, getYMax, getYMin, isMeasured
 

Constructor Detail

BinaryLattice

public BinaryLattice(int _nx,
                     int _ny)
Constructs a binary lattice with the given size.

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

createDefaultColors

public void createDefaultColors()
Creates the default palette.

Specified by:
createDefaultColors in interface ByteLattice

resizeLattice

public void resizeLattice(int _nx,
                          int _ny)
Resize the lattice.

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

setXMin

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

Specified by:
setXMin in interface ByteLattice
Overrides:
setXMin in class MeasuredImage
Parameters:
_value - double

setXMax

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

Specified by:
setXMax in interface ByteLattice
Overrides:
setXMax in class MeasuredImage
Parameters:
_value - double

setYMin

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

Specified by:
setYMin in interface ByteLattice
Overrides:
setYMin in class MeasuredImage
Parameters:
_value - double

setYMax

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

Specified by:
setYMax in interface ByteLattice
Overrides:
setYMax in class MeasuredImage
Parameters:
_value - double

randomize

public void randomize()
Randomizes the lattice values.

Specified by:
randomize in interface ByteLattice

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

setMinMax

public void setMinMax(double xmin,
                      double xmax,
                      double ymin,
                      double ymax)
Scales the grid to the given values in world units.

Specified by:
setMinMax in interface ByteLattice
Overrides:
setMinMax in class MeasuredImage
Parameters:
xmin -
xmax -
ymin -
ymax -

setBlock

public void setBlock(int x_offset,
                     int y_offset,
                     int[][] val)
Sets a block of cells to new values. A cell is set to 1 if the value is >0; the cell is set to zero otherwise

Parameters:
x_offset - int
y_offset - int
val - int[][]

setBlock

public void setBlock(int ix_offset,
                     int iy_offset,
                     byte[][] val)
Sets a block of cells to new values. A cell is set to 1 if the value is >0; the cell is set to zero otherwise

Specified by:
setBlock in interface ByteLattice
Parameters:
ix_offset -
iy_offset -
val - the value array

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 -

setCol

public void setCol(int ix,
                   int iy_offset,
                   int[] val)
Sets a column of cells to new values. A cell is set to 1 if the value is >0; the cell is set to zero otherwise

Parameters:
ix -
iy_offset -
val - the array of values

setCol

public void setCol(int ix,
                   int iy_offset,
                   byte[] val)
Sets a column of cells to new values. A cell is set to 1 if the value is >0; the cell is set to zero otherwise

Specified by:
setCol in interface ByteLattice
Parameters:
ix -
iy_offset -
val - the array of values

setRow

public void setRow(int iy,
                   int ix_offset,
                   int[] val)
Sets a row of cells to new values starting at the given column. A cell is set to 1 if the value is >0; the cell is set to zero otherwise

Parameters:
iy -
ix_offset - the x offset
val - the value array

setRow

public void setRow(int iy,
                   int ix_offset,
                   byte[] val)
Sets a row of cells to new values starting at the given column. A cell is set to 1 if the value is >0; the cell is set to zero otherwise

Specified by:
setRow in interface ByteLattice
Parameters:
iy -
ix_offset - the x offset
val - the value array

setValue

public void setValue(int ix,
                     int iy,
                     int val)
Sets a cell at the given location to a new value. A cell should take on a value of 0 or 1.

Parameters:
ix -
iy -
val -

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

getValue

public byte getValue(int ix,
                     int iy)
Gets a value from the given location. Cell values are zero or one.

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

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

setShowGrid

public void setShowGrid(boolean showGrid)
Sets the show grid option.

Parameters:
showGrid -

setColorPalette

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

Specified by:
setColorPalette in interface ByteLattice
Parameters:
colors -

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 -

setGridLineColor

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

Specified by:
setGridLineColor in interface ByteLattice
Parameters:
color -

setShowGridLines

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

Specified by:
setShowGridLines in interface ByteLattice

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

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

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