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ñ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);
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 = 5;
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.povray") + " : "),
137 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[1], 1, 3);
138 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
139 new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
141 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[2], 1, 4);
142 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
143 new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
145 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[3], 1, 5);
146 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
147 new JLabel(I18nManager.getText("dialog.about.systeminfo.gnuplot") + " : "),
149 addToGridBagPanel(sysInfoPanel, gridBag, constraints, _installedLabels[4], 1, 6);
150 _tabs.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
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;
159 addToGridBagPanel(creditsPanel, gridBag, constraints,
160 new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
162 addToGridBagPanel(creditsPanel, gridBag, constraints,
163 new JLabel("activityworkshop.net"),
165 addToGridBagPanel(creditsPanel, gridBag, constraints,
166 new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
168 addToGridBagPanel(creditsPanel, gridBag, constraints,
169 new JLabel("Drew Noakes"),
171 addToGridBagPanel(creditsPanel, gridBag, constraints,
172 new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
174 addToGridBagPanel(creditsPanel, gridBag, constraints,
175 new JLabel("Eclipse"),
177 addToGridBagPanel(creditsPanel, gridBag, constraints,
178 new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
180 addToGridBagPanel(creditsPanel, gridBag, constraints,
181 new JLabel("Ramon, Miguel, Inés, Piotr, Petrovsk, Josatoc, Weehal,"),
183 addToGridBagPanel(creditsPanel, gridBag, constraints,
184 new JLabel(" theYinYeti, Rothermographer"),
186 addToGridBagPanel(creditsPanel, gridBag, constraints,
187 new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
189 addToGridBagPanel(creditsPanel, gridBag, constraints,
190 new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
192 addToGridBagPanel(creditsPanel, gridBag, constraints,
193 new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
195 addToGridBagPanel(creditsPanel, gridBag, constraints,
196 new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
198 addToGridBagPanel(creditsPanel, gridBag, constraints,
199 new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
201 addToGridBagPanel(creditsPanel, gridBag, constraints,
202 new JLabel("Kate, Povray, Exiftool, Inkscape, Google Earth, Gpsbabel, Gnuplot"),
204 addToGridBagPanel(creditsPanel, gridBag, constraints,
205 new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
207 addToGridBagPanel(creditsPanel, gridBag, constraints,
208 new JLabel("Friends and loved ones, for encouragement and support"),
210 _tabs.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
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);
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()
230 public void actionPerformed(ActionEvent e)
235 _okButton.addKeyListener(new KeyListener() {
236 public void keyPressed(KeyEvent e)
238 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_dialog.dispose();}
240 public void keyTyped(KeyEvent e) {}
241 public void keyReleased(KeyEvent e) {}
243 okPanel.add(_okButton);
244 mainPanel.add(okPanel, BorderLayout.SOUTH);
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
258 private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
259 JLabel inLabel, int inX, int inY)
261 // set x and y in constraints
262 inConstraints.gridx = inX;
263 inConstraints.gridy = inY;
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);
273 * @return text from the readme file
275 private String getReadmeText()
279 // For some reason using ../readme.txt doesn't work, so need absolute path
280 InputStream in = AboutScreen.class.getResourceAsStream("/tim/prune/readme.txt");
282 byte[] buffer = new byte[in.available()];
284 return new String(buffer);
287 catch (java.io.IOException e) {
288 System.err.println("Exception trying to get readme : " + e.getMessage());
290 return I18nManager.getText("error.readme.notfound");
300 _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()));
301 _dialog.getContentPane().add(makeContents());
304 _tabs.setSelectedIndex(0);
306 _dialog.setVisible(true);
307 _okButton.requestFocus();
311 * Check the installed components and set the label texts accordingly
313 private void checkInstalls()
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);