View Javadoc
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.awt.event.ActionEvent;
8   import java.awt.event.ActionListener;
9   
10  
11  /**
12   * TODO write doc.
13   */
14  public class PanelButtons extends JPanel implements ActionListener {
15  
16    private final JButton buttonVonNeumann;
17    private final JButton buttonMoore;
18    private final JButton buttonWoehlke;
19    private ObjectRegistry ctx;
20  
21    public PanelButtons(ObjectRegistry ctx) {
22      this.ctx = ctx;
23      JLabel neighborhood = new JLabel("Neighborhood");
24      this.buttonVonNeumann = new JButton("Von Neumann");
25      this.buttonMoore = new JButton("Moore");
26      this.buttonWoehlke = new JButton("Woehlke");
27      FlowLayout layout = new FlowLayout();
28      this.setLayout(layout);
29      this.add(neighborhood);
30      this.add(this.buttonVonNeumann);
31      this.add(this.buttonMoore);
32      this.add(this.buttonWoehlke);
33      this.buttonVonNeumann.addActionListener(this);
34      this.buttonMoore.addActionListener(this);
35      this.buttonWoehlke.addActionListener(this);
36    }
37  
38    /**
39     * TODO write doc.
40     */
41    @Override
42    public void actionPerformed(ActionEvent ae) {
43      if (ae.getSource() == this.buttonVonNeumann) {
44          this.ctx.getController().pushButtonVonNeumann();
45      } else if (ae.getSource() == this.buttonMoore) {
46          this.ctx.getController().pushButtonMoore();
47      } else if (ae.getSource() == this.buttonWoehlke) {
48          this.ctx.getController().pushButtonWoehlke();
49      }
50    }
51  }