]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/AboutScreen.java
Version 9, February 2010
[GpsPrune.git] / tim / prune / function / AboutScreen.java
1 package tim.prune.function;
2
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.Font;
8 import java.awt.GridBagConstraints;
9 import java.awt.GridBagLayout;
10 import java.awt.event.ActionEvent;
11 import java.awt.event.ActionListener;
12 import java.awt.event.KeyEvent;
13 import java.awt.event.KeyListener;
14 import java.io.InputStream;
15
16 import javax.swing.BorderFactory;
17 import javax.swing.BoxLayout;
18 import javax.swing.JButton;
19 import javax.swing.JDialog;
20 import javax.swing.JEditorPane;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTabbedPane;
25 import javax.swing.JTextArea;
26
27 import tim.prune.App;
28 import tim.prune.ExternalTools;
29 import tim.prune.GenericFunction;
30 import tim.prune.GpsPruner;
31 import tim.prune.I18nManager;
32 import tim.prune.threedee.WindowFactory;
33
34 /**
35  * Class to represent the "About" popup window
36  */
37 public class AboutScreen extends GenericFunction
38 {
39         private JDialog _dialog = null;
40         private JTabbedPane _tabs = null;
41         private JButton _okButton = null;
42         /** Labels for whether tools installed or not */
43         private JLabel[] _installedLabels = null;
44
45
46         /**
47          * Constructor
48          * @param inApp app object
49          */
50         public AboutScreen(App inApp)
51         {
52                 super(inApp);
53         }
54
55         /**
56          * Return the name key for this function
57          */
58         public String getNameKey()
59         {
60                 return "function.about";
61         }
62
63         /**
64          * @return the contents of the window as a Component
65          */
66         private Component makeContents()
67         {
68                 JPanel mainPanel = new JPanel();
69                 mainPanel.setLayout(new BorderLayout());
70
71                 _tabs = new JTabbedPane();
72                 mainPanel.add(_tabs, BorderLayout.CENTER);
73
74                 JPanel aboutPanel = new JPanel();
75                 aboutPanel.setLayout(new BoxLayout(aboutPanel, BoxLayout.Y_AXIS));
76                 aboutPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
77                 JLabel titleLabel = new JLabel("Prune");
78                 titleLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
79                 titleLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
80                 aboutPanel.add(titleLabel);
81                 JLabel versionLabel = new JLabel(I18nManager.getText("dialog.about.version") + ": " + GpsPruner.VERSION_NUMBER);
82                 versionLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
83                 aboutPanel.add(versionLabel);
84                 JLabel buildLabel = new JLabel(I18nManager.getText("dialog.about.build") + ": " + GpsPruner.BUILD_NUMBER);
85                 buildLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
86                 aboutPanel.add(buildLabel);
87                 aboutPanel.add(new JLabel(" "));
88                 StringBuffer descBuffer = new StringBuffer();
89                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext1")).append("</p>");
90                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext2")).append("</p>");
91                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext3")).append("</p>");
92                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.languages")).append(" : ")
93                         .append("deutsch, english, espa\u00F1ol, fran\u00E7ais, italiano, polski, \u4e2d\u6587; (chinese)<br>" +
94                                 "schwiizerd\u00FC\u00FCtsch, \u65E5\u672C\u8A9E (japanese), t\u00FCrk\u00E7e, portugu\u00EAs, " +
95                                 "bahasa indonesia, rom\u00E2n\u0103").append("</p>");
96                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.translatedby")).append("</p>");
97                 JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
98                 descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
99                 descPane.setEditable(false);
100                 descPane.setOpaque(false);
101                 descPane.setAlignmentX(JEditorPane.CENTER_ALIGNMENT);
102
103                 aboutPanel.add(descPane);
104                 aboutPanel.add(new JLabel(" "));
105                 _tabs.add(I18nManager.getText("function.about"), aboutPanel);
106
107                 // Second pane for system info
108                 JPanel sysInfoPanel = new JPanel();
109                 GridBagLayout gridBag = new GridBagLayout();
110                 sysInfoPanel.setLayout(gridBag);
111                 GridBagConstraints constraints = new GridBagConstraints();
112                 constraints.weightx = 0.0; constraints.weighty = 0.0;
113                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
114                         new JLabel(I18nManager.getText("dialog.about.systeminfo.os") + " : "),
115                         0, 0);
116                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
117                         new JLabel(System.getProperty("os.name")),
118                         1, 0);
119                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
120                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
121                         0, 1);
122                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
123                         new JLabel(System.getProperty("java.runtime.version")),
124                         1, 1);
125                 // Create install labels to be populated later
126                 final int NUM_INSTALL_CHECKS = 4;
127                 _installedLabels = new JLabel[NUM_INSTALL_CHECKS];
128                 for (int i=0; i<NUM_INSTALL_CHECKS; i++) {
129                         _installedLabels[i] = new JLabel("...");
130                 }
131                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
132                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
133                         0, 2);
134                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[0], 1, 2);
135                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
136                         new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
137                         0, 3);
138                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[1], 1, 3);
139                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
140                         new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
141                         0, 4);
142                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[2], 1, 4);
143                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
144                         new JLabel(I18nManager.getText("dialog.about.systeminfo.gnuplot") + " : "),
145                         0, 5);
146                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[3], 1, 5);
147                 _tabs.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
148
149                 // Third pane for credits
150                 JPanel creditsPanel = new JPanel();
151                 gridBag = new GridBagLayout();
152                 creditsPanel.setLayout(gridBag);
153                 constraints = new GridBagConstraints();
154                 constraints.weightx = 0.0; constraints.weighty = 0.0;
155
156                 addToGridBagPanel(creditsPanel, gridBag, constraints,
157                         new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
158                         0, 0);
159                 addToGridBagPanel(creditsPanel, gridBag, constraints,
160                         new JLabel("activityworkshop.net"),
161                         1, 0);
162                 addToGridBagPanel(creditsPanel, gridBag, constraints,
163                         new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
164                         0, 1);
165                 addToGridBagPanel(creditsPanel, gridBag, constraints,
166                         new JLabel("Drew Noakes"),
167                         1, 1);
168                 addToGridBagPanel(creditsPanel, gridBag, constraints,
169                         new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
170                         0, 2);
171                 addToGridBagPanel(creditsPanel, gridBag, constraints,
172                         new JLabel("Eclipse"),
173                         1, 2);
174                 addToGridBagPanel(creditsPanel, gridBag, constraints,
175                         new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
176                         0, 3);
177                 addToGridBagPanel(creditsPanel, gridBag, constraints,
178                         new JLabel("Ramon, Miguel, In\u00E9s, Piotr, Petrovsk, Josatoc, Weehal,"),
179                         1, 3);
180                 addToGridBagPanel(creditsPanel, gridBag, constraints,
181                         new JLabel(" theYinYeti, Rothermographer, Sam, Rudolph, nazotoko, katpatuka"),
182                         1, 4);
183                 addToGridBagPanel(creditsPanel, gridBag, constraints,
184                         new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
185                         0, 5);
186                 addToGridBagPanel(creditsPanel, gridBag, constraints,
187                         new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
188                         1, 5);
189                 addToGridBagPanel(creditsPanel, gridBag, constraints,
190                         new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
191                         0, 6);
192                 addToGridBagPanel(creditsPanel, gridBag, constraints,
193                         new JLabel("Debian Linux, Sun Java, Eclipse, Svn, Gimp, Inkscape"),
194                         1, 6);
195                 addToGridBagPanel(creditsPanel, gridBag, constraints,
196                         new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
197                         0, 7);
198                 addToGridBagPanel(creditsPanel, gridBag, constraints,
199                         new JLabel("Openstreetmap, Povray, Exiftool, Google Earth, Gpsbabel, Gnuplot"),
200                         1, 7);
201                 addToGridBagPanel(creditsPanel, gridBag, constraints,
202                         new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
203                         0, 8);
204                 addToGridBagPanel(creditsPanel, gridBag, constraints,
205                         new JLabel("Friends and loved ones, for encouragement and support"),
206                         1, 8);
207                 _tabs.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
208
209                 // Read me
210                 JPanel readmePanel = new JPanel();
211                 readmePanel.setLayout(new BorderLayout());
212                 JTextArea textArea = new JTextArea(getReadmeText());
213                 textArea.setEditable(false);
214                 textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
215                 JScrollPane scrollPane = new JScrollPane(textArea);
216                 scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
217                 scrollPane.setPreferredSize(new Dimension(600, 130));
218                 readmePanel.add(scrollPane, BorderLayout.CENTER);
219                 _tabs.add(I18nManager.getText("dialog.about.readme"), readmePanel);
220
221                 // OK button at the bottom
222                 JPanel okPanel = new JPanel();
223                 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
224                 _okButton = new JButton(I18nManager.getText("button.ok"));
225                 _okButton.addActionListener(new ActionListener()
226                 {
227                         public void actionPerformed(ActionEvent e)
228                         {
229                                 _dialog.dispose();
230                         }
231                 });
232                 _okButton.addKeyListener(new KeyListener() {
233                         public void keyPressed(KeyEvent e)
234                         {
235                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
236                         }
237                         public void keyTyped(KeyEvent e) {}
238                         public void keyReleased(KeyEvent e) {}
239                 });
240                 okPanel.add(_okButton);
241                 mainPanel.add(okPanel, BorderLayout.SOUTH);
242                 return mainPanel;
243         }
244
245         /**
246          * Helper function to reduce complexity of gui-making code
247          * when adding labels to a GridBagLayout
248          * @param inPanel panel to add to
249          * @param inLayout GridBagLayout object
250          * @param inConstraints GridBagConstraints object
251          * @param inLabel label to add
252          * @param inX grid x
253          * @param inY grid y
254          */
255         private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout,
256                 GridBagConstraints inConstraints, JLabel inLabel, int inX, int inY)
257         {
258                 // set x and y in constraints
259                 inConstraints.gridx = inX;
260                 inConstraints.gridy = inY;
261                 // set anchor
262                 inConstraints.anchor = (inX == 0?GridBagConstraints.EAST:GridBagConstraints.WEST);
263                 // set constraints to label
264                 inLayout.setConstraints(inLabel, inConstraints);
265                 // add label to panel
266                 inPanel.add(inLabel);
267         }
268
269         /**
270          * @return text from the readme file
271          */
272         private String getReadmeText()
273         {
274                 try
275                 {
276                         // For some reason using ../readme.txt doesn't work, so need absolute path
277                         InputStream in = AboutScreen.class.getResourceAsStream("/tim/prune/readme.txt");
278                         if (in != null) {
279                                 byte[] buffer = new byte[in.available()];
280                                 in.read(buffer);
281                                 return new String(buffer);
282                         }
283                 }
284                 catch (java.io.IOException e) {
285                         System.err.println("Exception trying to get readme : " + e.getMessage());
286                 }
287                 return I18nManager.getText("error.readme.notfound");
288         }
289
290         /**
291          * Show window
292          */
293         public void begin()
294         {
295                 if (_dialog == null)
296                 {
297                         _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
298                         _dialog.getContentPane().add(makeContents());
299                         _dialog.pack();
300                 }
301                 _tabs.setSelectedIndex(0);
302                 checkInstalls();
303                 _dialog.setVisible(true);
304                 _okButton.requestFocus();
305         }
306
307         /**
308          * Check the installed components and set the label texts accordingly
309          */
310         private void checkInstalls()
311         {
312                 String yesText = I18nManager.getText("dialog.about.yes");
313                 String noText = I18nManager.getText("dialog.about.no");
314                 _installedLabels[0].setText(WindowFactory.isJava3dEnabled()?yesText:noText);
315                 final int[] tools = {ExternalTools.TOOL_EXIFTOOL, ExternalTools.TOOL_GPSBABEL, ExternalTools.TOOL_GNUPLOT};
316                 for (int i=0; i<tools.length; i++) {
317                         _installedLabels[i+1].setText(ExternalTools.isToolInstalled(tools[i])?yesText:noText);
318                 }
319         }
320 }