View Javadoc

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.frame;
21  
22  import java.awt.BorderLayout;
23  import java.awt.FlowLayout;
24  import java.awt.event.ActionEvent;
25  import java.awt.event.ActionListener;
26  
27  import javax.swing.JButton;
28  import javax.swing.JDialog;
29  import javax.swing.JFrame;
30  import javax.swing.JPanel;
31  import javax.swing.JScrollPane;
32  import javax.swing.border.TitledBorder;
33  
34  import org.apache.log4j.Logger;
35  
36  import ui.Messages;
37  import ui.util.MessageLogger;
38  
39  @SuppressWarnings("serial") //$NON-NLS-1$
40  public class MessageFrame extends JFrame {
41  
42  	private static final transient Logger logger = Logger
43  			.getLogger(MessageFrame.class.getName());
44  
45  	private JPanel contentPanel;
46  
47  	private JPanel buttonPanel;
48  
49  	private JScrollPane messageScrollPanel;
50  
51  	private JPanel messagePanel;
52  
53  	private static MessageFrame instance = null;
54  
55  	public static MessageFrame getInstance() {
56  		return instance == null ? instance = new MessageFrame() : instance;
57  	}
58  
59  	protected MessageFrame() {
60  		initialize();
61  	}
62  
63  	protected void initialize() {
64  		this.setSize(300, 600);
65  		this.setResizable(true);
66  		this.setContentPane(getContentPanel());
67  		this.setAlwaysOnTop(true);
68  		this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
69  	}
70  
71  	/***
72  	 * @return Returns the contentPanel.
73  	 */
74  	protected JPanel getContentPanel() {
75  		if (contentPanel == null) {
76  			contentPanel = new JPanel();
77  			TitledBorder titledBorder = new TitledBorder(Messages.getString("common.messages")); //$NON-NLS-1$
78  			contentPanel.setBorder(titledBorder);
79  			contentPanel.setLayout(new BorderLayout());
80  			contentPanel.add(getMessageScrollPanel(), BorderLayout.CENTER);
81  			contentPanel.add(getButtonPanel(), BorderLayout.SOUTH);
82  		}
83  		return contentPanel;
84  	}
85  
86  	/***
87  	 * @return Returns the messageScrollPanel.
88  	 */
89  	protected JScrollPane getMessageScrollPanel() {
90  		if (messageScrollPanel == null) {
91  			messageScrollPanel = new JScrollPane();
92  			messageScrollPanel.setViewportView(getMessagePanel());
93  			messageScrollPanel
94  					.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
95  			messageScrollPanel
96  					.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
97  		}
98  		return messageScrollPanel;
99  	}
100 
101 	/***
102 	 * @return Returns the messagePanel.
103 	 */
104 	protected JPanel getMessagePanel() {
105 		if (messagePanel == null) {
106 			messagePanel = MessageLogger.getMessagePanel();
107 		}
108 		return messagePanel;
109 	}
110 
111 	/***
112 	 * @return Returns the buttonPanel.
113 	 */
114 	protected JPanel getButtonPanel() {
115 		if (buttonPanel == null) {
116 			buttonPanel = new JPanel();
117 			TitledBorder titledBorder = new TitledBorder(Messages.getString("dialog.availableactions")); //$NON-NLS-1$
118 			buttonPanel.setBorder(titledBorder);
119 			buttonPanel.setLayout(new FlowLayout());
120 			JButton saveButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
121 			JButton clearButton = new JButton(Messages.getString("button.clear")); //$NON-NLS-1$
122 			JButton closeButton = new JButton(Messages.getString("button.close")); //$NON-NLS-1$
123 
124 			// buttonPanel.add(saveButton);
125 			buttonPanel.add(clearButton);
126 			buttonPanel.add(closeButton);
127 
128 			saveButton.addActionListener(new ActionListener() {
129 				public void actionPerformed(ActionEvent arg0) {
130 					logger.debug("actionPerformed saveButton"); //$NON-NLS-1$
131 				}
132 			});
133 
134 			clearButton.addActionListener(new ActionListener() {
135 				public void actionPerformed(ActionEvent arg0) {
136 					logger.debug("actionPerformed clearButton"); //$NON-NLS-1$
137 					getMessagePanel().removeAll();
138 					getMessagePanel().updateUI();
139 				}
140 			});
141 
142 			closeButton.addActionListener(new ActionListener() {
143 				public void actionPerformed(ActionEvent arg0) {
144 					logger.debug("actionPerformed closeButton"); //$NON-NLS-1$
145 					setVisible(false);
146 				}
147 			});
148 
149 		}
150 		return buttonPanel;
151 	}
152 
153 }