1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 package ui;
21
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24
25 import javax.swing.ImageIcon;
26 import javax.swing.JButton;
27 import javax.swing.JToolBar;
28
29 import org.apache.log4j.Logger;
30
31 import ui.command.CommandExecutor;
32 import ui.command.IO.LogOutAdministratorCommand;
33 import ui.command.IO.SaveDBCommand;
34 import ui.command.creation.ShowNewClientWorkstationDialogCommand;
35 import ui.command.creation.ShowNewServiceDialogCommand;
36 import ui.command.creation.ShowNewSessionDialogCommand;
37 import ui.command.creation.ShowNewUserDialogCommand;
38
39 @SuppressWarnings("serial")
40 public class ICToolBar extends JToolBar {
41
42 private static final transient Logger logger = Logger
43 .getLogger(ICToolBar.class.getName());
44
45 private JButton newUserButton;
46
47 private JButton newSessionButton;
48
49 private JButton newServiceButton;
50
51 private JButton newClientWorkstationButton;
52
53 private JButton saveDBButton;
54
55 private JButton logOutButton;
56
57 public ICToolBar() {
58 initialize();
59 }
60
61 protected void initialize() {
62 this.setOrientation(JToolBar.HORIZONTAL);
63 this.setOpaque(true);
64 this.add(getNewUserButton());
65 this.add(getNewSessionButton());
66 this.add(getNewServiceButton());
67 this.add(getNewClientWorkstationButton());
68 this.add(getSaveDBButton());
69 this.add(getLogOutButton());
70 }
71
72 /***
73 * @return Returns the newServiceButton.
74 */
75 protected JButton getNewServiceButton() {
76 if (newServiceButton == null) {
77 newServiceButton = new JButton();
78 newServiceButton.setToolTipText(Messages.getString("toolbar.newservice"));
79 newServiceButton
80 .setIcon(new ImageIcon(
81 this
82 .getClass()
83 .getResource(
84 "/icon/22x22/apps/preferences-desktop-remote-desktop.png")));
85 newServiceButton.addActionListener(new ActionListener() {
86 public void actionPerformed(ActionEvent arg0) {
87 logger.debug("actionPerformed newServiceButton");
88 CommandExecutor.getInstance().executeCommand(
89 new ShowNewServiceDialogCommand(), false);
90 }
91 });
92 }
93 return newServiceButton;
94 }
95
96 /***
97 * @return Returns the newSessionButton.
98 */
99 protected JButton getNewSessionButton() {
100 if (newSessionButton == null) {
101 newSessionButton = new JButton();
102 newSessionButton.setToolTipText(Messages.getString("toolbar.newsession"));
103 newSessionButton.setIcon(new ImageIcon(this.getClass().getResource(
104 "/icon/22x22/actions/window-new.png")));
105 newSessionButton.addActionListener(new ActionListener() {
106 public void actionPerformed(ActionEvent arg0) {
107 logger.debug("actionPerformed newSessionButton");
108 CommandExecutor.getInstance().executeCommand(
109 new ShowNewSessionDialogCommand(), false);
110 }
111 });
112 }
113 return newSessionButton;
114 }
115
116 /***
117 * @return Returns the newUserButton.
118 */
119 protected JButton getNewUserButton() {
120 if (newUserButton == null) {
121 newUserButton = new JButton();
122 newUserButton.setToolTipText(Messages.getString("toolbar.newuser"));
123 newUserButton.setIcon(new ImageIcon(this.getClass().getResource(
124 "/icon/22x22/actions/contact-new.png")));
125 newUserButton.addActionListener(new ActionListener() {
126 public void actionPerformed(ActionEvent arg0) {
127 logger.debug("actionPerformed newUserButton");
128 CommandExecutor.getInstance().executeCommand(
129 new ShowNewUserDialogCommand(), false);
130 }
131 });
132 }
133 return newUserButton;
134 }
135
136 /***
137 * @return Returns the saveDBButton.
138 */
139 protected JButton getSaveDBButton() {
140 if (saveDBButton == null) {
141 saveDBButton = new JButton();
142 saveDBButton.setToolTipText(Messages.getString("toolbar.savedatabaseas"));
143 saveDBButton.setIcon(new ImageIcon(this.getClass().getResource(
144 "/icon/22x22/actions/document-save.png")));
145
146 saveDBButton.addActionListener(new ActionListener() {
147 public void actionPerformed(ActionEvent arg0) {
148 logger.debug("actionPerformed saveDBButton");
149 CommandExecutor.getInstance().executeCommand(
150 new SaveDBCommand(), false);
151 }
152 });
153 }
154 return saveDBButton;
155 }
156
157 /***
158 * @return Returns the logOutButton.
159 */
160 protected JButton getLogOutButton() {
161 if (logOutButton == null) {
162 logOutButton = new JButton();
163 logOutButton.setToolTipText(Messages.getString("toolbar.logout"));
164 logOutButton.setIcon(new ImageIcon(this.getClass().getResource(
165 "/icon/22x22/actions/system-log-out.png")));
166 logOutButton.addActionListener(new ActionListener() {
167 public void actionPerformed(ActionEvent arg0) {
168 logger.debug("actionPerformed logOutButton");
169 CommandExecutor.getInstance().executeCommand(
170 new LogOutAdministratorCommand(), false);
171 }
172 });
173 }
174 return logOutButton;
175 }
176
177 /***
178 * @return Returns the newClientWorkstationButton.
179 */
180 protected JButton getNewClientWorkstationButton() {
181 if (newClientWorkstationButton == null) {
182 newClientWorkstationButton = new JButton();
183 newClientWorkstationButton.setToolTipText(Messages.getString("toolbar.newclientworkstation"));
184 newClientWorkstationButton.setIcon(new ImageIcon(this.getClass()
185 .getResource("/icon/22x22/devices/computer.png")));
186
187 newClientWorkstationButton.addActionListener(new ActionListener() {
188 public void actionPerformed(ActionEvent arg0) {
189 logger.debug("actionPerformed newClientWorkstationButton");
190 CommandExecutor.getInstance().executeCommand(
191 new ShowNewClientWorkstationDialogCommand(), false);
192 }
193 });
194 }
195 return newClientWorkstationButton;
196 }
197
198 }