1 package tim.prune.function;
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
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;
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;
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;
35 * Class to represent the "About" popup window
37 public class AboutScreen extends GenericFunction
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;
48 * @param inApp app object
50 public AboutScreen(App inApp)
56 * Return the name key for this function
58 public String getNameKey()
60 return "function.about";
64 * @return the contents of the window as a Component
66 private Component makeContents()
68 JPanel mainPanel = new JPanel();
69 mainPanel.setLayout(new BorderLayout());
71 _tabs = new JTabbedPane();
72 mainPanel.add(_tabs, BorderLayout.CENTER);
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);
102 aboutPanel.add(descPane);
103 aboutPanel.add(new JLabel(" "));
104 _tabs.add(I18nManager.getText("function.about"), aboutPanel);
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") + " : "),
115 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
116 new JLabel(System.getProperty("os.name")),
118 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
119 new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
121 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
122 new JLabel(System.getProperty("java.runtime.version")),
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("...");
130 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
131 new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
133 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[0], 1, 2);
134 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
135 new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
137 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[1], 1, 3);
138 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
139 new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
141 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[2], 1, 4);
142 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
143 new JLabel(I18nManager.getText("dialog.about.systeminfo.gnuplot") + " : "),
145 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[3], 1, 5);
146 _tabs.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
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;
155 addToGridBagPanel(creditsPanel, gridBag, constraints,
156 new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
158 addToGridBagPanel(creditsPanel, gridBag, constraints,
159 new JLabel("activityworkshop.net"),
161 addToGridBagPanel(creditsPanel, gridBag, constraints,
162 new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
164 addToGridBagPanel(creditsPanel, gridBag, constraints,
165 new JLabel("Drew Noakes"),
167 addToGridBagPanel(creditsPanel, gridBag, constraints,
168 new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
170 addToGridBagPanel(creditsPanel, gridBag, constraints,
171 new JLabel("Eclipse"),
173 addToGridBagPanel(creditsPanel, gridBag, constraints,
174 new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
176 addToGridBagPanel(creditsPanel, gridBag, constraints,
177 new JLabel("Ramon, Miguel, In\u00E9s, Piotr, Petrovsk, Josatoc, Weehal,"),
179 addToGridBagPanel(creditsPanel, gridBag, constraints,
180 new JLabel(" theYinYeti, Rothermographer, Sam, Rudolph"),
182 addToGridBagPanel(creditsPanel, gridBag, constraints,
183 new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
185 addToGridBagPanel(creditsPanel, gridBag, constraints,
186 new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
188 addToGridBagPanel(creditsPanel, gridBag, constraints,
189 new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
191 addToGridBagPanel(creditsPanel, gridBag, constraints,
192 new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
194 addToGridBagPanel(creditsPanel, gridBag, constraints,
195 new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
197 addToGridBagPanel(creditsPanel, gridBag, constraints,
198 new JLabel("Kate, Povray, Exiftool, Inkscape, Google Earth, Gpsbabel, Gnuplot"),
200 addToGridBagPanel(creditsPanel, gridBag, constraints,
201 new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
203 addToGridBagPanel(creditsPanel, gridBag, constraints,
204 new JLabel("Friends and loved ones, for encouragement and support"),
206 _tabs.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
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);
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()
226 public void actionPerformed(ActionEvent e)
231 _okButton.addKeyListener(new KeyListener() {
232 public void keyPressed(KeyEvent e)
234 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
236 public void keyTyped(KeyEvent e) {}
237 public void keyReleased(KeyEvent e) {}
239 okPanel.add(_okButton);
240 mainPanel.add(okPanel, BorderLayout.SOUTH);
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
254 private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
255 JLabel inLabel, int inX, int inY)
257 // set x and y in constraints
258 inConstraints.gridx = inX;
259 inConstraints.gridy = inY;
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);
269 * @return text from the readme file
271 private String getReadmeText()
275 // For some reason using ../readme.txt doesn't work, so need absolute path
276 InputStream in = AboutScreen.class.getResourceAsStream("/tim/prune/readme.txt");
278 byte[] buffer = new byte[in.available()];
280 return new String(buffer);
283 catch (java.io.IOException e) {
284 System.err.println("Exception trying to get readme : " + e.getMessage());
286 return I18nManager.getText("error.readme.notfound");
296 _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
297 _dialog.getContentPane().add(makeContents());
300 _tabs.setSelectedIndex(0);
302 _dialog.setVisible(true);
303 _okButton.requestFocus();
307 * Check the installed components and set the label texts accordingly
309 private void checkInstalls()
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);