OSDN Git Service

2de38f8ba8e7b945e4965d8352aa30145426adec
[sudokuki/sudokuki.git] / src / classes / net / jankenpoi / sudokuki / ui / swing / TranslateDialog.java
1 /*
2  * Sudokuki - essential sudoku game
3  * Copyright (C) 2007-2016 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.gtxt;
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.IOException;
29 import java.net.URI;
30 import java.net.URISyntaxException;
31
32 import javax.swing.BoxLayout;
33 import javax.swing.JButton;
34 import javax.swing.JDialog;
35 import javax.swing.JLabel;
36 import javax.swing.JPanel;
37 import javax.swing.SwingConstants;
38
39 @SuppressWarnings("serial")
40 public class TranslateDialog extends JDialog {
41
42         private Frame parent;
43
44         public TranslateDialog(Frame parent) {
45                 super(parent, true);
46                 this.parent = parent;
47                 initComponents();
48                 // setResizable(false);
49                 setTitle(gtxt("Translate this application"));
50                 pack();
51         }
52
53         private void initComponents() {
54                 URI sudokukiURI = null;
55                 try {
56                         sudokukiURI = new URI("http://sourceforge.net/projects/sudokuki/forums/forum/1801058");
57                 } catch (URISyntaxException e1) {
58                         e1.printStackTrace();
59                 }
60
61                 JPanel panel = makeInfoPanel(sudokukiURI);
62
63
64
65                 Dimension parentDim = parent.getPreferredSize();
66                 Dimension dim = new Dimension();
67                 dim.setSize(parentDim.getHeight() * 1.75, parentDim.getWidth() * 1.25);
68                 add(panel);
69                 pack();
70                 setLocationRelativeTo(parent);
71         }
72
73         protected JPanel makeInfoPanel(final URI sudokukiURI) {
74                 JPanel panel = new JPanel(false);
75                 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
76
77                 JPanel feedbackPanel = new JPanel(false);
78                 String feedbackStr = "<html>"
79                                 + "<table border=\"0\">"
80                                 + "<tr>"
81                                 + "</tr>"
82                                 + "<tr>"
83                                 + gtxt("You can easily translate Sudokuki into your own language!")+"<br/>"
84                                 +"<br/>"
85                                 + "</tr>"
86                                 + "<tr>"
87                                 + gtxt("Propose your help and get information on how to proceed<br/> on the Translators Forum hosted by Sourceforge:")+"<br/>"
88                                 + "</tr>"
89                                 + "<tr>"
90                                 + "</tr>" + "<tr>" + "</tr>" + "</table>" + "</html>";
91                 JLabel label = new JLabel(feedbackStr);
92                 feedbackPanel.add(label);
93
94                 panel.add(feedbackPanel);
95
96                 JPanel linkPanel = new JPanel(false);
97                 JButton linkButton = new JButton();
98
99                 linkButton
100                                 .setText("<HTML><FONT color=\"#000099\"><U>"+gtxt("Sudokuki Translators Forum")+"</U></FONT></HTML>");
101                 linkButton.setHorizontalAlignment(SwingConstants.CENTER);
102                 linkButton.setBorderPainted(false);
103                 linkButton.setOpaque(false);
104                 linkButton.setBackground(Color.WHITE);
105                 linkButton.setToolTipText(sudokukiURI.toString());
106                 linkButton.addActionListener(new ActionListener() {
107                         @Override
108                         public void actionPerformed(ActionEvent e) {
109                                 TranslateDialog.this.open(sudokukiURI);
110                         }
111                 });
112                 linkButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
113                 linkPanel.add(linkButton);
114                 panel.add(linkPanel);
115
116                 return panel;
117         }
118
119         private void open(URI uri) {
120                 if (Desktop.isDesktopSupported()) {
121                         Desktop desktop = Desktop.getDesktop();
122                         try {
123                                 desktop.browse(uri);
124                         } catch (IOException e) {
125                                 e.printStackTrace();
126                         }
127                 } else {
128                         // TODO: error handling
129                 }
130         }
131
132 }