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.JFrame;
22 import javax.swing.JLabel;
23 import javax.swing.JPanel;
24 import javax.swing.JScrollPane;
25 import javax.swing.JTabbedPane;
26 import javax.swing.JTextArea;
28 import tim.prune.ExternalTools;
29 import tim.prune.GpsPruner;
30 import tim.prune.I18nManager;
31 import tim.prune.threedee.WindowFactory;
34 * Class to represent the "About" popup window
36 public class AboutScreen extends JDialog
38 JButton _okButton = null;
42 * @param inParent parent frame
44 public AboutScreen(JFrame inParent)
46 super(inParent, I18nManager.getText("dialog.about.title"));
47 getContentPane().add(makeContents());
52 * @return the contents of the window as a Component
54 private Component makeContents()
56 JPanel mainPanel = new JPanel();
57 mainPanel.setLayout(new BorderLayout());
59 JTabbedPane tabPane = new JTabbedPane();
60 mainPanel.add(tabPane, BorderLayout.CENTER);
62 JPanel aboutPanel = new JPanel();
63 aboutPanel.setLayout(new BoxLayout(aboutPanel, BoxLayout.Y_AXIS));
64 aboutPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
65 JLabel titleLabel = new JLabel("Prune");
66 titleLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
67 titleLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
68 aboutPanel.add(titleLabel);
69 JLabel versionLabel = new JLabel(I18nManager.getText("dialog.about.version") + ": " + GpsPruner.VERSION_NUMBER);
70 versionLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
71 aboutPanel.add(versionLabel);
72 JLabel buildLabel = new JLabel(I18nManager.getText("dialog.about.build") + ": " + GpsPruner.BUILD_NUMBER);
73 buildLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
74 aboutPanel.add(buildLabel);
75 aboutPanel.add(new JLabel(" "));
76 StringBuffer descBuffer = new StringBuffer();
77 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext1")).append("</p>");
78 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext2")).append("</p>");
79 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext3")).append("</p>");
80 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.translatedby")).append("</p>");
81 JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
82 descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
83 descPane.setEditable(false);
84 descPane.setOpaque(false);
85 descPane.setAlignmentX(JEditorPane.CENTER_ALIGNMENT);
87 aboutPanel.add(descPane);
88 aboutPanel.add(new JLabel(" "));
89 tabPane.add(I18nManager.getText("dialog.about.title"), aboutPanel);
91 // Second pane for system info
92 JPanel sysInfoPanel = new JPanel();
93 GridBagLayout gridBag = new GridBagLayout();
94 sysInfoPanel.setLayout(gridBag);
95 GridBagConstraints constraints = new GridBagConstraints();
96 constraints.weightx = 0.0; constraints.weighty = 0.0;
97 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
98 new JLabel(I18nManager.getText("dialog.about.systeminfo.os") + " : "),
100 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
101 new JLabel(System.getProperty("os.name")),
103 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
104 new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
106 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
107 new JLabel(System.getProperty("java.runtime.version")),
109 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
110 new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
112 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
113 new JLabel(I18nManager.getText(WindowFactory.isJava3dEnabled()?"dialog.about.yes":"dialog.about.no")),
115 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
116 new JLabel(I18nManager.getText("dialog.about.systeminfo.povray") + " : "),
118 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
119 new JLabel(I18nManager.getText(ExternalTools.isPovrayInstalled()?"dialog.about.yes":"dialog.about.no")),
121 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
122 new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
124 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
125 new JLabel(I18nManager.getText(ExternalTools.isExiftoolInstalled()?"dialog.about.yes":"dialog.about.no")),
127 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
128 new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
130 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
131 new JLabel(I18nManager.getText(ExternalTools.isGpsbabelInstalled()?"dialog.about.yes":"dialog.about.no")),
133 tabPane.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
135 // Third pane for credits
136 JPanel creditsPanel = new JPanel();
137 gridBag = new GridBagLayout();
138 creditsPanel.setLayout(gridBag);
139 constraints = new GridBagConstraints();
140 constraints.weightx = 0.0; constraints.weighty = 0.0;
142 addToGridBagPanel(creditsPanel, gridBag, constraints,
143 new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
145 addToGridBagPanel(creditsPanel, gridBag, constraints,
146 new JLabel("activityworkshop.net"),
148 addToGridBagPanel(creditsPanel, gridBag, constraints,
149 new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
151 addToGridBagPanel(creditsPanel, gridBag, constraints,
152 new JLabel("Drew Noakes"),
154 addToGridBagPanel(creditsPanel, gridBag, constraints,
155 new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
157 addToGridBagPanel(creditsPanel, gridBag, constraints,
158 new JLabel("Eclipse"),
160 addToGridBagPanel(creditsPanel, gridBag, constraints,
161 new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
163 addToGridBagPanel(creditsPanel, gridBag, constraints,
164 new JLabel("Ramon, Miguel, Inés, Piotr, Petrovsk"),
166 addToGridBagPanel(creditsPanel, gridBag, constraints,
167 new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
169 addToGridBagPanel(creditsPanel, gridBag, constraints,
170 new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
172 addToGridBagPanel(creditsPanel, gridBag, constraints,
173 new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
175 addToGridBagPanel(creditsPanel, gridBag, constraints,
176 new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
178 addToGridBagPanel(creditsPanel, gridBag, constraints,
179 new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
181 addToGridBagPanel(creditsPanel, gridBag, constraints,
182 new JLabel("Garble, Kate, Povray, Exiftool, Inkscape, Google Earth"),
184 addToGridBagPanel(creditsPanel, gridBag, constraints,
185 new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
187 addToGridBagPanel(creditsPanel, gridBag, constraints,
188 new JLabel("Friends and loved ones, for encouragement and support"),
190 tabPane.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
193 JPanel readmePanel = new JPanel();
194 readmePanel.setLayout(new BorderLayout());
195 JTextArea textArea = new JTextArea(getReadmeText());
196 textArea.setEditable(false);
197 textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
198 JScrollPane scrollPane = new JScrollPane(textArea);
199 scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
200 scrollPane.setPreferredSize(new Dimension(600, 130));
201 readmePanel.add(scrollPane, BorderLayout.CENTER);
202 tabPane.add(I18nManager.getText("dialog.about.readme"), readmePanel);
204 // OK button at the bottom
205 JPanel okPanel = new JPanel();
206 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
207 _okButton = new JButton(I18nManager.getText("button.ok"));
208 _okButton.addActionListener(new ActionListener()
210 public void actionPerformed(ActionEvent e)
215 _okButton.addKeyListener(new KeyListener() {
216 public void keyPressed(KeyEvent e)
218 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {dispose();}
220 public void keyTyped(KeyEvent e) {}
221 public void keyReleased(KeyEvent e) {}
223 okPanel.add(_okButton);
224 mainPanel.add(okPanel, BorderLayout.SOUTH);
229 * Helper function to reduce complexity of gui making code
230 * when adding labels to a GridBagLayout
231 * @param inPanel panel to add to
232 * @param inLayout GridBagLayout object
233 * @param inConstraints GridBagConstraints object
234 * @param inLabel label to add
238 private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
239 JLabel inLabel, int inX, int inY)
241 // set x and y in constraints
242 inConstraints.gridx = inX;
243 inConstraints.gridy = inY;
245 inConstraints.anchor = (inX == 0?GridBagConstraints.EAST:GridBagConstraints.WEST);
246 // set constraints to label
247 inLayout.setConstraints(inLabel, inConstraints);
248 // add label to panel
249 inPanel.add(inLabel);
253 * @return text from the readme file
255 private String getReadmeText()
259 // For some reason using ../readme.txt doesn't work, so need absolute path
260 InputStream in = getClass().getResourceAsStream("/tim/prune/readme.txt");
262 byte[] buffer = new byte[in.available()];
264 return new String(buffer);
267 catch (java.io.IOException e) {
268 System.err.println("Exception trying to get readme : " + e.getMessage());
270 return I18nManager.getText("error.readme.notfound");
281 _okButton.requestFocus();