| 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.ShowNewUserDialogCommand; | |
| 43 | import ui.command.deletion.DeleteUserCommand; | |
| 44 | import ui.command.information.InfoOnUserCommand; | |
| 45 | import ui.table.TableSorter; | |
| 46 | import ui.table.UserTable; | |
| 47 | import ui.table.model.UserTableModel; | |
| 48 | ||
| 49 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 50 | 0 | public class ICUserPanel extends JPanel { |
| 51 | 0 | |
| 52 | 0 | private static final transient Logger logger = Logger |
| 53 | 0 | .getLogger(ICUserPanel.class.getName()); |
| 54 | ||
| 55 | private JPanel userPanel; | |
| 56 | ||
| 57 | private JPanel buttonPanel; | |
| 58 | ||
| 59 | private JButton newUserButton; | |
| 60 | ||
| 61 | private JButton deleteUserButton; | |
| 62 | ||
| 63 | private JButton infoOnUserButton; | |
| 64 | ||
| 65 | private JScrollPane userTableScrollPane; | |
| 66 | ||
| 67 | private JTable userTable; | |
| 68 | ||
| 69 | private TableSorter userTableSorter; | |
| 70 | ||
| 71 | private UserTableModel userTableModel; | |
| 72 | 0 | |
| 73 | 0 | public ICUserPanel() { |
| 74 | 0 | initialize(); |
| 75 | 0 | } |
| 76 | ||
| 77 | 0 | protected void initialize() { |
| 78 | 0 | this.setName(Messages.getString("common.users")); //$NON-NLS-1$ |
| 79 | 0 | this.setLayout(new BorderLayout()); |
| 80 | 0 | this.add(getUserPanel(), 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.setLayout(new GridLayout(1, 5)); |
| 91 | 0 | buttonPanel.setBorder(new EtchedBorder()); |
| 92 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 93 | 0 | buttonPanel.add(getNewUserButton()); |
| 94 | 0 | buttonPanel.add(getInfoOnUserButton()); |
| 95 | 0 | buttonPanel.add(getDeleteUserButton()); |
| 96 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 97 | ||
| 98 | 0 | } |
| 99 | 0 | return buttonPanel; |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * @return Returns the userPanel. | |
| 104 | */ | |
| 105 | 0 | protected JPanel getUserPanel() { |
| 106 | 0 | if (userPanel == null) { |
| 107 | 0 | userPanel = new JPanel(); |
| 108 | 0 | userPanel.setLayout(new BorderLayout()); |
| 109 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.registeredusers")); //$NON-NLS-1$ |
| 110 | 0 | userPanel.setBorder(titledBorder); |
| 111 | 0 | userPanel.add(getUserTableScrollPane(), BorderLayout.CENTER); |
| 112 | 0 | } |
| 113 | 0 | return userPanel; |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * @return Returns the userTable. | |
| 118 | */ | |
| 119 | 0 | protected JTable getUserTable() { |
| 120 | 0 | if (userTable == null) { |
| 121 | 0 | userTable = new UserTable(getUserTableSorter()); |
| 122 | 0 | userTable |
| 123 | 0 | .setPreferredScrollableViewportSize(new Dimension(500, 70)); |
| 124 | 0 | // We need to place it here to avoid a ciclyc call... |
| 125 | 0 | userTableSorter.setTableHeader(userTable.getTableHeader()); |
| 126 | 0 | // Set up tool tips for column headers. |
| 127 | 0 | userTable |
| 128 | 0 | .getTableHeader() |
| 129 | 0 | .setToolTipText( |
| 130 | 0 | Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$ |
| 131 | 0 | } |
| 132 | 0 | return userTable; |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * @return Returns the userTableScrollPane. | |
| 137 | */ | |
| 138 | 0 | protected JScrollPane getUserTableScrollPane() { |
| 139 | 0 | if (userTableScrollPane == null) { |
| 140 | 0 | userTableScrollPane = new JScrollPane(getUserTable()); |
| 141 | 0 | } |
| 142 | 0 | return userTableScrollPane; |
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * @return Returns the userTableSorter. | |
| 147 | */ | |
| 148 | 0 | protected TableSorter getUserTableSorter() { |
| 149 | 0 | if (userTableSorter == null) { |
| 150 | 0 | userTableSorter = new TableSorter(getUserTableModel()); |
| 151 | 0 | } |
| 152 | 0 | return userTableSorter; |
| 153 | } | |
| 154 | ||
| 155 | /** | |
| 156 | * @return Returns the userTableModel. | |
| 157 | */ | |
| 158 | 0 | protected UserTableModel getUserTableModel() { |
| 159 | 0 | if (userTableModel == null) { |
| 160 | 0 | userTableModel = new UserTableModel(); |
| 161 | 0 | } |
| 162 | 0 | return userTableModel; |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * @return Returns the deleteUserButton. | |
| 167 | */ | |
| 168 | 0 | protected JButton getDeleteUserButton() { |
| 169 | 0 | if (deleteUserButton == null) { |
| 170 | 0 | deleteUserButton = new JButton(Messages.getString("button.delete")); //$NON-NLS-1$ |
| 171 | 0 | deleteUserButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 172 | 0 | "/icon/16x16/actions/edit-delete.png"))); //$NON-NLS-1$ |
| 173 | 0 | |
| 174 | 0 | deleteUserButton.addActionListener(new ActionListener() { |
| 175 | public void actionPerformed(ActionEvent arg0) { | |
| 176 | logger.debug("actionPerformed deleteButton"); //$NON-NLS-1$ | |
| 177 | if (getUserTable().getSelectedRow() != -1) { | |
| 178 | int userId = Integer | |
| 179 | .parseInt(((TableSorter) getUserTable() | |
| 180 | .getModel()).getValueAt( | |
| 181 | getUserTable().getSelectedRow(), | |
| 182 | UserTableModel.USER_ID_COLUMN) | |
| 183 | .toString()); | |
| 184 | CommandExecutor.getInstance().executeCommand( | |
| 185 | new DeleteUserCommand(userId), false); | |
| 186 | } else | |
| 187 | JOptionPane | |
| 188 | .showMessageDialog( | |
| 189 | null, | |
| 190 | Messages.getString("panel.icuserpanle.message1"), //$NON-NLS-1$ | |
| 191 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 192 | } | |
| 193 | }); | |
| 194 | 0 | } |
| 195 | 0 | return deleteUserButton; |
| 196 | } | |
| 197 | ||
| 198 | /** | |
| 199 | * @return Returns the infoOnUserButton. | |
| 200 | */ | |
| 201 | 0 | protected JButton getInfoOnUserButton() { |
| 202 | 0 | if (infoOnUserButton == null) { |
| 203 | 0 | infoOnUserButton = new JButton(Messages.getString("button.info")); //$NON-NLS-1$ |
| 204 | 0 | infoOnUserButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 205 | 0 | "/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
| 206 | 0 | |
| 207 | 0 | infoOnUserButton.addActionListener(new ActionListener() { |
| 208 | public void actionPerformed(ActionEvent arg0) { | |
| 209 | logger.debug("actionPerformed infoButton"); //$NON-NLS-1$ | |
| 210 | if (getUserTable().getSelectedRow() != -1) { | |
| 211 | int userId = Integer | |
| 212 | .parseInt(((TableSorter) getUserTable() | |
| 213 | .getModel()).getValueAt( | |
| 214 | getUserTable().getSelectedRow(), | |
| 215 | UserTableModel.USER_ID_COLUMN) | |
| 216 | .toString()); | |
| 217 | CommandExecutor.getInstance().executeCommand( | |
| 218 | new InfoOnUserCommand(userId), false); | |
| 219 | } else | |
| 220 | JOptionPane | |
| 221 | .showMessageDialog( | |
| 222 | null, | |
| 223 | Messages.getString("panel.icuserpanel.message1"), //$NON-NLS-1$ | |
| 224 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 225 | } | |
| 226 | }); | |
| 227 | 0 | } |
| 228 | 0 | return infoOnUserButton; |
| 229 | } | |
| 230 | ||
| 231 | /** | |
| 232 | * @return Returns the newUserButton. | |
| 233 | */ | |
| 234 | 0 | protected JButton getNewUserButton() { |
| 235 | 0 | if (newUserButton == null) { |
| 236 | 0 | newUserButton = new JButton(Messages.getString("button.new")); //$NON-NLS-1$ |
| 237 | 0 | newUserButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 238 | 0 | "/icon/16x16/actions/contact-new.png"))); //$NON-NLS-1$ |
| 239 | 0 | |
| 240 | 0 | newUserButton.addActionListener(new ActionListener() { |
| 241 | public void actionPerformed(ActionEvent arg0) { | |
| 242 | logger.debug("actionPerformed newUserButton"); //$NON-NLS-1$ | |
| 243 | CommandExecutor.getInstance().executeCommand( | |
| 244 | new ShowNewUserDialogCommand(), false); | |
| 245 | } | |
| 246 | }); | |
| 247 | 0 | } |
| 248 | 0 | return newUserButton; |
| 249 | } | |
| 250 | ||
| 251 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |