1 package org.woehlke.computer.kurzweil.mandelbrot.view;
2
3 import org.woehlke.computer.kurzweil.mandelbrot.model.ApplicationModel;
4
5 import javax.swing.*;
6 import java.awt.*;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9
10 import static org.woehlke.computer.kurzweil.mandelbrot.view.RradioButtons.RADIO_BUTTONS_SWITCH;
11 import static org.woehlke.computer.kurzweil.mandelbrot.view.RradioButtons.RADIO_BUTTONS_ZOOM;
12
13
14
15
16
17
18
19
20
21
22
23 public class PanelButtons extends JPanel implements ActionListener {
24
25 private volatile JRadioButton radioButtonsSwitch;
26 private volatile JRadioButton radioButtonsZoom;
27 private volatile JButton zoomOut;
28 private volatile ButtonGroup radioButtonsGroup;
29 private volatile ApplicationModel model;
30
31 public PanelButtons(ApplicationModel model) {
32 this.model = model;
33 JLabel buttonsLabel = new JLabel(model.getConfig().getButtonsLabel());
34 this.radioButtonsSwitch = new JRadioButton(model.getConfig().getButtonsSwitch());
35 this.radioButtonsSwitch.setMnemonic(RADIO_BUTTONS_SWITCH.ordinal());
36 this.radioButtonsSwitch.setSelected(true);
37 this.radioButtonsSwitch.addActionListener(this);
38 this.radioButtonsZoom = new JRadioButton(model.getConfig().getButtonsZoom());
39 this.radioButtonsZoom.setMnemonic(RADIO_BUTTONS_ZOOM.ordinal());
40 this.radioButtonsZoom.addActionListener(this);
41 this.radioButtonsGroup = new ButtonGroup();
42 this.radioButtonsGroup.add(radioButtonsSwitch);
43 this.radioButtonsGroup.add(radioButtonsZoom);
44 this.zoomOut = new JButton(model.getConfig().getButtonsZoomOut());
45 this.zoomOut.addActionListener(this);
46 FlowLayout layout = new FlowLayout();
47 this.setLayout(layout);
48 this.add(buttonsLabel);
49 this.add(radioButtonsSwitch);
50 this.add(radioButtonsZoom);
51 this.add(zoomOut);
52 }
53
54
55
56
57 @Override
58 public void actionPerformed(ActionEvent ae) {
59 if (ae.getSource() == this.radioButtonsSwitch) {
60 this.model.setModeSwitch();
61 } else if(ae.getSource() == this.radioButtonsZoom) {
62 this.model.setModeZoom();
63 } else if(ae.getSource() == this.zoomOut){
64 this.model.zoomOut();
65 this.model.getFrame().getCanvas().repaint();
66 }
67 }
68 }