Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GameToolbar |
|
| 1.4166666666666667;1.417 | ||||
GameToolbar$1 |
|
| 1.4166666666666667;1.417 | ||||
GameToolbar$2 |
|
| 1.4166666666666667;1.417 | ||||
GameToolbar$3 |
|
| 1.4166666666666667;1.417 | ||||
GameToolbar$4 |
|
| 1.4166666666666667;1.417 |
1 | /****************************************************************************** | |
2 | * GameToolbar.java - Be the Game Toolbar above the board | |
3 | * $Id$ | |
4 | * | |
5 | * BuckoFIBS - Backgammon by BuckoSoft | |
6 | * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp. | |
7 | * | |
8 | * $Log$ | |
9 | * Revision 1.3 2010/03/03 13:12:21 inim | |
10 | * Replaced (c) sign in comment mangled by CVS default encoding back to UTF-8 | |
11 | * | |
12 | * Revision 1.2 2010/03/03 12:19:49 inim | |
13 | * Moved source to UTF8 encoding from CP1252 encoding. To this end all source files' (c) message was updated to "Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.". This replaces the (c) sign to UTF8, and adds the new year 2010. | |
14 | * | |
15 | * Revision 1.1 2010/02/04 05:57:53 inim | |
16 | * Mavenized project folder layout | |
17 | * | |
18 | * Revision 1.4 2009/02/14 15:26:52 dick | |
19 | * BuckoFIBS is released under the GNU license. | |
20 | * Javadoc. | |
21 | * | |
22 | * Revision 1.3 2009/02/05 05:59:35 dick | |
23 | * Add the AskDoubles and Resign buttons. | |
24 | * | |
25 | * Revision 1.2 2009/01/31 08:51:20 dick | |
26 | * Greedy fires Greedy, not Undo. | |
27 | * | |
28 | * Revision 1.1 2009/01/31 06:03:53 dick | |
29 | * Be the Game Toolbar above the board. | |
30 | */ | |
31 | ||
32 | /* | |
33 | * This program is free software: you can redistribute it and/or modify | |
34 | * it under the terms of the GNU General Public License as published by | |
35 | * the Free Software Foundation, either version 3 of the License, or | |
36 | * (at your option) any later version. | |
37 | * | |
38 | * This program is distributed in the hope that it will be useful, | |
39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
41 | * GNU General Public License for more details. | |
42 | * | |
43 | * You should have received a copy of the GNU General Public License | |
44 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
45 | * | |
46 | * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>. | |
47 | * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp. | |
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 | /** Be the Game Toolbar above the board | |
63 | * @author Dick Balaska | |
64 | * @since 2009/01/30 | |
65 | * @version $Revision$ <br> $Date$ | |
66 | * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/board/GameToolbar.java">cvs GameToolbar.java</a> | |
67 | */ | |
68 | 0 | public class GameToolbar extends JToolBar { |
69 | private static final long serialVersionUID = 1L; | |
70 | private ToolbarHandler toolbarHandler; // @jve:decl-index=0: | |
71 | ||
72 | 0 | private JButton jButtonUndo = null; |
73 | 0 | private JButton jButtonGreedy = null; |
74 | 0 | private JButton jButtonAskDouble = null; |
75 | 0 | private JButton jButtonResign = null; |
76 | ||
77 | 0 | private ImageIcon askDouble = new ImageIcon(getClass().getResource("/g/askDouble.png")); // @jve:decl-index=0: |
78 | 0 | private ImageIcon askDoubleOff = new ImageIcon(getClass().getResource("/g/askDoubleOff.png")); |
79 | ||
80 | /** Create and initialize a GameToolbar | |
81 | */ | |
82 | public GameToolbar() { | |
83 | 0 | super(); |
84 | 0 | initialize(); |
85 | 0 | } |
86 | ||
87 | /** Set the object that will receive our button presses. | |
88 | * @param toolbarHandler the toolbarHandler to set | |
89 | */ | |
90 | public void setToolbarHandler(ToolbarHandler toolbarHandler) { | |
91 | 0 | this.toolbarHandler = toolbarHandler; |
92 | 0 | } |
93 | ||
94 | /** Set the icon for the AskDouble button to match this state | |
95 | * @param onOff false = draw a line through the icon | |
96 | */ | |
97 | public void setAskDouble(boolean onOff) { | |
98 | 0 | jButtonAskDouble.setIcon(onOff ? askDouble : askDoubleOff); |
99 | 0 | } |
100 | ||
101 | /** | |
102 | * This method initializes this | |
103 | * | |
104 | */ | |
105 | private void initialize() { | |
106 | 0 | this.setBounds(new Rectangle(0, 0, 154, 26)); |
107 | 0 | this.add(getJButtonUndo()); |
108 | 0 | this.add(new JToolBar.Separator()); |
109 | 0 | this.add(getJButtonGreedy()); |
110 | 0 | this.add(getJButtonAskDouble()); |
111 | 0 | this.add(new JToolBar.Separator()); |
112 | 0 | this.add(getJButtonResign()); |
113 | ||
114 | 0 | } |
115 | ||
116 | /** | |
117 | * This method initializes jButtonUndo | |
118 | * | |
119 | * @return javax.swing.JButton | |
120 | */ | |
121 | private JButton getJButtonUndo() { | |
122 | 0 | if (jButtonUndo == null) { |
123 | 0 | jButtonUndo = new JButton(); |
124 | 0 | jButtonUndo.setPreferredSize(new Dimension(18, 18)); |
125 | 0 | jButtonUndo.setIcon(new ImageIcon(getClass().getResource("/g/undo.png"))); |
126 | 0 | jButtonUndo.addActionListener(new java.awt.event.ActionListener() { |
127 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
128 | 0 | toolbarHandler.buttonPressed(Button.Undo); |
129 | 0 | } |
130 | }); | |
131 | } | |
132 | 0 | return jButtonUndo; |
133 | } | |
134 | ||
135 | /** | |
136 | * This method initializes jButtonGreedy | |
137 | * | |
138 | * @return javax.swing.JButton | |
139 | */ | |
140 | private JButton getJButtonGreedy() { | |
141 | 0 | if (jButtonGreedy == null) { |
142 | 0 | jButtonGreedy = new JButton(); |
143 | 0 | jButtonGreedy.setPreferredSize(new Dimension(18, 18)); |
144 | 0 | jButtonGreedy.setIcon(new ImageIcon(getClass().getResource("/g/greedy.png"))); |
145 | 0 | jButtonGreedy.addActionListener(new java.awt.event.ActionListener() { |
146 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
147 | 0 | toolbarHandler.buttonPressed(Button.Greedy); |
148 | 0 | } |
149 | }); | |
150 | } | |
151 | 0 | return jButtonGreedy; |
152 | } | |
153 | ||
154 | /** | |
155 | * This method initializes jButtonAutoDoubles | |
156 | * | |
157 | * @return javax.swing.JButton | |
158 | */ | |
159 | private JButton getJButtonAskDouble() { | |
160 | 0 | if (jButtonAskDouble == null) { |
161 | 0 | jButtonAskDouble = new JButton(); |
162 | 0 | jButtonAskDouble.setIcon(askDouble); |
163 | 0 | jButtonAskDouble.addActionListener(new java.awt.event.ActionListener() { |
164 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
165 | 0 | toolbarHandler.buttonPressed(Button.AskDoubles); |
166 | 0 | } |
167 | }); | |
168 | } | |
169 | 0 | return jButtonAskDouble; |
170 | } | |
171 | ||
172 | /** | |
173 | * This method initializes jButtonResign | |
174 | * | |
175 | * @return javax.swing.JButton | |
176 | */ | |
177 | private JButton getJButtonResign() { | |
178 | 0 | if (jButtonResign == null) { |
179 | 0 | jButtonResign = new JButton(); |
180 | 0 | jButtonResign.setIcon(new ImageIcon(getClass().getResource("/g/whiteflag.png"))); |
181 | 0 | jButtonResign.addActionListener(new java.awt.event.ActionListener() { |
182 | public void actionPerformed(java.awt.event.ActionEvent e) { | |
183 | 0 | toolbarHandler.buttonPressed(Button.Resign); |
184 | 0 | } |
185 | }); | |
186 | } | |
187 | 0 | return jButtonResign; |
188 | } | |
189 | ||
190 | } // @jve:decl-index=0:visual-constraint="10,10" |