Package org.opensourcephysics.display2d
Class BinaryLattice
java.lang.Object
org.opensourcephysics.display.MeasuredImage
org.opensourcephysics.display2d.BinaryLattice
- All Implemented Interfaces:
Drawable,Measurable,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
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryLattice(int _nx, int _ny) Constructs a binary lattice with the given size. -
Method Summary
Modifier and TypeMethodDescriptionvoidCreates the default palette.voiddraw(DrawingPanel panel, Graphics g) Draws the lattice and the grid.intgetNx()Gets the number of x entries.intgetNy()Gets the number of y entries.bytegetValue(int ix, int iy) Gets a value from the given location.intindexFromPoint(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.voidRandomizes the lattice values.voidresizeLattice(int _nx, int _ny) Resize the lattice.voidsetAll(byte[][] val) Sets a block of data to new values.voidsetAll(byte[][] val, double xmin, double xmax, double ymin, double ymax) Sets the lattice values and scale.voidsetBlock(byte[][] val) Sets a block of data starting at (0,0) to new values.voidsetBlock(int ix_offset, int iy_offset, byte[][] val) Sets a block of cells to new values.voidsetBlock(int x_offset, int y_offset, int[][] val) Sets a block of cells to new values.voidsetCol(int ix, int iy_offset, byte[] val) Sets a column of cells to new values.voidsetCol(int ix, int iy_offset, int[] val) Sets a column of cells to new values.voidsetColorPalette(Color[] colors) Sets color palette.voidsetGridLineColor(Color color) Sets the grid color.voidsetIndexedColor(int i, Color color) Sets the color for a single index.voidsetMinMax(double xmin, double xmax, double ymin, double ymax) Scales the grid to the given values in world units.voidsetRow(int iy, int ix_offset, byte[] val) Sets a row of cells to new values starting at the given column.voidsetRow(int iy, int ix_offset, int[] val) Sets a row of cells to new values starting at the given column.voidsetShowGrid(boolean showGrid) Sets the show grid option.voidsetShowGridLines(boolean showGridLines) Outlines the lattice boundaries with a grid.voidsetValue(int ix, int iy, byte val) Sets the given x,y location to a value.voidsetValue(int ix, int iy, int val) Sets a cell at the given location to a new value.voidsetXMax(double _value) Sets xmax.voidsetXMin(double _value) Sets xmin.voidsetYMax(double _value) Sets ymax.voidsetYMin(double _value) Sets ymin.Shows the color associated with each value.intxToIndex(double x) Gets closest index from the given x world coordinate.intyToIndex(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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensourcephysics.display2d.ByteLattice
setVisibleMethods inherited from interface org.opensourcephysics.display.Drawable
isInteractiveMethods inherited from interface org.opensourcephysics.display.Measurable
getXMax, getXMin, getYMax, getYMin, isMeasured
-
Constructor Details
-
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 Details
-
createDefaultColors
public void createDefaultColors()Creates the default palette.- Specified by:
createDefaultColorsin interfaceByteLattice
-
resizeLattice
public void resizeLattice(int _nx, int _ny) Resize the lattice.- Specified by:
resizeLatticein interfaceByteLattice- Parameters:
_nx- number of x sites_ny- number of y sites
-
setXMin
public void setXMin(double _value) Description copied from interface:ByteLatticeSets xmin.- Specified by:
setXMinin interfaceByteLattice- Overrides:
setXMinin classMeasuredImage- Parameters:
_value- double
-
setXMax
public void setXMax(double _value) Description copied from interface:ByteLatticeSets xmax.- Specified by:
setXMaxin interfaceByteLattice- Overrides:
setXMaxin classMeasuredImage- Parameters:
_value- double
-
setYMin
public void setYMin(double _value) Description copied from interface:ByteLatticeSets ymin.- Specified by:
setYMinin interfaceByteLattice- Overrides:
setYMinin classMeasuredImage- Parameters:
_value- double
-
setYMax
public void setYMax(double _value) Description copied from interface:ByteLatticeSets ymax.- Specified by:
setYMaxin interfaceByteLattice- Overrides:
setYMaxin classMeasuredImage- Parameters:
_value- double
-
randomize
public void randomize()Randomizes the lattice values.- Specified by:
randomizein interfaceByteLattice
-
draw
Draws the lattice and the grid.- Specified by:
drawin interfaceDrawable- Overrides:
drawin classMeasuredImage- 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:
setAllin interfaceByteLattice- Parameters:
val- int[][] the new valuesxmin- doublexmax- doubleymin- doubleymax- 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:
setMinMaxin interfaceByteLattice- Overrides:
setMinMaxin classMeasuredImage- 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- inty_offset- intval- 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:
setBlockin interfaceByteLattice- 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:
setBlockin interfaceByteLattice- 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:
setColin interfaceByteLattice- 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 offsetval- 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:
setRowin interfaceByteLattice- Parameters:
iy-ix_offset- the x offsetval- 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:ByteLatticeSets the given x,y location to a value.- Specified by:
setValuein interfaceByteLattice
-
getValue
public byte getValue(int ix, int iy) Gets a value from the given location. Cell values are zero or one.- Specified by:
getValuein interfaceByteLattice- Parameters:
ix-iy-- Returns:
- the cell value.
-
getNx
public int getNx()Gets the number of x entries.- Specified by:
getNxin interfaceByteLattice- Returns:
- nx
-
getNy
public int getNy()Gets the number of y entries.- Specified by:
getNyin interfaceByteLattice- Returns:
- ny
-
setShowGrid
public void setShowGrid(boolean showGrid) Sets the show grid option.- Parameters:
showGrid-
-
setColorPalette
Sets color palette.- Specified by:
setColorPalettein interfaceByteLattice- Parameters:
colors-
-
setIndexedColor
Sets the color for a single index.- Specified by:
setIndexedColorin interfaceByteLattice- Parameters:
i-color-
-
setGridLineColor
Sets the grid color.- Specified by:
setGridLineColorin interfaceByteLattice- Parameters:
color-
-
setShowGridLines
public void setShowGridLines(boolean showGridLines) Description copied from interface:ByteLatticeOutlines the lattice boundaries with a grid.- Specified by:
setShowGridLinesin interfaceByteLattice
-
xToIndex
public int xToIndex(double x) Gets closest index from the given x world coordinate.- Specified by:
xToIndexin interfaceByteLattice- 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:
yToIndexin interfaceByteLattice- 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:
indexFromPointin interfaceByteLattice- Parameters:
x-y-- Returns:
- index
-
showLegend
Description copied from interface:ByteLatticeShows the color associated with each value.- Specified by:
showLegendin interfaceByteLattice- Returns:
- the JFrame containing the legend
-