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.languages")).append(" : ")
81 .append("deutsch, english, español, français, italiano, polski, schwiizerdüütsch").append("</p>");
82 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.translatedby")).append("</p>");
83 JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
84 descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
85 descPane.setEditable(false);
86 descPane.setOpaque(false);
87 descPane.setAlignmentX(JEditorPane.CENTER_ALIGNMENT);
89 aboutPanel.add(descPane);
90 aboutPanel.add(new JLabel(" "));
91 tabPane.add(I18nManager.getText("dialog.about.title"), aboutPanel);
93 // Second pane for system info
94 JPanel sysInfoPanel = new JPanel();
95 GridBagLayout gridBag = new GridBagLayout();
96 sysInfoPanel.setLayout(gridBag);
97 GridBagConstraints constraints = new GridBagConstraints();
98 constraints.weightx = 0.0; constraints.weighty = 0.0;
99 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
100 new JLabel(I18nManager.getText("dialog.about.systeminfo.os") + " : "),
102 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
103 new JLabel(System.getProperty("os.name")),
105 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
106 new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
108 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
109 new JLabel(System.getProperty("java.runtime.version")),
111 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
112 new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
114 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
115 new JLabel(I18nManager.getText(WindowFactory.isJava3dEnabled()?"dialog.about.yes":"dialog.about.no")),
117 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
118 new JLabel(I18nManager.getText("dialog.about.systeminfo.povray") + " : "),
120 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
121 new JLabel(I18nManager.getText(ExternalTools.isPovrayInstalled()?"dialog.about.yes":"dialog.about.no")),
123 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
124 new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
126 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
127 new JLabel(I18nManager.getText(ExternalTools.isExiftoolInstalled()?"dialog.about.yes":"dialog.about.no")),
129 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
130 new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
132 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
133 new JLabel(I18nManager.getText(ExternalTools.isGpsbabelInstalled()?"dialog.about.yes":"dialog.about.no")),
135 tabPane.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
137 // Third pane for credits
138 JPanel creditsPanel = new JPanel();
139 gridBag = new GridBagLayout();
140 creditsPanel.setLayout(gridBag);
141 constraints = new GridBagConstraints();
142 constraints.weightx = 0.0; constraints.weighty = 0.0;
144 addToGridBagPanel(creditsPanel, gridBag, constraints,
145 new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
147 addToGridBagPanel(creditsPanel, gridBag, constraints,
148 new JLabel("activityworkshop.net"),
150 addToGridBagPanel(creditsPanel, gridBag, constraints,
151 new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
153 addToGridBagPanel(creditsPanel, gridBag, constraints,
154 new JLabel("Drew Noakes"),
156 addToGridBagPanel(creditsPanel, gridBag, constraints,
157 new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
159 addToGridBagPanel(creditsPanel, gridBag, constraints,
160 new JLabel("Eclipse"),
162 addToGridBagPanel(creditsPanel, gridBag, constraints,
163 new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
165 addToGridBagPanel(creditsPanel, gridBag, constraints,
166 new JLabel("Ramon, Miguel, Inés, Piotr, Petrovsk, Josatoc"),
168 addToGridBagPanel(creditsPanel, gridBag, constraints,
169 new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
171 addToGridBagPanel(creditsPanel, gridBag, constraints,
172 new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
174 addToGridBagPanel(creditsPanel, gridBag, constraints,
175 new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
177 addToGridBagPanel(creditsPanel, gridBag, constraints,
178 new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
180 addToGridBagPanel(creditsPanel, gridBag, constraints,
181 new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
183 addToGridBagPanel(creditsPanel, gridBag, constraints,
184 new JLabel("Garble, Kate, Povray, Exiftool, Inkscape, Google Earth"),
186 addToGridBagPanel(creditsPanel, gridBag, constraints,
187 new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
189 addToGridBagPanel(creditsPanel, gridBag, constraints,
190 new JLabel("Friends and loved ones, for encouragement and support"),
192 tabPane.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
195 JPanel readmePanel = new JPanel();
196 readmePanel.setLayout(new BorderLayout());
197 JTextArea textArea = new JTextArea(getReadmeText());
198 textArea.setEditable(false);
199 textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
200 JScrollPane scrollPane = new JScrollPane(textArea);
201 scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
202 scrollPane.setPreferredSize(new Dimension(600, 130));
203 readmePanel.add(scrollPane, BorderLayout.CENTER);
204 tabPane.add(I18nManager.getText("dialog.about.readme"), readmePanel);
206 // OK button at the bottom
207 JPanel okPanel = new JPanel();
208 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
209 _okButton = new JButton(I18nManager.getText("button.ok"));
210 _okButton.addActionListener(new ActionListener()
212 public void actionPerformed(ActionEvent e)
217 _okButton.addKeyListener(new KeyListener() {
218 public void keyPressed(KeyEvent e)
220 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {dispose();}
222 public void keyTyped(KeyEvent e) {}
223 public void keyReleased(KeyEvent e) {}
225 okPanel.add(_okButton);
226 mainPanel.add(okPanel, BorderLayout.SOUTH);
231 * Helper function to reduce complexity of gui making code
232 * when adding labels to a GridBagLayout
233 * @param inPanel panel to add to
234 * @param inLayout GridBagLayout object
235 * @param inConstraints GridBagConstraints object
236 * @param inLabel label to add
240 private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
241 JLabel inLabel, int inX, int inY)
243 // set x and y in constraints
244 inConstraints.gridx = inX;
245 inConstraints.gridy = inY;
247 inConstraints.anchor = (inX == 0?GridBagConstraints.EAST:GridBagConstraints.WEST);
248 // set constraints to label
249 inLayout.setConstraints(inLabel, inConstraints);
250 // add label to panel
251 inPanel.add(inLabel);
255 * @return text from the readme file
257 private String getReadmeText()
261 // For some reason using ../readme.txt doesn't work, so need absolute path
262 InputStream in = getClass().getResourceAsStream("/tim/prune/readme.txt");
264 byte[] buffer = new byte[in.available()];
266 return new String(buffer);
269 catch (java.io.IOException e) {
270 System.err.println("Exception trying to get readme : " + e.getMessage());
272 return I18nManager.getText("error.readme.notfound");
283 _okButton.requestFocus();