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