2 * Sudokuki - essential sudoku game
3 * Copyright (C) 2007-2012 Sylvain Vedrenne
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.jankenpoi.sudokuki.ui.swing;
20 import static net.jankenpoi.i18n.I18n._;
22 import java.awt.Color;
23 import java.awt.Desktop;
24 import java.awt.Dimension;
25 import java.awt.Frame;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.io.BufferedReader;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.InputStreamReader;
33 import java.net.URISyntaxException;
35 import javax.swing.BoxLayout;
36 import javax.swing.ImageIcon;
37 import javax.swing.JButton;
38 import javax.swing.JComponent;
39 import javax.swing.JDialog;
40 import javax.swing.JEditorPane;
41 import javax.swing.JLabel;
42 import javax.swing.JPanel;
43 import javax.swing.JScrollPane;
44 import javax.swing.JTabbedPane;
45 import javax.swing.SwingConstants;
47 import net.jankenpoi.sudokuki.Version;
48 import net.jankenpoi.sudokuki.resources.UIResources;
50 @SuppressWarnings("serial")
51 public class AboutDialog extends JDialog {
55 private final String ABOUT_SUDOKUKI = _("About Sudokuki...");
56 private final String INFORMATION = _("Information");
57 private final String CONTRIBUTORS = _("Contributors");
58 private final String FEEDBACK = _("Feedback");
59 private final String TRANSFER = _("Transfer");
60 private final String LICENSE = _("License");
62 public AboutDialog(Frame parent) {
66 setTitle(ABOUT_SUDOKUKI);
70 private void initComponents() {
71 URI sudokukiURI = null;
73 sudokukiURI = new URI("http://sudokuki.sourceforge.net");
74 } catch (URISyntaxException e1) {
80 "http://sourceforge.net/projects/sudokuki/forums");
81 } catch (URISyntaxException e1) {
85 JTabbedPane tabbedPane = new JTabbedPane();
86 tabbedPane.addTab(INFORMATION, null, makeInfoPanel(sudokukiURI),
89 tabbedPane.addTab(CONTRIBUTORS, null, makeTextPanel("<html><body>"
90 + "<table border=\"0\"><tr></tr>"
92 + "<tr><td align=\"right\"><b>"
94 + "</b></td><td></td><td align=\"left\">"
95 + _("Spanish translations (v1.0)")
96 + "</td></tr><tr><td align=\"right\"><b>"
97 + _("Jeroen P. Broks")
98 + "</b></td><td></td><td align=\"left\">"
99 + _("Dutch translations")
100 + "</td></tr><tr><td align=\"right\"><b>"
101 + _("Helene Damianakos")
102 + "</b></td><td></td><td align=\"left\">"
103 + _("Greek translations (v1.0)")
104 + "</td></tr><tr><td align=\"right\"><b>"
106 + "</b></td><td></td><td align=\"left\">"
107 + _("Latvian translations")
108 + "</td></tr><tr><td align=\"right\"><b>"
109 + _("Rafael Ferreira")
110 + "</b></td><td></td><td align=\"left\">"
111 + _("Brazilian Portuguese translations")
112 + "</td></tr><tr><td align=\"right\"><b>"
114 + "</b></td><td></td><td align=\"left\">"
115 + _("Arabic translations")
116 + "</td></tr><tr><td align=\"right\"><b>"
117 + _("Stavros Mavrakis")
118 + "</b></td><td></td><td align=\"left\">"
119 + _("Greek translations")
120 + "</td></tr><tr><td align=\"right\"><b>"
121 + _("Fumiaki Nakanishi")
122 + "</b></td><td></td><td align=\"left\">"
123 + _("Japanese translations")
124 + "</td></tr><tr><td align=\"right\"><b>"
126 + "</b></td><td></td><td align=\"left\">"
127 + _("Chinese translations")
128 + "</td></tr><tr><td align=\"right\"><b>"
129 + _("Claus Poerschke")
130 + "</b></td><td></td><td align=\"left\">"
131 + _("Patches (v1.0) and German translations")
132 + "</td></tr><tr><td align=\"right\"><b>"
133 + _("Dmitry Salnikov")
134 + "</b></td><td></td><td align=\"left\">"
135 + _("Portuguese and Russian translations")
136 + "</td></tr><tr><td align=\"right\"><b>"
137 + _("Helene Vedrenne")
138 + "</b></td><td></td><td align=\"left\">"
139 + _("Japanese translations")
140 + "</td></tr><tr><td align=\"right\"><b>"
141 + _("Sylvain Vedrenne")
142 + "</b></td><td></td><td align=\"left\">"
143 + _("Esperanto, French, and Japanese translations (v1.0)")
145 + "</td>" + "</tr>" + "</table>"
146 + "</body></html>"), CONTRIBUTORS);
149 .addTab(FEEDBACK, null, makeFeedbackPanel(forumURI), FEEDBACK);
154 makeTextPanel("<html><body>"
156 + _("<b>Sudokuki</b> is released under the terms of the GNU General Public License version 3 or later (GPL v3+).")
160 + _("The full license text is available in the file called COPYING that must be included in every copy of the program.")
164 + _("This program is Free Software (\"Free\" as in \"Freedom\") developped during the author's free-time in the hope that some users will find it useful, but WITHOUT ANY WARRANTY of any kind.")
168 + _("You are welcome to transfer this program to other people as long as you respect the license terms. Read the GNU General Public License for more details.")
169 + "<br/>" + "</p>" + "<p>"
170 + _("Copyright (C) 2007-2012 Sylvain Vedrenne")
171 + "<br/>" + "</p>" + "</body></html>"),
172 TRANSFER); // tooltip text
174 String license_html = "<html> <table border=\"0\"> <tr> <td>Please visit:</td> </tr><tr> <td>http://www.gnu.org/licenses/gpl.html</td> </tr>";
176 license_html = readTextFile("text/COPYING.html");
177 } catch (IOException e) {
179 JEditorPane editPane = new JEditorPane("text/html", license_html);
180 editPane.setEditable(false);
182 Color bgColor = new JPanel().getBackground();
183 editPane.setBackground(new Color(bgColor.getRed(), bgColor
184 .getGreen(), bgColor.getBlue()));
186 editPane.setCaretPosition(0);
187 JScrollPane scrollPane = new JScrollPane(editPane);
188 tabbedPane.addTab(LICENSE, null, scrollPane, LICENSE);
190 Dimension parentDim = parent.getPreferredSize();
191 Dimension dim = new Dimension();
192 double width = parentDim.getHeight() * 1.4;
193 double height = parentDim.getWidth() * 1.3;
194 dim.setSize(width, height);
195 tabbedPane.setPreferredSize(dim);
198 setLocationRelativeTo(parent);
201 protected JComponent makeTextPanel(String text) {
202 JEditorPane editPane = new JEditorPane("text/html", text);
204 Color bgColor = new JPanel().getBackground();
205 editPane.setBackground(new Color(bgColor.getRed(), bgColor
206 .getGreen(), bgColor.getBlue()));
208 editPane.setEditable(false);
209 editPane.setCaretPosition(0);
210 JScrollPane scrollPane = new JScrollPane(editPane);
214 protected JComponent makeInfoPanel(final URI sudokukiURI) {
215 JPanel textPanel = new JPanel();
216 JEditorPane infoPane = new JEditorPane("text/html", "<html>"
217 + "<table border=\"0\">" + "<tr>" + "<td align=\"center\"><b>"
218 + Version.versionString + "</b></td>" + "</tr>" + "<tr>"
219 + "<td align=\"center\">"
220 + _("Copyright (C) 2007-2012 Sylvain Vedrenne") + "</td>"
221 + "</tr>" + "</table>" + "</html>");
223 Color bgColor = new JPanel().getBackground();
224 infoPane.setBackground(new Color(bgColor.getRed(), bgColor
225 .getGreen(), bgColor.getBlue()));
227 infoPane.setEditable(false);
228 infoPane.setCaretPosition(0);
230 JPanel panel = new JPanel(false);
231 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
233 JPanel iconPanel = new JPanel(false);
234 ImageIcon icon = Images.ICON_APPLICATION_LOGO;
235 JLabel iconLabel = new JLabel(icon);
236 iconPanel.add(iconLabel);
237 panel.add(iconPanel);
239 textPanel.add(infoPane);
240 panel.add(textPanel);
242 JPanel linkPanel = new JPanel(false);
243 JButton linkButton = new JButton();
245 linkButton.setText("<HTML><FONT color=\"#000099\"><U>Sudokuki "
246 + _("on the Web") + "</U></FONT></HTML>");
247 linkButton.setHorizontalAlignment(SwingConstants.CENTER);
248 linkButton.setBorderPainted(false);
249 linkButton.setOpaque(false);
250 linkButton.setToolTipText(sudokukiURI.toString());
251 linkButton.addActionListener(new ActionListener() {
253 public void actionPerformed(ActionEvent e) {
254 AboutDialog.this.open(sudokukiURI);
257 linkButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
258 linkPanel.add(linkButton);
259 panel.add(linkPanel);
261 JScrollPane scrollPaneFeedback = new JScrollPane(panel);
262 return scrollPaneFeedback;
265 protected JComponent makeFeedbackPanel(final URI forumURI) {
266 JPanel panel = new JPanel(false);
267 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
269 String feedbackStr = "<html>"
271 + _("Feel free to request features and report bugs<br/>on the Sudokuki Forums hosted by Sourceforge!")
272 + "</p></body>" + "</html>";
273 JEditorPane feedbackPane = new JEditorPane("text/html", feedbackStr);
274 feedbackPane.setEditable(false);
275 feedbackPane.setCaretPosition(0);
276 Color bgColor = panel.getBackground();
277 feedbackPane.setBackground(new Color(bgColor.getRed(), bgColor
278 .getGreen(), bgColor.getBlue()));
280 JPanel feedbackPanel = new JPanel(false);
281 feedbackPanel.add(feedbackPane);
283 panel.add(feedbackPanel);
285 JPanel linkPanel = new JPanel(false);
286 JButton linkButton = new JButton();
288 linkButton.setText("<HTML><FONT color=\"#000099\"><U>"
289 + _("Sudokuki Forums") + "</U></FONT></HTML>");
290 linkButton.setHorizontalAlignment(SwingConstants.CENTER);
291 linkButton.setBorderPainted(false);
292 linkButton.setOpaque(false);
293 linkButton.setToolTipText(forumURI.toString());
294 linkButton.addActionListener(new ActionListener() {
296 public void actionPerformed(ActionEvent e) {
297 AboutDialog.this.open(forumURI);
300 linkButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
301 linkPanel.add(linkButton);
302 panel.add(linkPanel);
304 JScrollPane scrollPaneFeedback = new JScrollPane(panel);
305 return scrollPaneFeedback;
308 private void open(URI uri) {
309 if (Desktop.isDesktopSupported()) {
310 Desktop desktop = Desktop.getDesktop();
313 } catch (IOException e) {
317 System.out.println("Desktop.isDesktopSupported() returned false");
321 private static String readTextFile(String path) throws IOException {
323 InputStream is = UIResources.class.getResourceAsStream(path);
324 InputStreamReader isr = new InputStreamReader(is);
325 BufferedReader br = new BufferedReader(isr);
326 StringBuffer sb = new StringBuffer();
328 while ((line = br.readLine()) != null) {
329 sb.append(line + "\n");
334 return sb.toString();