1 package org.woehlke.computer.kurzweil.tabs.simulatedevolution.views;
2
3 import lombok.EqualsAndHashCode;
4 import lombok.Getter;
5 import lombok.ToString;
6 import lombok.extern.java.Log;
7 import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
8 import org.woehlke.computer.kurzweil.commons.Updateable;
9 import org.woehlke.computer.kurzweil.commons.layouts.FlowLayoutCenter;
10 import org.woehlke.computer.kurzweil.commons.widgets.SubTab;
11 import org.woehlke.computer.kurzweil.commons.widgets.SubTabImpl;
12 import org.woehlke.computer.kurzweil.tabs.simulatedevolution.config.SimulatedEvolution;
13 import org.woehlke.computer.kurzweil.tabs.simulatedevolution.config.SimulatedEvolutionContext;
14 import org.woehlke.computer.kurzweil.tabs.simulatedevolution.model.population.CellPopulationRecord;
15
16 import javax.swing.*;
17 import javax.swing.border.CompoundBorder;
18 import java.awt.*;
19
20 import static org.woehlke.computer.kurzweil.tabs.simulatedevolution.model.cell.CellLifeCycleStatus.*;
21
22 @Log
23 @Getter
24 @ToString(callSuper = true,exclude = {"tabCtx","border","layout","layoutSubPanel"})
25 @EqualsAndHashCode(callSuper=true,exclude = {"tabCtx","border","layout","layoutSubPanel"})
26 public class GetPopulationLifeCyclePanel extends SubTabImpl
27 implements SimulatedEvolution, SubTab, Updateable {
28
29 private static final long serialVersionUID = 7526471155622776147L;
30
31 private final SimulatedEvolutionContext tabCtx;
32
33 private final JTextField youngCellsElement = new JTextField("0",4);
34 private final JTextField youngAndFatCellsElement = new JTextField("0",4);
35 private final JTextField fullAgeCellsElement = new JTextField("0",4);
36 private final JTextField hungryCellsElement = new JTextField("0",4);
37 private final JTextField oldCellsElement = new JTextField("0",4);
38
39 public GetPopulationLifeCyclePanel(
40 SimulatedEvolutionContext tabCtx
41 ) {
42 super(
43 tabCtx.getCtx().getProperties().getSimulatedevolution().getPopulation().getPanelLifeCycleStatistics(),
44 tabCtx.getCtx().getProperties()
45 );
46 this.tabCtx = tabCtx;
47 FlowLayout layoutSubPanel = new FlowLayout();
48 this.setLayout(layoutSubPanel);
49 String borderLabel =
50 this.tabCtx.getCtx().getProperties().getSimulatedevolution().getPopulation().getPanelPopulationStatistics();
51 FlowLayoutCenter layout = new FlowLayoutCenter();
52 CompoundBorder border = tabCtx.getCtx().getBottomButtonsPanelBorder(borderLabel);
53 this.setLayout(layout);
54 this.setBorder(border);
55 ComputerKurzweilProperties.SimulatedEvolution.Population cfg =
56 this.tabCtx.getCtx().getProperties().getSimulatedevolution().getPopulation();
57 JLabel youngCellsLabel = new JLabel(cfg.getYoungCellsLabel());
58 JLabel youngAndFatCellsLabel = new JLabel(cfg.getYoungAndFatCellsLabel());
59 JLabel fullAgeCellsLabel = new JLabel(cfg.getFullAgeCellsLabel());
60 JLabel hungryCellsLabel = new JLabel(cfg.getHungryCellsLabel());
61 JLabel oldCellsLabel = new JLabel(cfg.getOldCellsLabel());
62 youngCellsElement.setForeground(YOUNG.getColorForeground());
63 youngCellsElement.setBackground(YOUNG.getColorBackground());
64 youngAndFatCellsElement.setForeground(YOUNG_AND_FAT.getColorForeground());
65 youngAndFatCellsElement.setBackground(YOUNG_AND_FAT.getColorBackground());
66 fullAgeCellsElement.setForeground(FULL_AGE.getColorForeground());
67 fullAgeCellsElement.setBackground(FULL_AGE.getColorBackground());
68 hungryCellsElement.setForeground(HUNGRY.getColorForeground());
69 hungryCellsElement.setBackground(HUNGRY.getColorBackground());
70 oldCellsElement.setForeground(OLD.getColorForeground());
71 oldCellsElement.setBackground(OLD.getColorBackground());
72 this.add(youngCellsLabel);
73 this.add(youngCellsElement);
74 this.add(youngAndFatCellsLabel);
75 this.add(youngAndFatCellsElement);
76 this.add(fullAgeCellsLabel);
77 this.add(fullAgeCellsElement);
78 this.add(hungryCellsLabel);
79 this.add(hungryCellsElement);
80 this.add(oldCellsLabel);
81 this.add(oldCellsElement);
82 update();
83 }
84
85 public void update() {
86 CellPopulationRecord population = tabCtx.getTab().getPopulation();
87
88 this.youngCellsElement.setText(population.getYoungCells()+"");
89 this.youngAndFatCellsElement.setText(population.getYoungAndFatCells()+"");
90 this.fullAgeCellsElement.setText(population.getFullAgeCells()+"");
91 this.hungryCellsElement.setText(population.getHungryCells()+"");
92 this.oldCellsElement.setText(population.getOldCells()+"");
93 this.repaint();
94 }
95
96 }