OSDN Git Service

f163d939ef09441ce2648f973c8a1c4c8a941282
[sudokuki/sudokuki.git] / src / classes / net / jankenpoi / sudokuki / ui / swing / AboutDialog.java
1 /*
2  * Sudokuki - essential sudoku game
3  * Copyright (C) 2007-2012 Sylvain Vedrenne
4  *
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.
9  *
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.
14  *
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/>.
17  */
18 package net.jankenpoi.sudokuki.ui.swing;
19
20 import static net.jankenpoi.i18n.I18n._;
21
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;
32 import java.net.URI;
33 import java.net.URISyntaxException;
34
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;
46
47 import net.jankenpoi.sudokuki.Version;
48 import net.jankenpoi.sudokuki.resources.UIResources;
49
50 @SuppressWarnings("serial")
51 public class AboutDialog extends JDialog {
52
53         private Frame parent;
54
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");
61
62         public AboutDialog(Frame parent) {
63                 super(parent, true);
64                 this.parent = parent;
65                 initComponents();
66                 setTitle(ABOUT_SUDOKUKI);
67                 pack();
68         }
69
70         private void initComponents() {
71                 URI sudokukiURI = null;
72                 try {
73                         sudokukiURI = new URI("http://sudokuki.sourceforge.net");
74                 } catch (URISyntaxException e1) {
75                         e1.printStackTrace();
76                 }
77                 URI forumURI = null;
78                 try {
79                         forumURI = new URI(
80                                         "http://sourceforge.net/projects/sudokuki/forums");
81                 } catch (URISyntaxException e1) {
82                         e1.printStackTrace();
83                 }
84
85                 JTabbedPane tabbedPane = new JTabbedPane();
86                 tabbedPane.addTab(INFORMATION, null, makeInfoPanel(sudokukiURI),
87                                 INFORMATION);
88
89                 tabbedPane.addTab(CONTRIBUTORS, null, makeTextPanel("<html><body>"
90                                 + "<table border=\"0\"><tr></tr>"
91                                 
92                                 + "<tr><td align=\"right\"><b>"
93                                 + _("Aritz Beraza")
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>"
105                                 + _("Janis Eisaks")
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>"
113                                 + _("Daneih Ismail")
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>"
125                                 + _("Jeanne Peng")
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)")
144                                 
145                                 + "</td>" + "</tr>" + "</table>"
146                                 + "</body></html>"), CONTRIBUTORS);
147
148                 tabbedPane
149                                 .addTab(FEEDBACK, null, makeFeedbackPanel(forumURI), FEEDBACK);
150
151                 tabbedPane
152                                 .addTab(TRANSFER,
153                                                 null,
154                                                 makeTextPanel("<html><body>"
155                                                                 + "<p>"
156                                                                 + _("<b>Sudokuki</b> is released under the terms of the GNU General Public License version 3 or later (GPL v3+).")
157                                                                 + "<br/>"
158                                                                 + "</p>"
159                                                                 + "<p>"
160                                                                 + _("The full license text is available in the file called COPYING that must be included in every copy of the program.")
161                                                                 + "<br/>"
162                                                                 + "</p>"
163                                                                 + "<p>"
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.")
165                                                                 + "<br/>"
166                                                                 + "</p>"
167                                                                 + "<p>"
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
173
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>";
175                 try {
176                         license_html = readTextFile("text/COPYING.html");
177                 } catch (IOException e) {
178                 }
179                 JEditorPane editPane = new JEditorPane("text/html", license_html);
180                 editPane.setEditable(false);
181                 {
182                         Color bgColor = new JPanel().getBackground();
183                         editPane.setBackground(new Color(bgColor.getRed(), bgColor
184                                         .getGreen(), bgColor.getBlue()));
185                 }
186                 editPane.setCaretPosition(0);
187                 JScrollPane scrollPane = new JScrollPane(editPane);
188                 tabbedPane.addTab(LICENSE, null, scrollPane, LICENSE);
189
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);
196                 add(tabbedPane);
197                 pack();
198                 setLocationRelativeTo(parent);
199         }
200
201         protected JComponent makeTextPanel(String text) {
202                 JEditorPane editPane = new JEditorPane("text/html", text);
203                 {
204                         Color bgColor = new JPanel().getBackground();
205                         editPane.setBackground(new Color(bgColor.getRed(), bgColor
206                                         .getGreen(), bgColor.getBlue()));
207                 }
208                 editPane.setEditable(false);
209                 editPane.setCaretPosition(0);
210                 JScrollPane scrollPane = new JScrollPane(editPane);
211                 return scrollPane;
212         }
213
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>");
222                 {
223                         Color bgColor = new JPanel().getBackground();
224                         infoPane.setBackground(new Color(bgColor.getRed(), bgColor
225                                         .getGreen(), bgColor.getBlue()));
226                 }
227                 infoPane.setEditable(false);
228                 infoPane.setCaretPosition(0);
229
230                 JPanel panel = new JPanel(false);
231                 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
232
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);
238
239                 textPanel.add(infoPane);
240                 panel.add(textPanel);
241
242                 JPanel linkPanel = new JPanel(false);
243                 JButton linkButton = new JButton();
244
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() {
252                         @Override
253                         public void actionPerformed(ActionEvent e) {
254                                 AboutDialog.this.open(sudokukiURI);
255                         }
256                 });
257                 linkButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
258                 linkPanel.add(linkButton);
259                 panel.add(linkPanel);
260
261                 JScrollPane scrollPaneFeedback = new JScrollPane(panel);
262                 return scrollPaneFeedback;
263         }
264
265         protected JComponent makeFeedbackPanel(final URI forumURI) {
266                 JPanel panel = new JPanel(false);
267                 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
268
269                 String feedbackStr = "<html>"
270                                 + "<body><p></p><p>"
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()));
279
280                 JPanel feedbackPanel = new JPanel(false);
281                 feedbackPanel.add(feedbackPane);
282
283                 panel.add(feedbackPanel);
284
285                 JPanel linkPanel = new JPanel(false);
286                 JButton linkButton = new JButton();
287
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() {
295                         @Override
296                         public void actionPerformed(ActionEvent e) {
297                                 AboutDialog.this.open(forumURI);
298                         }
299                 });
300                 linkButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
301                 linkPanel.add(linkButton);
302                 panel.add(linkPanel);
303
304                 JScrollPane scrollPaneFeedback = new JScrollPane(panel);
305                 return scrollPaneFeedback;
306         }
307
308         private void open(URI uri) {
309                 if (Desktop.isDesktopSupported()) {
310                         Desktop desktop = Desktop.getDesktop();
311                         try {
312                                 desktop.browse(uri);
313                         } catch (IOException e) {
314                                 e.printStackTrace();
315                         }
316                 } else {
317                         System.out.println("Desktop.isDesktopSupported() returned false");
318                 }
319         }
320
321         private static String readTextFile(String path) throws IOException {
322
323                 InputStream is = UIResources.class.getResourceAsStream(path);
324                 InputStreamReader isr = new InputStreamReader(is);
325                 BufferedReader br = new BufferedReader(isr);
326                 StringBuffer sb = new StringBuffer();
327                 String line;
328                 while ((line = br.readLine()) != null) {
329                         sb.append(line + "\n");
330                 }
331                 br.close();
332                 isr.close();
333                 is.close();
334                 return sb.toString();
335         }
336
337 }