1 package ch.odi.justblog.gui.swing;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5
6 import javax.swing.JButton;
7 import javax.swing.JPanel;
8
9 import ch.odi.justblog.gui.swing.control.ButtonBarController;
10
11 /***
12 *
13 *
14 * @author oglueck
15 */
16 public class ButtonBar extends JPanel implements ActionListener {
17 private static final String CMD_POST = "post";
18 private static final String CMD_CLEAR = "clear";
19 private ButtonBarController controller;
20 private JButton post, clear;
21
22 /***
23 *
24 */
25 public ButtonBar(ButtonBarController controller) {
26 this.controller = controller;
27 init();
28 }
29
30 /***
31 *
32 */
33 private void init() {
34 clear = new JButton("New Posting");
35 clear.setActionCommand(CMD_CLEAR);
36 clear.addActionListener(this);
37 this.add(clear);
38
39 post = new JButton("Publish");
40 post.setActionCommand(CMD_POST);
41 post.addActionListener(this);
42 this.add(post);
43 }
44
45 /***
46 * Disables all the buttons.
47 * @param enabled
48 */
49 public void setEnabled(boolean enabled) {
50 super.setEnabled(enabled);
51 post.setEnabled(enabled);
52 clear.setEnabled(enabled);
53 }
54
55 public void actionPerformed(ActionEvent e) {
56 if (CMD_POST.equals(e.getActionCommand())) {
57 controller.postEntry();
58 } else if (CMD_CLEAR.equals(e.getActionCommand())) {
59 controller.clearEntry();
60 }
61 }
62
63 }