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
21 package ui.panel;
22
23 import java.awt.BorderLayout;
24 import java.awt.Dimension;
25 import java.awt.GridLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JLabel;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JTable;
36 import javax.swing.border.EtchedBorder;
37 import javax.swing.border.TitledBorder;
38
39 import org.apache.log4j.Logger;
40
41 import ui.Messages;
42 import ui.command.CommandExecutor;
43 import ui.command.creation.ShowNewClientWorkstationDialogCommand;
44 import ui.command.deletion.DeleteClientWorkstationCommand;
45 import ui.command.information.InfoOnClientWorkstationCommand;
46 import ui.table.ClientWorkstationTable;
47 import ui.table.TableSorter;
48 import ui.table.model.ClientWorkstationTableModel;
49
50 /***
51 * @author skunk
52 *
53 */
54 @SuppressWarnings("serial")
55 public class TabledClientWorkstationPanel extends JPanel {
56
57 private static final transient Logger logger = Logger
58 .getLogger(TabledClientWorkstationPanel.class.getName());
59
60 private JTable workstationTable;
61
62 private TableSorter workstationTableSorter;
63
64 private JScrollPane workstationTableScrollPane;
65
66 private ClientWorkstationTableModel workstationTableModel;
67
68 private JPanel buttonPanel;
69
70 private JButton newClientWorkstationButton;
71
72 private JButton infoOnClientWorkstationButton;
73
74 private JButton snapshotOfClientWorkstationButton;
75
76 private JButton deleteClientWorkstationButton;
77
78 public TabledClientWorkstationPanel() {
79 initialize();
80 }
81
82 protected void initialize() {
83 this.setLayout(new BorderLayout());
84 TitledBorder titledBorder = new TitledBorder(Messages.getString("common.clientworkstations"));
85 this.setBorder(titledBorder);
86 this.add(getWorkstationTableScrollPane(), BorderLayout.CENTER);
87 this.add(getButtonPanel(), BorderLayout.EAST);
88 }
89
90 /***
91 * @return Returns the buttonPanel.
92 */
93 protected JPanel getButtonPanel() {
94 if (buttonPanel == null) {
95 buttonPanel = new JPanel();
96 buttonPanel.setLayout(new GridLayout(6, 1));
97 buttonPanel.setBorder(new EtchedBorder());
98 buttonPanel.add(new JLabel(""));
99 buttonPanel.add(getNewClientWorkstationButton());
100 buttonPanel.add(getInfoOnClientWorkstationButton());
101 buttonPanel.add(getSnapshotOfClientWorkstationButton());
102 buttonPanel.add(getDeleteClientWorkstationButton());
103 buttonPanel.add(new JLabel(""));
104 }
105 return buttonPanel;
106 }
107
108 /***
109 * @return Returns the workstationTableScrollPane.
110 */
111 protected JScrollPane getWorkstationTableScrollPane() {
112 if (workstationTableScrollPane == null) {
113 workstationTableScrollPane = new JScrollPane(getWorkstationTable());
114 }
115 return workstationTableScrollPane;
116 }
117
118 /***
119 * @return Returns the workstationTableSorter.
120 */
121 protected TableSorter getWorkstationTableSorter() {
122 if (workstationTableSorter == null) {
123 workstationTableSorter = new TableSorter(getWorkstationTableModel());
124 }
125 return workstationTableSorter;
126 }
127
128 /***
129 * @return Returns the workstationTableModel.
130 */
131 protected ClientWorkstationTableModel getWorkstationTableModel() {
132 if (workstationTableModel == null) {
133 workstationTableModel = new ClientWorkstationTableModel();
134 }
135 return workstationTableModel;
136 }
137
138 /***
139 * @return Returns the workstationTable.
140 */
141 protected JTable getWorkstationTable() {
142 if (workstationTable == null) {
143 workstationTable = new ClientWorkstationTable(
144 getWorkstationTableSorter());
145 workstationTable.setPreferredScrollableViewportSize(new Dimension(
146 500, 70));
147
148 workstationTableSorter.setTableHeader(workstationTable
149 .getTableHeader());
150
151 workstationTable
152 .getTableHeader()
153 .setToolTipText(
154 Messages.getString("tablesorter.header.tooltip"));
155 }
156 return workstationTable;
157 }
158
159 /***
160 * @return Returns the deleteClientWorkstationButton.
161 */
162 protected JButton getDeleteClientWorkstationButton() {
163 if (deleteClientWorkstationButton == null) {
164 deleteClientWorkstationButton = new JButton(
165 Messages.getString("button.delete"));
166 deleteClientWorkstationButton.setIcon(new ImageIcon(this.getClass()
167 .getResource("/icon/22x22/actions/edit-delete.png")));
168
169 deleteClientWorkstationButton
170 .addActionListener(new ActionListener() {
171 public void actionPerformed(ActionEvent arg0) {
172 logger
173 .debug("actionPerformed deleteClientWorkstationButton");
174 if (getWorkstationTable().getSelectedRow() != -1) {
175 int workstationId = Integer
176 .parseInt(((TableSorter) getWorkstationTable()
177 .getModel())
178 .getValueAt(
179 getWorkstationTable()
180 .getSelectedRow(),
181 ClientWorkstationTableModel.WORKSTATION_ID_COLUMN)
182 .toString());
183 CommandExecutor.getInstance().executeCommand(
184 new DeleteClientWorkstationCommand(
185 workstationId), false);
186 } else
187 JOptionPane
188 .showMessageDialog(
189 null,
190 Messages.getString("panel.tabledclientworkstationpanel.message1"),
191 Messages.getString("common.warning"),
192 JOptionPane.WARNING_MESSAGE);
193 }
194 });
195 }
196 return deleteClientWorkstationButton;
197 }
198
199 /***
200 * @return Returns the infoOnClientWorkstationButton.
201 */
202 protected JButton getInfoOnClientWorkstationButton() {
203 if (infoOnClientWorkstationButton == null) {
204 infoOnClientWorkstationButton = new JButton(
205 Messages.getString("button.info"));
206 infoOnClientWorkstationButton.setIcon(new ImageIcon(this.getClass()
207 .getResource("/icon/22x22/status/dialog-information.png")));
208
209 infoOnClientWorkstationButton
210 .addActionListener(new ActionListener() {
211 public void actionPerformed(ActionEvent arg0) {
212 logger
213 .debug("actionPerformed infoOnClientWorkstationButton");
214 if (getWorkstationTable().getSelectedRow() != -1) {
215 int workstationId = Integer
216 .parseInt(((TableSorter) getWorkstationTable()
217 .getModel())
218 .getValueAt(
219 getWorkstationTable()
220 .getSelectedRow(),
221 ClientWorkstationTableModel.WORKSTATION_ID_COLUMN)
222 .toString());
223 CommandExecutor.getInstance().executeCommand(
224 new InfoOnClientWorkstationCommand(
225 workstationId), false);
226
227 } else
228 JOptionPane
229 .showMessageDialog(
230 null,
231 Messages.getString("panel.tabledclientworkstationpanel.message1"),
232 Messages.getString("common.warning"),
233 JOptionPane.WARNING_MESSAGE);
234
235 }
236 });
237 }
238 return infoOnClientWorkstationButton;
239 }
240
241 /***
242 * @return Returns the newClientWorkstationButton.
243 */
244 protected JButton getNewClientWorkstationButton() {
245 if (newClientWorkstationButton == null) {
246 newClientWorkstationButton = new JButton(Messages.getString("button.new"));
247 newClientWorkstationButton.setIcon(new ImageIcon(this.getClass()
248 .getResource("/icon/22x22/devices/computer.png")));
249
250 newClientWorkstationButton.addActionListener(new ActionListener() {
251 public void actionPerformed(ActionEvent arg0) {
252 logger.debug("actionPerformed newClientWorkstationButton");
253 CommandExecutor.getInstance().executeCommand(
254 new ShowNewClientWorkstationDialogCommand(), false);
255 }
256 });
257 }
258 return newClientWorkstationButton;
259 }
260
261 /***
262 * @return Returns the snapshotOfClientWorkstationButton.
263 */
264 protected JButton getSnapshotOfClientWorkstationButton() {
265 if (snapshotOfClientWorkstationButton == null) {
266 snapshotOfClientWorkstationButton = new JButton(
267 Messages.getString("button.snapshot"));
268 snapshotOfClientWorkstationButton.setIcon(new ImageIcon(this
269 .getClass().getResource(
270 "/icon/22x22/devices/camera-photo.png")));
271
272 snapshotOfClientWorkstationButton
273 .addActionListener(new ActionListener() {
274 public void actionPerformed(ActionEvent arg0) {
275 logger
276 .debug("actionPerformed snapshotOfClientWorkstationButton");
277
278
279 }
280 });
281 }
282 return snapshotOfClientWorkstationButton;
283 }
284
285 }