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 TypeMethodDescriptionvoidCreates the default palette.Creates a new SiteLattice containing the same data as this lattice.voiddraw(DrawingPanel panel, Graphics g) Draws a representation of an object in a drawing panel.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.doublegetXMax()Gets the maximum x needed to draw this object.doublegetXMin()Gets the minimum x needed to draw this object.doublegetYMax()Gets the maximum y needed to draw this object.doublegetYMin()Gets the minimum y needed to draw this object.intindexFromPoint(double x, double y) Determines the lattice index (row-major order) from given x and y world coordinates.booleanDetermines if information is available to set min/max values.voidRandomizes the values.voidresizeLattice(int nx, int ny) Resizes the lattice.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 data to new values.voidsetBlock(int ix_offset, int iy_offset, int[][] val) Sets a block of cells using integer values.voidsetCol(int ix, int iy_offset, byte[] val) Sets a column to new values.voidsetColorPalette(Color[] colors) Sets the color palette.voidSets the color for grid line boundariesvoidsetIndexedColor(int i, Color color) Sets the color for a single index.voidsetMinMax(double xmin, double xmax, double ymin, double ymax) Assigns a scale to the lattice in world units.voidsetRow(int iy, int ix_offset, byte[] val) Sets a row to new values.voidsetShowGridLines(boolean show) Outlines the lattice boundaries with a grid.voidsetValue(int ix, int iy, byte val) Sets the given x,y location to a value.voidsetVisible(boolean isVisible) Sets the visibility of the lattice.voidsetXMax(double xmax) Sets xmax.voidsetXMin(double xmin) Sets xmin.voidsetYMax(double ymax) Sets ymax.voidsetYMin(double ymin) 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:MeasurableGets the minimum x needed to draw this object.- Specified by:
getXMinin interfaceMeasurable- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:MeasurableGets the maximum x needed to draw this object.- Specified by:
getXMaxin interfaceMeasurable- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:MeasurableGets the minimum y needed to draw this object.- Specified by:
getYMinin interfaceMeasurable- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:MeasurableGets the maximum y needed to draw this object.- Specified by:
getYMaxin interfaceMeasurable- Returns:
- minimum
-
isMeasured
public boolean isMeasured()Description copied from interface:MeasurableDetermines if information is available to set min/max values. Objects that store data should return false if data is null.- Specified by:
isMeasuredin interfaceMeasurable- Returns:
- true if min/max values are valid
-
draw
Description copied from interface:DrawableDraws a representation of an object in a drawing panel. -
getNx
public int getNx()Description copied from interface:ByteLatticeGets the number of x entries.- Specified by:
getNxin interfaceByteLattice- Returns:
- nx
-
getNy
public int getNy()Description copied from interface:ByteLatticeGets the number of y entries.- Specified by:
getNyin interfaceByteLattice- Returns:
- ny
-
indexFromPoint
public int indexFromPoint(double x, double y) Description copied from interface:ByteLatticeDetermines 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- Returns:
- index
-
xToIndex
public int xToIndex(double x) Description copied from interface:ByteLatticeGets 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) Description copied from interface:ByteLatticeGets closest index from the given y world coordinate.- Specified by:
yToIndexin interfaceByteLattice- Parameters:
y- double the coordinate- Returns:
- int the index
-
getValue
public byte getValue(int ix, int iy) Description copied from interface:ByteLatticeGets a value from the given location.- Specified by:
getValuein interfaceByteLattice- Returns:
- the value.
-
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
-
randomize
public void randomize()Description copied from interface:ByteLatticeRandomizes the values.- Specified by:
randomizein interfaceByteLattice
-
resizeLattice
public void resizeLattice(int nx, int ny) Description copied from interface:ByteLatticeResizes the lattice.- Specified by:
resizeLatticein 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:
setAllin 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:ByteLatticeSets a block of data to new values.- Specified by:
setBlockin 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:ByteLatticeSets a block of data starting at (0,0) to new values.- Specified by:
setBlockin interfaceByteLattice
-
setCol
public void setCol(int ix, int iy_offset, byte[] val) Description copied from interface:ByteLatticeSets a column to new values.- Specified by:
setColin 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:ByteLatticeSets a row to new values.- Specified by:
setRowin 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:ByteLatticeOutlines the lattice boundaries with a grid.- Specified by:
setShowGridLinesin interfaceByteLattice
-
setGridLineColor
Description copied from interface:ByteLatticeSets the color for grid line boundaries- Specified by:
setGridLineColorin interfaceByteLattice
-
showLegend
Description copied from interface:ByteLatticeShows the color associated with each value.- Specified by:
showLegendin interfaceByteLattice- Returns:
- the JFrame containing the legend
-
setVisible
public void setVisible(boolean isVisible) Description copied from interface:ByteLatticeSets the visibility of the lattice. Drawing will be disabled if visible is false.- Specified by:
setVisiblein interfaceByteLattice
-
setColorPalette
Description copied from interface:ByteLatticeSets the color palette.- Specified by:
setColorPalettein interfaceByteLattice
-
setIndexedColor
Description copied from interface:ByteLatticeSets the color for a single index.- Specified by:
setIndexedColorin interfaceByteLattice
-
setMinMax
public void setMinMax(double xmin, double xmax, double ymin, double ymax) Description copied from interface:ByteLatticeAssigns a scale to the lattice in world units. This method does not change lattice values; it assigns units corners of the lattice.- Specified by:
setMinMaxin 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:ByteLatticeSets xmin.- Specified by:
setXMinin interfaceByteLattice- Parameters:
xmin- double
-
setXMax
public void setXMax(double xmax) Description copied from interface:ByteLatticeSets xmax.- Specified by:
setXMaxin interfaceByteLattice- Parameters:
xmax- double
-
setYMin
public void setYMin(double ymin) Description copied from interface:ByteLatticeSets ymin.- Specified by:
setYMinin interfaceByteLattice- Parameters:
ymin- double
-
setYMax
public void setYMax(double ymax) Description copied from interface:ByteLatticeSets ymax.- Specified by:
setYMaxin interfaceByteLattice- Parameters:
ymax- double
-
createDefaultColors
public void createDefaultColors()Description copied from interface:ByteLatticeCreates the default palette.- Specified by:
createDefaultColorsin interfaceByteLattice
-