Package org.opensourcephysics.display2d
Class CellLattice
java.lang.Object
org.opensourcephysics.display2d.CellLattice
- All Implemented Interfaces:
Drawable
,Measurable
,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
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates the default palette.Creates a new SiteLattice containing the same data as this lattice.void
draw
(DrawingPanel panel, 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
Determines if information is available to set min/max values.void
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
(Color[] colors) Sets the color palette.void
Sets the color for grid line boundariesvoid
setIndexedColor
(int i, 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.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
Methods inherited from interface org.opensourcephysics.display.Drawable
isInteractive
-
Constructor Details
-
CellLattice
public CellLattice()Constructor CellLattice -
CellLattice
public CellLattice(int nx, int ny) Constructor CellLattice- Parameters:
nx
-ny
-
-
-
Method Details
-
getXMin
public double getXMin()Description copied from interface:Measurable
Gets the minimum x needed to draw this object.- Specified by:
getXMin
in interfaceMeasurable
- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:Measurable
Gets the maximum x needed to draw this object.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:Measurable
Gets the minimum y needed to draw this object.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:Measurable
Gets the maximum y needed to draw this object.- Specified by:
getYMax
in interfaceMeasurable
- 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 interfaceMeasurable
- Returns:
- true if min/max values are valid
-
draw
Description copied from interface:Drawable
Draws a representation of an object in a drawing panel. -
getNx
public int getNx()Description copied from interface:ByteLattice
Gets the number of x entries.- Specified by:
getNx
in interfaceByteLattice
- Returns:
- nx
-
getNy
public int getNy()Description copied from interface:ByteLattice
Gets the number of y entries.- Specified by:
getNy
in interfaceByteLattice
- 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 interfaceByteLattice
- 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 interfaceByteLattice
- 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 interfaceByteLattice
- 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 interfaceByteLattice
- 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 interfaceByteLattice
-
randomize
public void randomize()Description copied from interface:ByteLattice
Randomizes the values.- Specified by:
randomize
in interfaceByteLattice
-
resizeLattice
public void resizeLattice(int nx, int ny) Description copied from interface:ByteLattice
Resizes the lattice.- Specified by:
resizeLattice
in interfaceByteLattice
-
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 interfaceByteLattice
- Parameters:
val
- int[][] the new valuesxmin
- doublexmax
- doubleymin
- doubleymax
- 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 interfaceByteLattice
- Parameters:
ix_offset
- the x offset into the latticeiy_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 interfaceByteLattice
-
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 interfaceByteLattice
- Parameters:
ix
- the x index of the columniy_offset
- the y offset in the columnval
- 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 interfaceByteLattice
- Parameters:
iy
- the y index of the rowix_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 interfaceByteLattice
-
setGridLineColor
Description copied from interface:ByteLattice
Sets the color for grid line boundaries- Specified by:
setGridLineColor
in interfaceByteLattice
-
showLegend
Description copied from interface:ByteLattice
Shows the color associated with each value.- Specified by:
showLegend
in interfaceByteLattice
- 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 interfaceByteLattice
-
setColorPalette
Description copied from interface:ByteLattice
Sets the color palette.- Specified by:
setColorPalette
in interfaceByteLattice
-
setIndexedColor
Description copied from interface:ByteLattice
Sets the color for a single index.- Specified by:
setIndexedColor
in interfaceByteLattice
-
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 interfaceByteLattice
-
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
- intiy_offset
- intval
- int[][]
-
setXMin
public void setXMin(double xmin) Description copied from interface:ByteLattice
Sets xmin.- Specified by:
setXMin
in interfaceByteLattice
- Parameters:
xmin
- double
-
setXMax
public void setXMax(double xmax) Description copied from interface:ByteLattice
Sets xmax.- Specified by:
setXMax
in interfaceByteLattice
- Parameters:
xmax
- double
-
setYMin
public void setYMin(double ymin) Description copied from interface:ByteLattice
Sets ymin.- Specified by:
setYMin
in interfaceByteLattice
- Parameters:
ymin
- double
-
setYMax
public void setYMax(double ymax) Description copied from interface:ByteLattice
Sets ymax.- Specified by:
setYMax
in interfaceByteLattice
- Parameters:
ymax
- double
-
createDefaultColors
public void createDefaultColors()Description copied from interface:ByteLattice
Creates the default palette.- Specified by:
createDefaultColors
in interfaceByteLattice
-