Class SiteLattice

java.lang.Object
org.opensourcephysics.display.Grid
org.opensourcephysics.display2d.SiteLattice
All Implemented Interfaces:
Drawable, Measurable, ByteLattice

public class SiteLattice extends Grid implements Measurable, ByteLattice
A SiteLattice displays an array where each array element can assume one of 256 values. Array values are drawn as non-overlapping circles. 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, Joshua Gould
  • Field Summary

    Fields inherited from class org.opensourcephysics.display.Grid

    color, dx, dy, generalPath, nx, ny, xmax, xmin, ymax, ymin
  • Constructor Summary

    Constructors
    Constructor
    Description
    SiteLattice(int sx, int sy)
    Constructs a Site lattice with the given size.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new CellLattice containing the same data as this lattice.
    void
    Creates the default palette.
    void
    Draws the lattice and the grid.
    int
    Gets the number of x entries.
    int
    Gets the number of y entries.
    byte
    getValue(int col, int row)
    Gets a lattice site value.
    double
    Method getXMax
    double
    Method getXMin
    double
    Method getYMax
    double
    Method getYMin
    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.
    boolean
    Method isMeasured
    void
    Randomizes the lattice values.
    void
    resizeLattice(int _nx, int _ny)
    Resizes 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 cells to new values.
    void
    setBlock(int ix_offset, int iy_offset, byte[][] val)
    Sets a block of cells using byte 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
    Sets the color palette.
    void
    Sets the grid line color.
    void
    setIndexedColor(int i, Color color)
    Sets the color for a single index.
    void
    setRow(int iy, int ix_offset, byte[] val)
    Sets a row to new values.
    void
    setShowGridLines(boolean showGridLines)
    Sets the visibility of the grid connecting the sites.
    void
    setShowVisible(boolean isVisible)
    Sets the visibility of the sites.
    void
    setValue(int ix, int iy, byte val)
    Sets the given x,y location to a new value.
    void
    setVisible(boolean isVisible)
    Sets the visibility of the lattice.
    void
    setXMax(double _value)
    Sets xmax.
    void
    setXMin(double _value)
    Sets xmin.
    void
    setYMax(double _value)
    Sets ymax.
    void
    setYMin(double _value)
    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 org.opensourcephysics.display.Grid

    getCellPoint, getClosestGridPoint, getColor, getDx, getDy, isVisible, setColor, setMinMax

    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

    setMinMax

    Methods inherited from interface org.opensourcephysics.display.Drawable

    isInteractive
  • Constructor Details

    • SiteLattice

      public SiteLattice(int sx, int sy)
      Constructs a Site lattice with the given size. Site values are -128 to 127.
      Parameters:
      sx - sites in x direction
      sy - sites in y direction
  • Method Details

    • resizeLattice

      public void resizeLattice(int _nx, int _ny)
      Description copied from interface: ByteLattice
      Resizes the lattice.
      Specified by:
      resizeLattice in interface ByteLattice
    • createCellLattice

      public ByteLattice createCellLattice()
      Creates a new CellLattice containing the same data as this lattice.
    • 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
    • setVisible

      public void setVisible(boolean isVisible)
      Sets the visibility of the lattice. Drawing will be disabled if visible is false.
      Specified by:
      setVisible in interface ByteLattice
      Overrides:
      setVisible in class Grid
      Parameters:
      isVisible -
    • draw

      public void draw(DrawingPanel panel, Graphics g)
      Draws the lattice and the grid.
      Specified by:
      draw in interface Drawable
      Overrides:
      draw in class Grid
      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(int ix_offset, int iy_offset, byte[][] val)
      Sets a block of cells using byte values.
      Specified by:
      setBlock in interface ByteLattice
      Parameters:
      ix_offset - int
      iy_offset - int
      val - byte[][]
    • setBlock

      public void setBlock(int ix_offset, int iy_offset, int[][] val)
      Sets a block of cells using integer values.
      Parameters:
      ix_offset - int
      iy_offset - int
      val - int[][]
    • setBlock

      public void setBlock(byte[][] val)
      Sets a block of cells to new values.
      Specified by:
      setBlock in interface ByteLattice
      Parameters:
      val -
    • 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 new value.
      Specified by:
      setValue in interface ByteLattice
      Parameters:
      ix -
      iy -
      val -
    • getValue

      public byte getValue(int col, int row)
      Gets a lattice site value.
      Specified by:
      getValue in interface ByteLattice
      Parameters:
      row -
      col -
      Returns:
      the cell 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
    • setShowVisible

      public void setShowVisible(boolean isVisible)
      Sets the visibility of the sites. Drawing will be disabled if visible is false.
      Parameters:
      isVisible -
    • setShowGridLines

      public void setShowGridLines(boolean showGridLines)
      Sets the visibility of the grid connecting the sites.
      Specified by:
      setShowGridLines in interface ByteLattice
      Parameters:
      showGridLines -
    • randomize

      public void randomize()
      Randomizes the lattice values.
      Specified by:
      randomize in interface ByteLattice
    • showLegend

      public 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(Color[] _colors)
      Sets the color palette.
      Specified by:
      setColorPalette in interface ByteLattice
      Parameters:
      _colors -
    • setGridLineColor

      public void setGridLineColor(Color _color)
      Sets the grid line color.
      Specified by:
      setGridLineColor in interface ByteLattice
      Parameters:
      _color -
    • setIndexedColor

      public void setIndexedColor(int i, Color color)
      Sets the color for a single index.
      Specified by:
      setIndexedColor in interface ByteLattice
      Parameters:
      i -
      color -
    • isMeasured

      public boolean isMeasured()
      Method isMeasured
      Specified by:
      isMeasured in interface Measurable
      Returns:
      measured flag
    • getXMin

      public double getXMin()
      Method getXMin
      Specified by:
      getXMin in interface Measurable
      Overrides:
      getXMin in class Grid
      Returns:
      x min
    • getXMax

      public double getXMax()
      Method getXMax
      Specified by:
      getXMax in interface Measurable
      Overrides:
      getXMax in class Grid
      Returns:
      x max
    • getYMin

      public double getYMin()
      Method getYMin
      Specified by:
      getYMin in interface Measurable
      Overrides:
      getYMin in class Grid
      Returns:
      y min
    • getYMax

      public double getYMax()
      Method getYMax
      Specified by:
      getYMax in interface Measurable
      Overrides:
      getYMax in class Grid
      Returns:
      y max
    • setXMin

      public void setXMin(double _value)
      Description copied from interface: ByteLattice
      Sets xmin.
      Specified by:
      setXMin in interface ByteLattice
      Parameters:
      _value - double
    • setXMax

      public void setXMax(double _value)
      Description copied from interface: ByteLattice
      Sets xmax.
      Specified by:
      setXMax in interface ByteLattice
      Parameters:
      _value - double
    • setYMin

      public void setYMin(double _value)
      Description copied from interface: ByteLattice
      Sets ymin.
      Specified by:
      setYMin in interface ByteLattice
      Parameters:
      _value - double
    • setYMax

      public void setYMax(double _value)
      Description copied from interface: ByteLattice
      Sets ymax.
      Specified by:
      setYMax in interface ByteLattice
      Parameters:
      _value - double
    • createDefaultColors

      public void createDefaultColors()
      Creates the default palette.
      Specified by:
      createDefaultColors in interface ByteLattice