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 | package ui.panel; | |
21 | ||
22 | import java.awt.BorderLayout; | |
23 | import java.awt.Dimension; | |
24 | import java.awt.GridLayout; | |
25 | import java.awt.event.ActionEvent; | |
26 | import java.awt.event.ActionListener; | |
27 | ||
28 | import javax.swing.ImageIcon; | |
29 | import javax.swing.JButton; | |
30 | import javax.swing.JLabel; | |
31 | import javax.swing.JOptionPane; | |
32 | import javax.swing.JPanel; | |
33 | import javax.swing.JScrollPane; | |
34 | import javax.swing.JTable; | |
35 | import javax.swing.border.EtchedBorder; | |
36 | import javax.swing.border.TitledBorder; | |
37 | ||
38 | import org.apache.log4j.Logger; | |
39 | ||
40 | import ui.Messages; | |
41 | import ui.command.CommandExecutor; | |
42 | import ui.command.creation.ShowNewServiceDialogCommand; | |
43 | import ui.command.deletion.DeleteServiceCommand; | |
44 | import ui.command.information.InfoOnServiceCommand; | |
45 | import ui.table.ServiceTable; | |
46 | import ui.table.TableSorter; | |
47 | import ui.table.model.ServiceTableModel; | |
48 | import ui.table.model.SessionTableModel; | |
49 | ||
50 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
51 | 0 | public class ICServicePanel extends JPanel { |
52 | 0 | |
53 | 0 | private static final transient Logger logger = Logger |
54 | 0 | .getLogger(ICServicePanel.class.getName()); |
55 | ||
56 | private JPanel contentPanel; | |
57 | ||
58 | private JPanel buttonPanel; | |
59 | ||
60 | private JButton newServiceButton; | |
61 | ||
62 | private JButton deleteServiceButton; | |
63 | ||
64 | private JButton infoOnServiceButton; | |
65 | ||
66 | private JTable serviceTable; | |
67 | ||
68 | private TableSorter serviceTableSorter; | |
69 | ||
70 | private JScrollPane serviceTableScrollPane; | |
71 | ||
72 | private ServiceTableModel serviceTableModel; | |
73 | 0 | |
74 | 0 | public ICServicePanel() { |
75 | 0 | initialize(); |
76 | 0 | } |
77 | ||
78 | 0 | protected void initialize() { |
79 | 0 | this.setLayout(new BorderLayout()); |
80 | 0 | this.add(getContentPanel(), BorderLayout.CENTER); |
81 | 0 | this.add(getButtonPanel(), BorderLayout.SOUTH); |
82 | 0 | } |
83 | ||
84 | /** | |
85 | * @return Returns the buttonPanel. | |
86 | */ | |
87 | 0 | protected JPanel getButtonPanel() { |
88 | 0 | if (buttonPanel == null) { |
89 | 0 | buttonPanel = new JPanel(); |
90 | 0 | buttonPanel.setBorder(new EtchedBorder()); |
91 | 0 | buttonPanel.setLayout(new GridLayout(1, 5)); |
92 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
93 | 0 | buttonPanel.add(getNewServiceButton()); |
94 | 0 | buttonPanel.add(getInfoOnServiceButton()); |
95 | 0 | buttonPanel.add(getDeleteServiceButton()); |
96 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
97 | ||
98 | 0 | } |
99 | 0 | return buttonPanel; |
100 | } | |
101 | ||
102 | /** | |
103 | * @return Returns the contentPanel. | |
104 | */ | |
105 | 0 | protected JPanel getContentPanel() { |
106 | 0 | if (contentPanel == null) { |
107 | 0 | contentPanel = new JPanel(); |
108 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.services")); //$NON-NLS-1$ |
109 | 0 | contentPanel.setBorder(titledBorder); |
110 | 0 | contentPanel.setLayout(new BorderLayout()); |
111 | 0 | contentPanel.add(getServiceTableScrollPane(), BorderLayout.CENTER); |
112 | 0 | } |
113 | 0 | return contentPanel; |
114 | } | |
115 | ||
116 | /** | |
117 | * @return Returns the deleteServiceButton. | |
118 | */ | |
119 | 0 | protected JButton getDeleteServiceButton() { |
120 | 0 | if (deleteServiceButton == null) { |
121 | 0 | deleteServiceButton = new JButton(Messages.getString("button.delete")); //$NON-NLS-1$ |
122 | 0 | deleteServiceButton.setIcon(new ImageIcon(this.getClass() |
123 | 0 | .getResource("/icon/16x16/actions/edit-delete.png"))); //$NON-NLS-1$ |
124 | 0 | |
125 | 0 | deleteServiceButton.addActionListener(new ActionListener() { |
126 | public void actionPerformed(ActionEvent arg0) { | |
127 | logger.debug("actionPerformed deleteServiceButton"); //$NON-NLS-1$ | |
128 | if (getServiceTable().getSelectedRow() != -1) { | |
129 | int serviceId = Integer | |
130 | .parseInt(((TableSorter) getServiceTable() | |
131 | .getModel()).getValueAt( | |
132 | getServiceTable().getSelectedRow(), | |
133 | SessionTableModel.SESSION_ID_COLUMN) | |
134 | .toString()); | |
135 | CommandExecutor.getInstance().executeCommand( | |
136 | new DeleteServiceCommand(serviceId), false); | |
137 | } else | |
138 | JOptionPane | |
139 | .showMessageDialog( | |
140 | null, | |
141 | Messages.getString("panel.icservicepanel.message1"), //$NON-NLS-1$ | |
142 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
143 | } | |
144 | }); | |
145 | 0 | } |
146 | 0 | return deleteServiceButton; |
147 | } | |
148 | ||
149 | /** | |
150 | * @return Returns the infoOnServiceButton. | |
151 | */ | |
152 | 0 | protected JButton getInfoOnServiceButton() { |
153 | 0 | if (infoOnServiceButton == null) { |
154 | 0 | infoOnServiceButton = new JButton(Messages.getString("button.info")); //$NON-NLS-1$ |
155 | 0 | infoOnServiceButton.setIcon(new ImageIcon(this.getClass() |
156 | 0 | .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
157 | 0 | |
158 | 0 | infoOnServiceButton.addActionListener(new ActionListener() { |
159 | public void actionPerformed(ActionEvent arg0) { | |
160 | logger.debug("actionPerformed infoOnServiceButton"); //$NON-NLS-1$ | |
161 | if (getServiceTable().getSelectedRow() != -1) { | |
162 | int serviceId = Integer | |
163 | .parseInt(((TableSorter) getServiceTable() | |
164 | .getModel()).getValueAt( | |
165 | getServiceTable().getSelectedRow(), | |
166 | SessionTableModel.SESSION_ID_COLUMN) | |
167 | .toString()); | |
168 | CommandExecutor.getInstance().executeCommand( | |
169 | new InfoOnServiceCommand(serviceId), false); | |
170 | } else | |
171 | JOptionPane | |
172 | .showMessageDialog( | |
173 | null, | |
174 | Messages.getString("panel.icservicepanel.message1"), //$NON-NLS-1$ | |
175 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
176 | ||
177 | } | |
178 | }); | |
179 | 0 | } |
180 | 0 | return infoOnServiceButton; |
181 | } | |
182 | ||
183 | /** | |
184 | * @return Returns the newServiceButton. | |
185 | */ | |
186 | 0 | protected JButton getNewServiceButton() { |
187 | 0 | if (newServiceButton == null) { |
188 | 0 | newServiceButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$ |
189 | 0 | newServiceButton |
190 | 0 | .setIcon(new ImageIcon( |
191 | 0 | this |
192 | 0 | .getClass() |
193 | 0 | .getResource( |
194 | 0 | "/icon/16x16/apps/preferences-desktop-remote-desktop.png"))); //$NON-NLS-1$ |
195 | 0 | |
196 | 0 | newServiceButton.addActionListener(new ActionListener() { |
197 | public void actionPerformed(ActionEvent arg0) { | |
198 | logger.debug("actionPerformed newServiceButton"); //$NON-NLS-1$ | |
199 | CommandExecutor.getInstance().executeCommand( | |
200 | new ShowNewServiceDialogCommand(), false); | |
201 | } | |
202 | }); | |
203 | 0 | } |
204 | 0 | return newServiceButton; |
205 | } | |
206 | ||
207 | /** | |
208 | * @return Returns the serviceTableScrollPane. | |
209 | */ | |
210 | 0 | protected JScrollPane getServiceTableScrollPane() { |
211 | 0 | if (serviceTableScrollPane == null) { |
212 | 0 | serviceTableScrollPane = new JScrollPane(getServiceTable()); |
213 | 0 | } |
214 | 0 | return serviceTableScrollPane; |
215 | } | |
216 | ||
217 | /** | |
218 | * @return Returns the serviceTableSorter. | |
219 | */ | |
220 | 0 | protected TableSorter getServiceTableSorter() { |
221 | 0 | if (serviceTableSorter == null) { |
222 | 0 | serviceTableSorter = new TableSorter(getServiceTableModel()); |
223 | 0 | } |
224 | 0 | return serviceTableSorter; |
225 | } | |
226 | ||
227 | /** | |
228 | * @return Returns the serviceTableModel. | |
229 | */ | |
230 | 0 | protected ServiceTableModel getServiceTableModel() { |
231 | 0 | if (serviceTableModel == null) { |
232 | 0 | serviceTableModel = new ServiceTableModel(); |
233 | 0 | } |
234 | 0 | return serviceTableModel; |
235 | } | |
236 | ||
237 | /** | |
238 | * @return Returns the serviceTable. | |
239 | */ | |
240 | 0 | protected JTable getServiceTable() { |
241 | 0 | if (serviceTable == null) { |
242 | 0 | serviceTable = new ServiceTable(getServiceTableSorter()); |
243 | 0 | serviceTable.setPreferredScrollableViewportSize(new Dimension(500, |
244 | 0 | 70)); |
245 | 0 | // We need to place it here to avoid a ciclyc call... |
246 | 0 | serviceTableSorter.setTableHeader(serviceTable.getTableHeader()); |
247 | 0 | // Set up tool tips for column headers. |
248 | 0 | serviceTable |
249 | 0 | .getTableHeader() |
250 | 0 | .setToolTipText( |
251 | 0 | Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$ |
252 | 0 | } |
253 | 0 | return serviceTable; |
254 | } | |
255 | ||
256 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |