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.panel.SessionPanel;
40 import base.session.Session;
41
42 @SuppressWarnings("serial")
43 public class SessionDialog extends JDialog {
44
45 private static final transient Logger logger = Logger
46 .getLogger(SessionDialog.class.getName());
47
48 private JPanel contentPanel;
49
50 private JPanel buttonPanel;
51
52 private JButton saveSessionButton;
53
54 private SessionPanel sessionPanel;
55
56 private Session session;
57
58 public SessionDialog(Session session) {
59 this.session = session;
60 initialize();
61 }
62
63 protected void initialize() {
64 this.setResizable(false);
65 this.setSize(550, 600);
66
67 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
68 Dimension frameSize = this.getSize();
69 if (frameSize.height > screenSize.height) {
70 frameSize.height = screenSize.height;
71 }
72 if (frameSize.width > screenSize.width) {
73 frameSize.width = screenSize.width;
74 }
75 this.setLocation((screenSize.width - frameSize.width) / 2,
76 (screenSize.height - frameSize.height) / 2);
77
78 this.setContentPane(getContentPanel());
79 this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
80 }
81
82 /***
83 * @return Returns the contentPanel.
84 */
85 protected JPanel getContentPanel() {
86 if (contentPanel == null) {
87 contentPanel = new JPanel();
88 contentPanel.setLayout(new BorderLayout());
89 contentPanel.add(getSessionPanel(), BorderLayout.CENTER);
90 contentPanel.add(getButtonPanel(), BorderLayout.SOUTH);
91 }
92 return contentPanel;
93 }
94
95 /***
96 * @return Returns the sessionPanel.
97 */
98 protected SessionPanel getSessionPanel() {
99 if (sessionPanel == null) {
100 sessionPanel = new SessionPanel(session);
101 }
102 return sessionPanel;
103 }
104
105 /***
106 * @return Returns the buttonPanel.
107 */
108 protected JPanel getButtonPanel() {
109 if (buttonPanel == null) {
110 buttonPanel = new JPanel();
111 TitledBorder titledBorder = new TitledBorder(Messages.getString("dialog.availableactions"));
112 buttonPanel.setBorder(titledBorder);
113 buttonPanel.setLayout(new GridLayout(1, 3));
114 buttonPanel.add(new JLabel(""));
115 buttonPanel.add(getSaveSessionButton());
116 buttonPanel.add(new JLabel(""));
117 }
118 return buttonPanel;
119 }
120
121 /***
122 * @return Returns the saveSessionButton.
123 */
124 protected JButton getSaveSessionButton() {
125 if (saveSessionButton == null) {
126 saveSessionButton = new JButton(Messages.getString("button.save"));
127 saveSessionButton.setIcon(new ImageIcon(this.getClass()
128 .getResource("/icon/16x16/actions/document-save.png")));
129
130 saveSessionButton.addActionListener(new ActionListener() {
131 public void actionPerformed(ActionEvent arg0) {
132 logger.debug("actionPerformed saveButton");
133 if (session != null) {
134 session.setDescription(getSessionPanel()
135 .getSessionDescription());
136 setVisible(false);
137 }
138 }
139 });
140 }
141 return saveSessionButton;
142 }
143 }