]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/AboutScreen.java
Version 8, September 2009
[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, portugu\u00EAs, bahasa indonesia, rom\u00E2n\u0103").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 = 4;
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.exiftool") + " : "),
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.gpsbabel") + " : "),
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.gnuplot") + " : "),
144                         0, 5);
145                 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[3], 1, 5);
146                 _tabs.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
147
148                 // Third pane for credits
149                 JPanel creditsPanel = new JPanel();
150                 gridBag = new GridBagLayout();
151                 creditsPanel.setLayout(gridBag);
152                 constraints = new GridBagConstraints();
153                 constraints.weightx = 0.0; constraints.weighty = 0.0;
154
155                 addToGridBagPanel(creditsPanel, gridBag, constraints,
156                         new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
157                         0, 0);
158                 addToGridBagPanel(creditsPanel, gridBag, constraints,
159                         new JLabel("activityworkshop.net"),
160                         1, 0);
161                 addToGridBagPanel(creditsPanel, gridBag, constraints,
162                         new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
163                         0, 1);
164                 addToGridBagPanel(creditsPanel, gridBag, constraints,
165                         new JLabel("Drew Noakes"),
166                         1, 1);
167                 addToGridBagPanel(creditsPanel, gridBag, constraints,
168                         new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
169                         0, 2);
170                 addToGridBagPanel(creditsPanel, gridBag, constraints,
171                         new JLabel("Eclipse"),
172                         1, 2);
173                 addToGridBagPanel(creditsPanel, gridBag, constraints,
174                         new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
175                         0, 3);
176                 addToGridBagPanel(creditsPanel, gridBag, constraints,
177                         new JLabel("Ramon, Miguel, In\u00E9s, Piotr, Petrovsk, Josatoc, Weehal,"),
178                         1, 3);
179                 addToGridBagPanel(creditsPanel, gridBag, constraints,
180                         new JLabel(" theYinYeti, Rothermographer, Sam, Rudolph"),
181                         1, 4);
182                 addToGridBagPanel(creditsPanel, gridBag, constraints,
183                         new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
184                         0, 5);
185                 addToGridBagPanel(creditsPanel, gridBag, constraints,
186                         new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
187                         1, 5);
188                 addToGridBagPanel(creditsPanel, gridBag, constraints,
189                         new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
190                         0, 6);
191                 addToGridBagPanel(creditsPanel, gridBag, constraints,
192                         new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
193                         1, 6);
194                 addToGridBagPanel(creditsPanel, gridBag, constraints,
195                         new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
196                         0, 7);
197                 addToGridBagPanel(creditsPanel, gridBag, constraints,
198                         new JLabel("Kate, Povray, Exiftool, Inkscape, Google Earth, Gpsbabel, Gnuplot"),
199                         1, 7);
200                 addToGridBagPanel(creditsPanel, gridBag, constraints,
201                         new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
202                         0, 8);
203                 addToGridBagPanel(creditsPanel, gridBag, constraints,
204                         new JLabel("Friends and loved ones, for encouragement and support"),
205                         1, 8);
206                 _tabs.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
207
208                 // Read me
209                 JPanel readmePanel = new JPanel();
210                 readmePanel.setLayout(new BorderLayout());
211                 JTextArea textArea = new JTextArea(getReadmeText());
212                 textArea.setEditable(false);
213                 textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
214                 JScrollPane scrollPane = new JScrollPane(textArea);
215                 scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
216                 scrollPane.setPreferredSize(new Dimension(600, 130));
217                 readmePanel.add(scrollPane, BorderLayout.CENTER);
218                 _tabs.add(I18nManager.getText("dialog.about.readme"), readmePanel);
219
220                 // OK button at the bottom
221                 JPanel okPanel = new JPanel();
222                 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
223                 _okButton = new JButton(I18nManager.getText("button.ok"));
224                 _okButton.addActionListener(new ActionListener()
225                 {
226                         public void actionPerformed(ActionEvent e)
227                         {
228                                 _dialog.dispose();
229                         }
230                 });
231                 _okButton.addKeyListener(new KeyListener() {
232                         public void keyPressed(KeyEvent e)
233                         {
234                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
235                         }
236                         public void keyTyped(KeyEvent e) {}
237                         public void keyReleased(KeyEvent e) {}
238                 });
239                 okPanel.add(_okButton);
240                 mainPanel.add(okPanel, BorderLayout.SOUTH);
241                 return mainPanel;
242         }
243
244         /**
245          * Helper function to reduce complexity of gui making code
246          * when adding labels to a GridBagLayout
247          * @param inPanel panel to add to
248          * @param inLayout GridBagLayout object
249          * @param inConstraints GridBagConstraints object
250          * @param inLabel label to add
251          * @param inX grid x
252          * @param inY grid y
253          */
254         private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
255                 JLabel inLabel, int inX, int inY)
256         {
257                 // set x and y in constraints
258                 inConstraints.gridx = inX;
259                 inConstraints.gridy = inY;
260                 // set anchor
261                 inConstraints.anchor = (inX == 0?GridBagConstraints.EAST:GridBagConstraints.WEST);
262                 // set constraints to label
263                 inLayout.setConstraints(inLabel, inConstraints);
264                 // add label to panel
265                 inPanel.add(inLabel);
266         }
267
268         /**
269          * @return text from the readme file
270          */
271         private String getReadmeText()
272         {
273                 try
274                 {
275                         // For some reason using ../readme.txt doesn't work, so need absolute path
276                         InputStream in = AboutScreen.class.getResourceAsStream("/tim/prune/readme.txt");
277                         if (in != null) {
278                                 byte[] buffer = new byte[in.available()];
279                                 in.read(buffer);
280                                 return new String(buffer);
281                         }
282                 }
283                 catch (java.io.IOException e) {
284                         System.err.println("Exception trying to get readme : " + e.getMessage());
285                 }
286                 return I18nManager.getText("error.readme.notfound");
287         }
288
289         /**
290          * Show window
291          */
292         public void begin()
293         {
294                 if (_dialog == null)
295                 {
296                         _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
297                         _dialog.getContentPane().add(makeContents());
298                         _dialog.pack();
299                 }
300                 _tabs.setSelectedIndex(0);
301                 checkInstalls();
302                 _dialog.setVisible(true);
303                 _okButton.requestFocus();
304         }
305
306         /**
307          * Check the installed components and set the label texts accordingly
308          */
309         private void checkInstalls()
310         {
311                 String yesText = I18nManager.getText("dialog.about.yes");
312                 String noText = I18nManager.getText("dialog.about.no");
313                 _installedLabels[0].setText(WindowFactory.isJava3dEnabled()?yesText:noText);
314                 final int[] tools = {ExternalTools.TOOL_EXIFTOOL, ExternalTools.TOOL_GPSBABEL, ExternalTools.TOOL_GNUPLOT};
315                 for (int i=0; i<tools.length; i++) {
316                         _installedLabels[i+1].setText(ExternalTools.isToolInstalled(tools[i])?yesText:noText);
317                 }
318         }
319 }