1 package org.woehlke.computer.kurzweil.tabs.cca.view;
2
3 import org.woehlke.computer.kurzweil.tabs.cca.config.ObjectRegistry;
4
5 import javax.swing.*;
6 import java.awt.*;
7 import java.io.Serializable;
8
9
10
11
12
13
14
15
16
17
18
19 public class CyclicCellularAutomatonCanvas extends JComponent implements Serializable {
20
21 private static final long serialVersionUID = -3057254130516052936L;
22
23 private ObjectRegistry ctx;
24
25 public CyclicCellularAutomatonCanvas(ObjectRegistry ctx) {
26 this.ctx = ctx;
27 Dimension preferredSize = new Dimension(
28 (int) ctx.getConfig().getLatticeDimensions().getX(),
29 (int) ctx.getConfig().getLatticeDimensions().getY()
30 );
31 this.setPreferredSize(preferredSize);
32 }
33
34 public void paint(Graphics g) {
35 super.paintComponent(g);
36 for(int y = 0; y < ctx.getConfig().getLatticeDimensions().getY(); y++){
37 for(int x = 0; x < ctx.getConfig().getLatticeDimensions().getX(); x++){
38 int state = this.ctx.getLattice().getCellStatusFor(x,y);
39 Color stateColor = this.ctx.getColorScheme().getColorForState(state);
40 g.setColor(stateColor);
41 g.drawLine(x,y,x,y);
42 }
43 }
44 }
45
46 public void update(Graphics g) {
47 paint(g);
48 }
49
50 }