1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 package com.buckosoft.fibs.BuckoFIBS.gui.boardTab;
51
52 import java.awt.Dimension;
53
54 import javax.swing.ImageIcon;
55 import javax.swing.JButton;
56 import javax.swing.JToolBar;
57
58 import com.buckosoft.fibs.BuckoFIBS.gui.boardTab.ToolbarHandler.Button;
59
60 import java.awt.Rectangle;
61
62
63
64
65
66
67
68 public class GameToolbar extends JToolBar {
69 private static final long serialVersionUID = 1L;
70 private ToolbarHandler toolbarHandler;
71
72 private JButton jButtonUndo = null;
73 private JButton jButtonGreedy = null;
74 private JButton jButtonAskDouble = null;
75 private JButton jButtonResign = null;
76
77 private ImageIcon askDouble = new ImageIcon(getClass().getResource("/g/askDouble.png"));
78 private ImageIcon askDoubleOff = new ImageIcon(getClass().getResource("/g/askDoubleOff.png"));
79
80
81
82 public GameToolbar() {
83 super();
84 initialize();
85 }
86
87
88
89
90 public void setToolbarHandler(ToolbarHandler toolbarHandler) {
91 this.toolbarHandler = toolbarHandler;
92 }
93
94
95
96
97 public void setAskDouble(boolean onOff) {
98 jButtonAskDouble.setIcon(onOff ? askDouble : askDoubleOff);
99 }
100
101
102
103
104
105 private void initialize() {
106 this.setBounds(new Rectangle(0, 0, 154, 26));
107 this.add(getJButtonUndo());
108 this.add(new JToolBar.Separator());
109 this.add(getJButtonGreedy());
110 this.add(getJButtonAskDouble());
111 this.add(new JToolBar.Separator());
112 this.add(getJButtonResign());
113
114 }
115
116
117
118
119
120
121 private JButton getJButtonUndo() {
122 if (jButtonUndo == null) {
123 jButtonUndo = new JButton();
124 jButtonUndo.setPreferredSize(new Dimension(18, 18));
125 jButtonUndo.setIcon(new ImageIcon(getClass().getResource("/g/undo.png")));
126 jButtonUndo.addActionListener(new java.awt.event.ActionListener() {
127 public void actionPerformed(java.awt.event.ActionEvent e) {
128 toolbarHandler.buttonPressed(Button.Undo);
129 }
130 });
131 }
132 return jButtonUndo;
133 }
134
135
136
137
138
139
140 private JButton getJButtonGreedy() {
141 if (jButtonGreedy == null) {
142 jButtonGreedy = new JButton();
143 jButtonGreedy.setPreferredSize(new Dimension(18, 18));
144 jButtonGreedy.setIcon(new ImageIcon(getClass().getResource("/g/greedy.png")));
145 jButtonGreedy.addActionListener(new java.awt.event.ActionListener() {
146 public void actionPerformed(java.awt.event.ActionEvent e) {
147 toolbarHandler.buttonPressed(Button.Greedy);
148 }
149 });
150 }
151 return jButtonGreedy;
152 }
153
154
155
156
157
158
159 private JButton getJButtonAskDouble() {
160 if (jButtonAskDouble == null) {
161 jButtonAskDouble = new JButton();
162 jButtonAskDouble.setIcon(askDouble);
163 jButtonAskDouble.addActionListener(new java.awt.event.ActionListener() {
164 public void actionPerformed(java.awt.event.ActionEvent e) {
165 toolbarHandler.buttonPressed(Button.AskDoubles);
166 }
167 });
168 }
169 return jButtonAskDouble;
170 }
171
172
173
174
175
176
177 private JButton getJButtonResign() {
178 if (jButtonResign == null) {
179 jButtonResign = new JButton();
180 jButtonResign.setIcon(new ImageIcon(getClass().getResource("/g/whiteflag.png")));
181 jButtonResign.addActionListener(new java.awt.event.ActionListener() {
182 public void actionPerformed(java.awt.event.ActionEvent e) {
183 toolbarHandler.buttonPressed(Button.Resign);
184 }
185 });
186 }
187 return jButtonResign;
188 }
189
190 }