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