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