| 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.dialog; | |
| 21 | ||
| 22 | import java.awt.BorderLayout; | |
| 23 | import java.awt.Dimension; | |
| 24 | import java.awt.GridLayout; | |
| 25 | import java.awt.Toolkit; | |
| 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.JDialog; | |
| 32 | import javax.swing.JLabel; | |
| 33 | import javax.swing.JPanel; | |
| 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.IO.SaveClientWorkstationCommand; | |
| 41 | import ui.panel.WorkstationPanel; | |
| 42 | import base.network.Workstation; | |
| 43 | ||
| 44 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 45 | 0 | public class WorkstationDialog extends JDialog { |
| 46 | 0 | |
| 47 | 0 | private static final transient Logger logger = Logger |
| 48 | 0 | .getLogger(WorkstationDialog.class.getName()); |
| 49 | ||
| 50 | private JPanel contentPanel; | |
| 51 | ||
| 52 | private JPanel buttonPanel; | |
| 53 | ||
| 54 | private JButton saveWorkstationButton; | |
| 55 | ||
| 56 | private JButton clearWorkstationDataButton; | |
| 57 | ||
| 58 | private WorkstationPanel workstationPanel; | |
| 59 | 0 | |
| 60 | 0 | private Workstation workstation; |
| 61 | 0 | |
| 62 | 0 | private boolean createWorkstation = false; |
| 63 | 0 | |
| 64 | 0 | public WorkstationDialog() { |
| 65 | 0 | createWorkstation = true; |
| 66 | 0 | initialize(); |
| 67 | 0 | } |
| 68 | 0 | |
| 69 | 0 | public WorkstationDialog(Workstation workstation) { |
| 70 | 0 | this.workstation = workstation; |
| 71 | 0 | if (workstation == null) |
| 72 | 0 | createWorkstation = true; |
| 73 | 0 | initialize(); |
| 74 | 0 | } |
| 75 | ||
| 76 | 0 | protected void initialize() { |
| 77 | 0 | this.setResizable(false); |
| 78 | 0 | this.setSize(550, 600); |
| 79 | 0 | // Center the dialog |
| 80 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
| 81 | 0 | Dimension frameSize = this.getSize(); |
| 82 | 0 | if (frameSize.height > screenSize.height) { |
| 83 | 0 | frameSize.height = screenSize.height; |
| 84 | 0 | } |
| 85 | 0 | if (frameSize.width > screenSize.width) { |
| 86 | 0 | frameSize.width = screenSize.width; |
| 87 | 0 | } |
| 88 | 0 | this.setLocation((screenSize.width - frameSize.width) / 2, |
| 89 | 0 | (screenSize.height - frameSize.height) / 2); |
| 90 | 0 | |
| 91 | 0 | this.setContentPane(getContentPanel()); |
| 92 | 0 | this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); |
| 93 | 0 | } |
| 94 | ||
| 95 | /** | |
| 96 | * @return Returns the contentPanel. | |
| 97 | */ | |
| 98 | 0 | protected JPanel getContentPanel() { |
| 99 | 0 | if (contentPanel == null) { |
| 100 | 0 | contentPanel = new JPanel(); |
| 101 | 0 | contentPanel.setLayout(new BorderLayout()); |
| 102 | 0 | contentPanel.add(getWorkstationPanel(), BorderLayout.CENTER); |
| 103 | 0 | contentPanel.add(getButtonPanel(), BorderLayout.SOUTH); |
| 104 | 0 | } |
| 105 | 0 | return contentPanel; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * @return Returns the buttonPanel. | |
| 110 | */ | |
| 111 | 0 | protected JPanel getButtonPanel() { |
| 112 | 0 | if (buttonPanel == null) { |
| 113 | 0 | buttonPanel = new JPanel(); |
| 114 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("dialog.availableactions")); //$NON-NLS-1$ |
| 115 | 0 | buttonPanel.setBorder(titledBorder); |
| 116 | 0 | buttonPanel.setLayout(new GridLayout(1, 4)); |
| 117 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 118 | 0 | buttonPanel.add(getSaveWorkstationButton()); |
| 119 | 0 | buttonPanel.add(getClearWorkstationDataButton()); |
| 120 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 121 | 0 | } |
| 122 | 0 | return buttonPanel; |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * @return Returns the workstationPanel. | |
| 127 | */ | |
| 128 | 0 | protected WorkstationPanel getWorkstationPanel() { |
| 129 | 0 | if (workstationPanel == null) { |
| 130 | 0 | workstationPanel = new WorkstationPanel(workstation); |
| 131 | 0 | } |
| 132 | 0 | return workstationPanel; |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * @return Returns the clearWorkstationDataButton. | |
| 137 | */ | |
| 138 | 0 | protected JButton getClearWorkstationDataButton() { |
| 139 | 0 | if (clearWorkstationDataButton == null) { |
| 140 | 0 | clearWorkstationDataButton = new JButton(Messages.getString("button.clear")); //$NON-NLS-1$ |
| 141 | 0 | clearWorkstationDataButton.setIcon(new ImageIcon(this.getClass() |
| 142 | 0 | .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$ |
| 143 | 0 | |
| 144 | 0 | clearWorkstationDataButton.addActionListener(new ActionListener() { |
| 145 | public void actionPerformed(ActionEvent arg0) { | |
| 146 | logger.debug("actionPerformed clearWorkstationDataButton"); //$NON-NLS-1$ | |
| 147 | getWorkstationPanel().clearWorkstationData(); | |
| 148 | } | |
| 149 | }); | |
| 150 | 0 | } |
| 151 | 0 | return clearWorkstationDataButton; |
| 152 | } | |
| 153 | ||
| 154 | /** | |
| 155 | * @return Returns the saveWorkstationButton. | |
| 156 | */ | |
| 157 | 0 | protected JButton getSaveWorkstationButton() { |
| 158 | 0 | if (saveWorkstationButton == null) { |
| 159 | 0 | saveWorkstationButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$ |
| 160 | 0 | saveWorkstationButton.setIcon(new ImageIcon(this.getClass() |
| 161 | 0 | .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$ |
| 162 | 0 | |
| 163 | 0 | saveWorkstationButton.addActionListener(new ActionListener() { |
| 164 | public void actionPerformed(ActionEvent arg0) { | |
| 165 | logger.debug("actionPerformed saveWorkstationButton"); //$NON-NLS-1$ | |
| 166 | SaveClientWorkstationCommand saveWorkstationCommand = new SaveClientWorkstationCommand( | |
| 167 | getWorkstationPanel(), workstation, | |
| 168 | createWorkstation); | |
| 169 | CommandExecutor.getInstance().executeCommand( | |
| 170 | saveWorkstationCommand, true); | |
| 171 | if (saveWorkstationCommand.getStatus() == SaveClientWorkstationCommand.SUCCESS_STATUS) | |
| 172 | setVisible(false); | |
| 173 | } | |
| 174 | ||
| 175 | }); | |
| 176 | ||
| 177 | 0 | } |
| 178 | 0 | return saveWorkstationButton; |
| 179 | } | |
| 180 | ||
| 181 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |