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, \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);
103 aboutPanel.add(descPane);
104 aboutPanel.add(new JLabel(" "));
105 _tabs.add(I18nManager.getText("function.about"), aboutPanel);
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") + " : "),
116 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
117 new JLabel(System.getProperty("os.name")),
119 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
120 new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
122 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
123 new JLabel(System.getProperty("java.runtime.version")),
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("...");
131 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
132 new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
134 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[0], 1, 2);
135 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
136 new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
138 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[1], 1, 3);
139 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
140 new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
142 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[2], 1, 4);
143 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
144 new JLabel(I18nManager.getText("dialog.about.systeminfo.gnuplot") + " : "),
146 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[3], 1, 5);
147 _tabs.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
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;
156 addToGridBagPanel(creditsPanel, gridBag, constraints,
157 new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
159 addToGridBagPanel(creditsPanel, gridBag, constraints,
160 new JLabel("activityworkshop.net"),
162 addToGridBagPanel(creditsPanel, gridBag, constraints,
163 new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
165 addToGridBagPanel(creditsPanel, gridBag, constraints,
166 new JLabel("Drew Noakes"),
168 addToGridBagPanel(creditsPanel, gridBag, constraints,
169 new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
171 addToGridBagPanel(creditsPanel, gridBag, constraints,
172 new JLabel("Eclipse"),
174 addToGridBagPanel(creditsPanel, gridBag, constraints,
175 new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
177 addToGridBagPanel(creditsPanel, gridBag, constraints,
178 new JLabel("Ramon, Miguel, In\u00E9s, Piotr, Petrovsk, Josatoc, Weehal,"),
180 addToGridBagPanel(creditsPanel, gridBag, constraints,
181 new JLabel(" theYinYeti, Rothermographer, Sam, Rudolph, nazotoko, katpatuka"),
183 addToGridBagPanel(creditsPanel, gridBag, constraints,
184 new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
186 addToGridBagPanel(creditsPanel, gridBag, constraints,
187 new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
189 addToGridBagPanel(creditsPanel, gridBag, constraints,
190 new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
192 addToGridBagPanel(creditsPanel, gridBag, constraints,
193 new JLabel("Debian Linux, Sun Java, Eclipse, Svn, Gimp, Inkscape"),
195 addToGridBagPanel(creditsPanel, gridBag, constraints,
196 new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
198 addToGridBagPanel(creditsPanel, gridBag, constraints,
199 new JLabel("Openstreetmap, Povray, Exiftool, Google Earth, Gpsbabel, Gnuplot"),
201 addToGridBagPanel(creditsPanel, gridBag, constraints,
202 new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
204 addToGridBagPanel(creditsPanel, gridBag, constraints,
205 new JLabel("Friends and loved ones, for encouragement and support"),
207 _tabs.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
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);
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()
227 public void actionPerformed(ActionEvent e)
232 _okButton.addKeyListener(new KeyListener() {
233 public void keyPressed(KeyEvent e)
235 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
237 public void keyTyped(KeyEvent e) {}
238 public void keyReleased(KeyEvent e) {}
240 okPanel.add(_okButton);
241 mainPanel.add(okPanel, BorderLayout.SOUTH);
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
255 private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout,
256 GridBagConstraints inConstraints, JLabel inLabel, int inX, int inY)
258 // set x and y in constraints
259 inConstraints.gridx = inX;
260 inConstraints.gridy = inY;
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);
270 * @return text from the readme file
272 private String getReadmeText()
276 // For some reason using ../readme.txt doesn't work, so need absolute path
277 InputStream in = AboutScreen.class.getResourceAsStream("/tim/prune/readme.txt");
279 byte[] buffer = new byte[in.available()];
281 return new String(buffer);
284 catch (java.io.IOException e) {
285 System.err.println("Exception trying to get readme : " + e.getMessage());
287 return I18nManager.getText("error.readme.notfound");
297 _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
298 _dialog.getContentPane().add(makeContents());
301 _tabs.setSelectedIndex(0);
303 _dialog.setVisible(true);
304 _okButton.requestFocus();
308 * Check the installed components and set the label texts accordingly
310 private void checkInstalls()
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);