]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/AboutScreen.java
Version 6, October 2008
[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ñol, français, italiano, polski,<br>" +
94                                 "schwiizerdüütsch, português, bahasa indonesia, română").append("</p>");
95                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.translatedby")).append("</p>");
96                 JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
97                 descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
98                 descPane.setEditable(false);
99                 descPane.setOpaque(false);
100                 descPane.setAlignmentX(JEditorPane.CENTER_ALIGNMENT);
101
102                 aboutPanel.add(descPane);
103                 aboutPanel.add(new JLabel(" "));
104                 _tabs.add(I18nManager.getText("function.about"), aboutPanel);
105
106                 // Second pane for system info
107                 JPanel sysInfoPanel = new JPanel();
108                 GridBagLayout gridBag = new GridBagLayout();
109                 sysInfoPanel.setLayout(gridBag);
110                 GridBagConstraints constraints = new GridBagConstraints();
111                 constraints.weightx = 0.0; constraints.weighty = 0.0;
112                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
113                         new JLabel(I18nManager.getText("dialog.about.systeminfo.os") + " : "),
114                         0, 0);
115                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
116                         new JLabel(System.getProperty("os.name")),
117                         1, 0);
118                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
119                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
120                         0, 1);
121                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
122                         new JLabel(System.getProperty("java.runtime.version")),
123                         1, 1);
124                 // Create install labels to be populated later
125                 final int NUM_INSTALL_CHECKS = 5;
126                 _installedLabels = new JLabel[NUM_INSTALL_CHECKS];
127                 for (int i=0; i<NUM_INSTALL_CHECKS; i++) {
128                         _installedLabels[i] = new JLabel("...");
129                 }
130                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
131                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
132                         0, 2);
133                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[0], 1, 2);
134                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
135                         new JLabel(I18nManager.getText("dialog.about.systeminfo.povray") + " : "),
136                         0, 3);
137                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[1], 1, 3);
138                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
139                         new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
140                         0, 4);
141                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[2], 1, 4);
142                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
143                         new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
144                         0, 5);
145                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[3], 1, 5);
146                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
147                         new JLabel(I18nManager.getText("dialog.about.systeminfo.gnuplot") + " : "),
148                         0, 6);
149                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[4], 1, 6);
150                 _tabs.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
151
152                 // Third pane for credits
153                 JPanel creditsPanel = new JPanel();
154                 gridBag = new GridBagLayout();
155                 creditsPanel.setLayout(gridBag);
156                 constraints = new GridBagConstraints();
157                 constraints.weightx = 0.0; constraints.weighty = 0.0;
158
159                 addToGridBagPanel(creditsPanel, gridBag, constraints,
160                         new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
161                         0, 0);
162                 addToGridBagPanel(creditsPanel, gridBag, constraints,
163                         new JLabel("activityworkshop.net"),
164                         1, 0);
165                 addToGridBagPanel(creditsPanel, gridBag, constraints,
166                         new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
167                         0, 1);
168                 addToGridBagPanel(creditsPanel, gridBag, constraints,
169                         new JLabel("Drew Noakes"),
170                         1, 1);
171                 addToGridBagPanel(creditsPanel, gridBag, constraints,
172                         new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
173                         0, 2);
174                 addToGridBagPanel(creditsPanel, gridBag, constraints,
175                         new JLabel("Eclipse"),
176                         1, 2);
177                 addToGridBagPanel(creditsPanel, gridBag, constraints,
178                         new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
179                         0, 3);
180                 addToGridBagPanel(creditsPanel, gridBag, constraints,
181                         new JLabel("Ramon, Miguel, Inés, Piotr, Petrovsk, Josatoc, Weehal,"),
182                         1, 3);
183                 addToGridBagPanel(creditsPanel, gridBag, constraints,
184                         new JLabel(" theYinYeti, Rothermographer"),
185                         1, 4);
186                 addToGridBagPanel(creditsPanel, gridBag, constraints,
187                         new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
188                         0, 5);
189                 addToGridBagPanel(creditsPanel, gridBag, constraints,
190                         new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
191                         1, 5);
192                 addToGridBagPanel(creditsPanel, gridBag, constraints,
193                         new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
194                         0, 6);
195                 addToGridBagPanel(creditsPanel, gridBag, constraints,
196                         new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
197                         1, 6);
198                 addToGridBagPanel(creditsPanel, gridBag, constraints,
199                         new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
200                         0, 7);
201                 addToGridBagPanel(creditsPanel, gridBag, constraints,
202                         new JLabel("Kate, Povray, Exiftool, Inkscape, Google Earth, Gpsbabel, Gnuplot"),
203                         1, 7);
204                 addToGridBagPanel(creditsPanel, gridBag, constraints,
205                         new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
206                         0, 8);
207                 addToGridBagPanel(creditsPanel, gridBag, constraints,
208                         new JLabel("Friends and loved ones, for encouragement and support"),
209                         1, 8);
210                 _tabs.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
211
212                 // Read me
213                 JPanel readmePanel = new JPanel();
214                 readmePanel.setLayout(new BorderLayout());
215                 JTextArea textArea = new JTextArea(getReadmeText());
216                 textArea.setEditable(false);
217                 textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
218                 JScrollPane scrollPane = new JScrollPane(textArea);
219                 scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
220                 scrollPane.setPreferredSize(new Dimension(600, 130));
221                 readmePanel.add(scrollPane, BorderLayout.CENTER);
222                 _tabs.add(I18nManager.getText("dialog.about.readme"), readmePanel);
223
224                 // OK button at the bottom
225                 JPanel okPanel = new JPanel();
226                 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
227                 _okButton = new JButton(I18nManager.getText("button.ok"));
228                 _okButton.addActionListener(new ActionListener()
229                 {
230                         public void actionPerformed(ActionEvent e)
231                         {
232                                 _dialog.dispose();
233                         }
234                 });
235                 _okButton.addKeyListener(new KeyListener() {
236                         public void keyPressed(KeyEvent e)
237                         {
238                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
239                         }
240                         public void keyTyped(KeyEvent e) {}
241                         public void keyReleased(KeyEvent e) {}
242                 });
243                 okPanel.add(_okButton);
244                 mainPanel.add(okPanel, BorderLayout.SOUTH);
245                 return mainPanel;
246         }
247
248         /**
249          * Helper function to reduce complexity of gui making code
250          * when adding labels to a GridBagLayout
251          * @param inPanel panel to add to
252          * @param inLayout GridBagLayout object
253          * @param inConstraints GridBagConstraints object
254          * @param inLabel label to add
255          * @param inX grid x
256          * @param inY grid y
257          */
258         private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
259                 JLabel inLabel, int inX, int inY)
260         {
261                 // set x and y in constraints
262                 inConstraints.gridx = inX;
263                 inConstraints.gridy = inY;
264                 // set anchor
265                 inConstraints.anchor = (inX == 0?GridBagConstraints.EAST:GridBagConstraints.WEST);
266                 // set constraints to label
267                 inLayout.setConstraints(inLabel, inConstraints);
268                 // add label to panel
269                 inPanel.add(inLabel);
270         }
271
272         /**
273          * @return text from the readme file
274          */
275         private String getReadmeText()
276         {
277                 try
278                 {
279                         // For some reason using ../readme.txt doesn't work, so need absolute path
280                         InputStream in = AboutScreen.class.getResourceAsStream("/tim/prune/readme.txt");
281                         if (in != null) {
282                                 byte[] buffer = new byte[in.available()];
283                                 in.read(buffer);
284                                 return new String(buffer);
285                         }
286                 }
287                 catch (java.io.IOException e) {
288                         System.err.println("Exception trying to get readme : " + e.getMessage());
289                 }
290                 return I18nManager.getText("error.readme.notfound");
291         }
292
293         /**
294          * Show window
295          */
296         public void begin()
297         {
298                 if (_dialog == null)
299                 {
300                         _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
301                         _dialog.getContentPane().add(makeContents());
302                         _dialog.pack();
303                 }
304                 _tabs.setSelectedIndex(0);
305                 checkInstalls();
306                 _dialog.setVisible(true);
307                 _okButton.requestFocus();
308         }
309
310         /**
311          * Check the installed components and set the label texts accordingly
312          */
313         private void checkInstalls()
314         {
315                 String yesText = I18nManager.getText("dialog.about.yes");
316                 String noText = I18nManager.getText("dialog.about.no");
317                 _installedLabels[0].setText(WindowFactory.isJava3dEnabled()?yesText:noText);
318                 _installedLabels[1].setText(ExternalTools.isPovrayInstalled()?yesText:noText);
319                 _installedLabels[2].setText(ExternalTools.isExiftoolInstalled()?yesText:noText);
320                 _installedLabels[3].setText(ExternalTools.isGpsbabelInstalled()?yesText:noText);
321                 _installedLabels[4].setText(ExternalTools.isGnuplotInstalled()?yesText:noText);
322         }
323 }