]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/AboutScreen.java
Version 6, October 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.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);
88
89                 aboutPanel.add(descPane);
90                 aboutPanel.add(new JLabel(" "));
91                 tabPane.add(I18nManager.getText("dialog.about.title"), aboutPanel);
92
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") + " : "),
101                         0, 0);
102                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
103                         new JLabel(System.getProperty("os.name")),
104                         1, 0);
105                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
106                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
107                         0, 1);
108                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
109                         new JLabel(System.getProperty("java.runtime.version")),
110                         1, 1);
111                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
112                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
113                         0, 2);
114                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
115                         new JLabel(I18nManager.getText(WindowFactory.isJava3dEnabled()?"dialog.about.yes":"dialog.about.no")),
116                         1, 2);
117                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
118                         new JLabel(I18nManager.getText("dialog.about.systeminfo.povray") + " : "),
119                         0, 3);
120                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
121                         new JLabel(I18nManager.getText(ExternalTools.isPovrayInstalled()?"dialog.about.yes":"dialog.about.no")),
122                         1, 3);
123                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
124                         new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
125                         0, 4);
126                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
127                         new JLabel(I18nManager.getText(ExternalTools.isExiftoolInstalled()?"dialog.about.yes":"dialog.about.no")),
128                         1, 4);
129                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
130                         new JLabel(I18nManager.getText("dialog.about.systeminfo.gpsbabel") + " : "),
131                         0, 5);
132                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
133                         new JLabel(I18nManager.getText(ExternalTools.isGpsbabelInstalled()?"dialog.about.yes":"dialog.about.no")),
134                         1, 5);
135                 tabPane.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
136
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;
143
144                 addToGridBagPanel(creditsPanel, gridBag, constraints,
145                         new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
146                         0, 0);
147                 addToGridBagPanel(creditsPanel, gridBag, constraints,
148                         new JLabel("activityworkshop.net"),
149                         1, 0);
150                 addToGridBagPanel(creditsPanel, gridBag, constraints,
151                         new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
152                         0, 1);
153                 addToGridBagPanel(creditsPanel, gridBag, constraints,
154                         new JLabel("Drew Noakes"),
155                         1, 1);
156                 addToGridBagPanel(creditsPanel, gridBag, constraints,
157                         new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
158                         0, 2);
159                 addToGridBagPanel(creditsPanel, gridBag, constraints,
160                         new JLabel("Eclipse"),
161                         1, 2);
162                 addToGridBagPanel(creditsPanel, gridBag, constraints,
163                         new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
164                         0, 3);
165                 addToGridBagPanel(creditsPanel, gridBag, constraints,
166                         new JLabel("Ramon, Miguel, Inés, Piotr, Petrovsk, Josatoc"),
167                         1, 3);
168                 addToGridBagPanel(creditsPanel, gridBag, constraints,
169                         new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
170                         0, 4);
171                 addToGridBagPanel(creditsPanel, gridBag, constraints,
172                         new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
173                         1, 4);
174                 addToGridBagPanel(creditsPanel, gridBag, constraints,
175                         new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
176                         0, 5);
177                 addToGridBagPanel(creditsPanel, gridBag, constraints,
178                         new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
179                         1, 5);
180                 addToGridBagPanel(creditsPanel, gridBag, constraints,
181                         new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
182                         0, 6);
183                 addToGridBagPanel(creditsPanel, gridBag, constraints,
184                         new JLabel("Garble, Kate, Povray, Exiftool, Inkscape, Google Earth"),
185                         1, 6);
186                 addToGridBagPanel(creditsPanel, gridBag, constraints,
187                         new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
188                         0, 7);
189                 addToGridBagPanel(creditsPanel, gridBag, constraints,
190                         new JLabel("Friends and loved ones, for encouragement and support"),
191                         1, 7);
192                 tabPane.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
193
194                 // Read me
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);
205
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()
211                 {
212                         public void actionPerformed(ActionEvent e)
213                         {
214                                 dispose();
215                         }
216                 });
217                 _okButton.addKeyListener(new KeyListener() {
218                         public void keyPressed(KeyEvent e)
219                         {
220                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {dispose();}
221                         }
222                         public void keyTyped(KeyEvent e) {}
223                         public void keyReleased(KeyEvent e) {}
224                 });
225                 okPanel.add(_okButton);
226                 mainPanel.add(okPanel, BorderLayout.SOUTH);
227                 return mainPanel;
228         }
229
230         /**
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
237          * @param inX grid x
238          * @param inY grid y
239          */
240         private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
241                 JLabel inLabel, int inX, int inY)
242         {
243                 // set x and y in constraints
244                 inConstraints.gridx = inX;
245                 inConstraints.gridy = inY;
246                 // set anchor
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);
252         }
253
254         /**
255          * @return text from the readme file
256          */
257         private String getReadmeText()
258         {
259                 try
260                 {
261                         // For some reason using ../readme.txt doesn't work, so need absolute path
262                         InputStream in = getClass().getResourceAsStream("/tim/prune/readme.txt");
263                         if (in != null) {
264                                 byte[] buffer = new byte[in.available()];
265                                 in.read(buffer);
266                                 return new String(buffer);
267                         }
268                 }
269                 catch (java.io.IOException e) {
270                         System.err.println("Exception trying to get readme : " + e.getMessage());
271                 }
272                 return I18nManager.getText("error.readme.notfound");
273         }
274
275         /**
276          * Show window
277          */
278         public void show()
279         {
280                 pack();
281                 // setSize(300,200);
282                 super.show();
283                 _okButton.requestFocus();
284         }
285 }