| 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.JOptionPane; | |
| 31 | import javax.swing.JPanel; | |
| 32 | import javax.swing.JScrollPane; | |
| 33 | import javax.swing.JTable; | |
| 34 | import javax.swing.border.TitledBorder; | |
| 35 | ||
| 36 | import org.apache.log4j.Logger; | |
| 37 | ||
| 38 | import ui.Messages; | |
| 39 | import ui.command.CommandExecutor; | |
| 40 | import ui.command.creation.ShowNewPhoneNumberDialogCommand; | |
| 41 | import ui.command.deletion.DeletePhoneNumberCommand; | |
| 42 | import ui.command.information.InfoOnPhoneNumberCommand; | |
| 43 | import ui.table.PhoneNumberTable; | |
| 44 | import ui.table.TableSorter; | |
| 45 | import ui.table.model.PhoneNumberTableModel; | |
| 46 | import base.user.User; | |
| 47 | ||
| 48 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 49 | 0 | public class TabledPhoneNumberPanel extends JPanel { |
| 50 | 0 | |
| 51 | 0 | private static final transient Logger logger = Logger |
| 52 | 0 | .getLogger(TabledPhoneNumberPanel.class.getName()); |
| 53 | ||
| 54 | private JTable phoneNumberTable; | |
| 55 | ||
| 56 | private TableSorter phoneNumberTableSorter; | |
| 57 | ||
| 58 | private JScrollPane phoneNumberTableScrollPane; | |
| 59 | ||
| 60 | private PhoneNumberTableModel phoneNumberTableModel; | |
| 61 | ||
| 62 | private JPanel phoneNumberButtonPanel; | |
| 63 | ||
| 64 | private JButton newPhoneNumberButton; | |
| 65 | ||
| 66 | private JButton infoOnPhoneNumberButton; | |
| 67 | ||
| 68 | private JButton deletePhoneNumberButton; | |
| 69 | ||
| 70 | private final User user; | |
| 71 | 0 | |
| 72 | 0 | public TabledPhoneNumberPanel(User user) { |
| 73 | 0 | this.user = user; |
| 74 | 0 | initialize(); |
| 75 | 0 | } |
| 76 | ||
| 77 | 0 | protected void initialize() { |
| 78 | 0 | this.setBorder(new TitledBorder(Messages.getString("common.phonenumbers"))); //$NON-NLS-1$ |
| 79 | 0 | this.setLayout(new BorderLayout()); |
| 80 | 0 | this.add(getPhoneNumberTableScrollPane(), BorderLayout.CENTER); |
| 81 | 0 | this.add(getPhoneNumberButtonPanel(), BorderLayout.EAST); |
| 82 | 0 | } |
| 83 | ||
| 84 | /** | |
| 85 | * @return Returns the phoneNumberTable. | |
| 86 | */ | |
| 87 | 0 | protected JTable getPhoneNumberTable() { |
| 88 | 0 | if (phoneNumberTable == null) { |
| 89 | 0 | phoneNumberTable = new PhoneNumberTable(getPhoneNumberTableSorter()); |
| 90 | 0 | phoneNumberTable.setPreferredScrollableViewportSize(new Dimension( |
| 91 | 0 | 500, 70)); |
| 92 | 0 | // We need to place it here to avoid a ciclyc call... |
| 93 | 0 | phoneNumberTableSorter.setTableHeader(phoneNumberTable |
| 94 | 0 | .getTableHeader()); |
| 95 | 0 | // Set up tool tips for column headers. |
| 96 | 0 | phoneNumberTable |
| 97 | 0 | .getTableHeader() |
| 98 | 0 | .setToolTipText( |
| 99 | 0 | Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$ |
| 100 | 0 | } |
| 101 | 0 | return phoneNumberTable; |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * @return Returns the phoneNumberTableScrollPane. | |
| 106 | */ | |
| 107 | 0 | protected JScrollPane getPhoneNumberTableScrollPane() { |
| 108 | 0 | if (phoneNumberTableScrollPane == null) { |
| 109 | 0 | phoneNumberTableScrollPane = new JScrollPane(getPhoneNumberTable()); |
| 110 | 0 | } |
| 111 | 0 | return phoneNumberTableScrollPane; |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * @return Returns the phoneNumberTableSorter. | |
| 116 | */ | |
| 117 | 0 | protected TableSorter getPhoneNumberTableSorter() { |
| 118 | 0 | if (phoneNumberTableSorter == null) { |
| 119 | 0 | phoneNumberTableSorter = new TableSorter(getPhoneNumberTableModel()); |
| 120 | 0 | } |
| 121 | 0 | return phoneNumberTableSorter; |
| 122 | } | |
| 123 | ||
| 124 | /** | |
| 125 | * @return Returns the phoneNumberTableModel. | |
| 126 | */ | |
| 127 | 0 | protected PhoneNumberTableModel getPhoneNumberTableModel() { |
| 128 | 0 | if (phoneNumberTableModel == null) { |
| 129 | 0 | phoneNumberTableModel = new PhoneNumberTableModel(getUser()); |
| 130 | 0 | } |
| 131 | 0 | return phoneNumberTableModel; |
| 132 | } | |
| 133 | ||
| 134 | /** | |
| 135 | * @return Returns the phoneNumberButtonPanel. | |
| 136 | */ | |
| 137 | 0 | protected JPanel getPhoneNumberButtonPanel() { |
| 138 | 0 | if (phoneNumberButtonPanel == null) { |
| 139 | 0 | phoneNumberButtonPanel = new JPanel(); |
| 140 | 0 | phoneNumberButtonPanel.setLayout(new GridLayout(3, 1)); |
| 141 | 0 | phoneNumberButtonPanel.add(getNewPhoneNumberButton()); |
| 142 | 0 | phoneNumberButtonPanel.add(getDeletePhoneNumberButton()); |
| 143 | 0 | phoneNumberButtonPanel.add(getInfoOnPhoneNumberButton()); |
| 144 | 0 | } |
| 145 | 0 | return phoneNumberButtonPanel; |
| 146 | } | |
| 147 | ||
| 148 | /** | |
| 149 | * @return Returns the deletePhoneNumberButton. | |
| 150 | */ | |
| 151 | 0 | protected JButton getDeletePhoneNumberButton() { |
| 152 | 0 | if (deletePhoneNumberButton == null) { |
| 153 | 0 | deletePhoneNumberButton = new JButton(); |
| 154 | 0 | deletePhoneNumberButton.setIcon(new ImageIcon(this.getClass() |
| 155 | 0 | .getResource("/icon/16x16/actions/list-remove.png"))); //$NON-NLS-1$ |
| 156 | 0 | |
| 157 | 0 | deletePhoneNumberButton.addActionListener(new ActionListener() { |
| 158 | public void actionPerformed(ActionEvent arg0) { | |
| 159 | logger.debug("actionPerformed deletePhoneNumberButton"); //$NON-NLS-1$ | |
| 160 | if (getPhoneNumberTable().getSelectedRow() != -1) { | |
| 161 | int phoneNumberId = Integer | |
| 162 | .parseInt(((TableSorter) getPhoneNumberTable() | |
| 163 | .getModel()) | |
| 164 | .getValueAt( | |
| 165 | getPhoneNumberTable() | |
| 166 | .getSelectedRow(), | |
| 167 | PhoneNumberTableModel.PHONENUMBER_ID_COLUMN) | |
| 168 | .toString()); | |
| 169 | CommandExecutor.getInstance().executeCommand( | |
| 170 | new DeletePhoneNumberCommand(getUser(), | |
| 171 | phoneNumberId, | |
| 172 | getPhoneNumberTableModel()), false); | |
| 173 | } else | |
| 174 | JOptionPane | |
| 175 | .showMessageDialog( | |
| 176 | null, | |
| 177 | Messages.getString("panel.tabledphonenumberpanel.message1"), //$NON-NLS-1$ | |
| 178 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 179 | } | |
| 180 | }); | |
| 181 | ||
| 182 | 0 | } |
| 183 | 0 | return deletePhoneNumberButton; |
| 184 | } | |
| 185 | ||
| 186 | /** | |
| 187 | * @return Returns the infoOnPhoneNumberButton. | |
| 188 | */ | |
| 189 | 0 | protected JButton getInfoOnPhoneNumberButton() { |
| 190 | 0 | if (infoOnPhoneNumberButton == null) { |
| 191 | 0 | infoOnPhoneNumberButton = new JButton(); |
| 192 | 0 | infoOnPhoneNumberButton.setIcon(new ImageIcon(this.getClass() |
| 193 | 0 | .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
| 194 | 0 | |
| 195 | 0 | infoOnPhoneNumberButton.addActionListener(new ActionListener() { |
| 196 | public void actionPerformed(ActionEvent arg0) { | |
| 197 | logger.debug("actionPerformed infoOnPhoneNumberButton"); //$NON-NLS-1$ | |
| 198 | if (getPhoneNumberTable().getSelectedRow() != -1) { | |
| 199 | int phoneNumberId = Integer | |
| 200 | .parseInt(((TableSorter) getPhoneNumberTable() | |
| 201 | .getModel()) | |
| 202 | .getValueAt( | |
| 203 | getPhoneNumberTable() | |
| 204 | .getSelectedRow(), | |
| 205 | PhoneNumberTableModel.PHONENUMBER_ID_COLUMN) | |
| 206 | .toString()); | |
| 207 | CommandExecutor.getInstance().executeCommand( | |
| 208 | new InfoOnPhoneNumberCommand(getUser(), | |
| 209 | phoneNumberId), false); | |
| 210 | } else | |
| 211 | JOptionPane | |
| 212 | .showMessageDialog( | |
| 213 | null, | |
| 214 | Messages.getString("panel.tabledphonenumberpanel.message1"), //$NON-NLS-1$ | |
| 215 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 216 | } | |
| 217 | }); | |
| 218 | 0 | } |
| 219 | 0 | return infoOnPhoneNumberButton; |
| 220 | } | |
| 221 | ||
| 222 | /** | |
| 223 | * @return Returns the newPhoneNumberButton. | |
| 224 | */ | |
| 225 | 0 | protected JButton getNewPhoneNumberButton() { |
| 226 | 0 | if (newPhoneNumberButton == null) { |
| 227 | 0 | newPhoneNumberButton = new JButton(); |
| 228 | 0 | newPhoneNumberButton.setIcon(new ImageIcon(this.getClass() |
| 229 | 0 | .getResource("/icon/16x16/actions/list-add.png"))); //$NON-NLS-1$ |
| 230 | 0 | |
| 231 | 0 | newPhoneNumberButton.addActionListener(new ActionListener() { |
| 232 | public void actionPerformed(ActionEvent arg0) { | |
| 233 | logger.debug("actionPerformed newPhoneNumberButton"); //$NON-NLS-1$ | |
| 234 | ShowNewPhoneNumberDialogCommand showNewPhoneNumberDialogCommand = new ShowNewPhoneNumberDialogCommand( | |
| 235 | getUser(), getPhoneNumberTableModel()); | |
| 236 | CommandExecutor.getInstance().executeCommand( | |
| 237 | showNewPhoneNumberDialogCommand, false); | |
| 238 | } | |
| 239 | }); | |
| 240 | 0 | } |
| 241 | 0 | return newPhoneNumberButton; |
| 242 | } | |
| 243 | ||
| 244 | /** | |
| 245 | * @return Returns the user. | |
| 246 | */ | |
| 247 | 0 | protected User getUser() { |
| 248 | 0 | return user; |
| 249 | } | |
| 250 | ||
| 251 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |