]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/AboutScreen.java
Version 5, May 2008
[GpsPrune.git] / tim / prune / gui / AboutScreen.java
1 package tim.prune.gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.Font;
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;
15
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;
27
28 import tim.prune.ExternalTools;
29 import tim.prune.GpsPruner;
30 import tim.prune.I18nManager;
31 import tim.prune.threedee.WindowFactory;
32
33 /**
34  * Class to represent the "About" popup window
35  */
36 public class AboutScreen extends JDialog
37 {
38         JButton _okButton = null;
39
40         /**
41          * Constructor
42          * @param inParent parent frame
43          */
44         public AboutScreen(JFrame inParent)
45         {
46                 super(inParent, I18nManager.getText("dialog.about.title"));
47                 getContentPane().add(makeContents());
48         }
49
50
51         /**
52          * @return the contents of the window as a Component
53          */
54         private Component makeContents()
55         {
56                 JPanel mainPanel = new JPanel();
57                 mainPanel.setLayout(new BorderLayout());
58
59                 JTabbedPane tabPane = new JTabbedPane();
60                 mainPanel.add(tabPane, BorderLayout.CENTER);
61
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);
86
87                 aboutPanel.add(descPane);
88                 aboutPanel.add(new JLabel(" "));
89                 tabPane.add(I18nManager.getText("dialog.about.title"), aboutPanel);
90
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") + " : "),
99                         0, 0);
100                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
101                         new JLabel(System.getProperty("os.name")),
102                         1, 0);
103                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
104                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
105                         0, 1);
106                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
107                         new JLabel(System.getProperty("java.runtime.version")),
108                         1, 1);
109                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
110                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
111                         0, 2);
112                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
113                         new JLabel(I18nManager.getText(WindowFactory.isJava3dEnabled()?"dialog.about.yes":"dialog.about.no")),
114                         1, 2);
115                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
116                         new JLabel(I18nManager.getText("dialog.about.systeminfo.povray") + " : "),
117                         0, 3);
118                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
119                         new JLabel(I18nManager.getText(ExternalTools.isPovrayInstalled()?"dialog.about.yes":"dialog.about.no")),
120                         1, 3);
121                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
122                         new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
123                         0, 4);
124                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
125                         new JLabel(I18nManager.getText(ExternalTools.isExiftoolInstalled()?"dialog.about.yes":"dialog.about.no")),
126                         1, 4);
127                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
128                         new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
129                         0, 5);
130                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
131                         new JLabel(I18nManager.getText(ExternalTools.isGpsbabelInstalled()?"dialog.about.yes":"dialog.about.no")),
132                         1, 5);
133                 tabPane.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
134
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;
141
142                 addToGridBagPanel(creditsPanel, gridBag, constraints,
143                         new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
144                         0, 0);
145                 addToGridBagPanel(creditsPanel, gridBag, constraints,
146                         new JLabel("activityworkshop.net"),
147                         1, 0);
148                 addToGridBagPanel(creditsPanel, gridBag, constraints,
149                         new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
150                         0, 1);
151                 addToGridBagPanel(creditsPanel, gridBag, constraints,
152                         new JLabel("Drew Noakes"),
153                         1, 1);
154                 addToGridBagPanel(creditsPanel, gridBag, constraints,
155                         new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
156                         0, 2);
157                 addToGridBagPanel(creditsPanel, gridBag, constraints,
158                         new JLabel("Eclipse"),
159                         1, 2);
160                 addToGridBagPanel(creditsPanel, gridBag, constraints,
161                         new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
162                         0, 3);
163                 addToGridBagPanel(creditsPanel, gridBag, constraints,
164                         new JLabel("Ramon, Miguel, InĂ©s, Piotr, Petrovsk"),
165                         1, 3);
166                 addToGridBagPanel(creditsPanel, gridBag, constraints,
167                         new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
168                         0, 4);
169                 addToGridBagPanel(creditsPanel, gridBag, constraints,
170                         new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
171                         1, 4);
172                 addToGridBagPanel(creditsPanel, gridBag, constraints,
173                         new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
174                         0, 5);
175                 addToGridBagPanel(creditsPanel, gridBag, constraints,
176                         new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
177                         1, 5);
178                 addToGridBagPanel(creditsPanel, gridBag, constraints,
179                         new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
180                         0, 6);
181                 addToGridBagPanel(creditsPanel, gridBag, constraints,
182                         new JLabel("Garble, Kate, Povray, Exiftool, Inkscape, Google Earth"),
183                         1, 6);
184                 addToGridBagPanel(creditsPanel, gridBag, constraints,
185                         new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
186                         0, 7);
187                 addToGridBagPanel(creditsPanel, gridBag, constraints,
188                         new JLabel("Friends and loved ones, for encouragement and support"),
189                         1, 7);
190                 tabPane.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
191
192                 // Read me
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);
203
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()
209                 {
210                         public void actionPerformed(ActionEvent e)
211                         {
212                                 dispose();
213                         }
214                 });
215                 _okButton.addKeyListener(new KeyListener() {
216                         public void keyPressed(KeyEvent e)
217                         {
218                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {dispose();}
219                         }
220                         public void keyTyped(KeyEvent e) {}
221                         public void keyReleased(KeyEvent e) {}
222                 });
223                 okPanel.add(_okButton);
224                 mainPanel.add(okPanel, BorderLayout.SOUTH);
225                 return mainPanel;
226         }
227
228         /**
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
235          * @param inX grid x
236          * @param inY grid y
237          */
238         private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
239                 JLabel inLabel, int inX, int inY)
240         {
241                 // set x and y in constraints
242                 inConstraints.gridx = inX;
243                 inConstraints.gridy = inY;
244                 // set anchor
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);
250         }
251
252         /**
253          * @return text from the readme file
254          */
255         private String getReadmeText()
256         {
257                 try
258                 {
259                         // For some reason using ../readme.txt doesn't work, so need absolute path
260                         InputStream in = getClass().getResourceAsStream("/tim/prune/readme.txt");
261                         if (in != null) {
262                                 byte[] buffer = new byte[in.available()];
263                                 in.read(buffer);
264                                 return new String(buffer);
265                         }
266                 }
267                 catch (java.io.IOException e) {
268                         System.err.println("Exception trying to get readme : " + e.getMessage());
269                 }
270                 return I18nManager.getText("error.readme.notfound");
271         }
272
273         /**
274          * Show window
275          */
276         public void show()
277         {
278                 pack();
279                 // setSize(300,200);
280                 super.show();
281                 _okButton.requestFocus();
282         }
283 }