Class ImageEvolutionPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ImageEvolutionPanel extends JPanel
Custom drawing panel for the image evolution GA demo.

Layout

The panel is divided into three horizontal regions:

  ┌──────────────────┬──────────────────┬──────────────────┐
  │                  │                  │                  │
  │   Best so far    │  Population grid │   Target image   │
  │   (full res)     │  (N thumbnails)  │                  │
  │                  │                  │                  │
  └──────────────────┴──────────────────┴──────────────────┘
 

The three regions share the available width equally. All rendering happens in paintComponent(Graphics) on the EDT, reading volatile references set by the simulation refresh callback.

Threading

updateBest(BufferedImage) and updatePopulation(List) are called from onSimulationRefresh, which is already on the EDT (guaranteed by SimulationEngine). No additional synchronization is needed.

See Also:
  • Constructor Details

    • ImageEvolutionPanel

      public ImageEvolutionPanel(BufferedImage targetImage)
      Construct the panel with the given target image.
      Parameters:
      targetImage - the image being approximated (non-null); displayed in the right-hand region and never modified
  • Method Details

    • updateBest

      public void updateBest(BufferedImage bestRendered, long generation, double bestFitness)
      Update the best-individual image and associated statistics label.

      Must be called on the EDT. The supplied image is displayed as-is; the caller is responsible for rendering it at an appropriate display resolution before calling this method.

      Parameters:
      bestRendered - full-resolution render of the best individual
      generation - current generation index
      bestFitness - current best fitness (higher = better, range [-1, 0])
    • updatePopulation

      public void updatePopulation(List<BufferedImage> thumbs)
      Update the population thumbnail grid.

      Must be called on the EDT. Each element of thumbs is a small pre-rendered image (e.g. 40×40 px) of one individual. The panel arranges them in a grid that fills the center region.

      Parameters:
      thumbs - thumbnail renders of all current individuals (non-null)
    • resetForTarget

      public void resetForTarget(BufferedImage targetImage)
      Replace the target and clear renders belonging to the previous run.
      Parameters:
      targetImage - new non-null target image
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent