]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/AboutScreen.java
Version 4, January 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.FlowLayout;
6 import java.awt.Font;
7 import java.awt.GridBagConstraints;
8 import java.awt.GridBagLayout;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11 import java.awt.event.KeyEvent;
12 import java.awt.event.KeyListener;
13
14 import javax.swing.BorderFactory;
15 import javax.swing.BoxLayout;
16 import javax.swing.JButton;
17 import javax.swing.JDialog;
18 import javax.swing.JEditorPane;
19 import javax.swing.JFrame;
20 import javax.swing.JLabel;
21 import javax.swing.JPanel;
22 import javax.swing.JTabbedPane;
23
24 import tim.prune.ExternalTools;
25 import tim.prune.GpsPruner;
26 import tim.prune.I18nManager;
27 import tim.prune.threedee.WindowFactory;
28
29 /**
30  * Class to represent the "About" popup window
31  */
32 public class AboutScreen extends JDialog
33 {
34         JButton _okButton = null;
35
36         /**
37          * Constructor
38          * @param inParent parent frame
39          */
40         public AboutScreen(JFrame inParent)
41         {
42                 super(inParent, I18nManager.getText("dialog.about.title"));
43                 getContentPane().add(makeContents());
44         }
45
46
47         /**
48          * @return the contents of the window as a Component
49          */
50         private Component makeContents()
51         {
52                 JPanel mainPanel = new JPanel();
53                 mainPanel.setLayout(new BorderLayout());
54
55                 JTabbedPane tabPane = new JTabbedPane();
56                 mainPanel.add(tabPane, BorderLayout.CENTER);
57
58                 JPanel aboutPanel = new JPanel();
59                 aboutPanel.setLayout(new BoxLayout(aboutPanel, BoxLayout.Y_AXIS));
60                 aboutPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
61                 JLabel titleLabel = new JLabel("Prune");
62                 titleLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
63                 titleLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
64                 aboutPanel.add(titleLabel);
65                 JLabel versionLabel = new JLabel(I18nManager.getText("dialog.about.version") + ": " + GpsPruner.VERSION_NUMBER);
66                 versionLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
67                 aboutPanel.add(versionLabel);
68                 JLabel buildLabel = new JLabel(I18nManager.getText("dialog.about.build") + ": " + GpsPruner.BUILD_NUMBER);
69                 buildLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
70                 aboutPanel.add(buildLabel);
71                 aboutPanel.add(new JLabel(" "));
72                 StringBuffer descBuffer = new StringBuffer();
73                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext1")).append("</p>");
74                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext2")).append("</p>");
75                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.summarytext3")).append("</p>");
76                 descBuffer.append("<p>").append(I18nManager.getText("dialog.about.translatedby")).append("</p>");
77                 JEditorPane descPane = new JEditorPane("text/html", descBuffer.toString());
78                 descPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
79                 descPane.setEditable(false);
80                 descPane.setOpaque(false);
81                 descPane.setAlignmentX(JEditorPane.CENTER_ALIGNMENT);
82
83                 aboutPanel.add(descPane);
84                 aboutPanel.add(new JLabel(" "));
85                 tabPane.add(I18nManager.getText("dialog.about.title"), aboutPanel);
86
87                 // Second pane for system info
88                 JPanel sysInfoPanel = new JPanel();
89                 GridBagLayout gridBag = new GridBagLayout();
90                 sysInfoPanel.setLayout(gridBag);
91                 GridBagConstraints constraints = new GridBagConstraints();
92                 constraints.weightx = 0.0; constraints.weighty = 0.0;
93                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
94                         new JLabel(I18nManager.getText("dialog.about.systeminfo.os") + " : "),
95                         0, 0);
96                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
97                         new JLabel(System.getProperty("os.name")),
98                         1, 0);
99                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
100                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java") + " : "),
101                         0, 1);
102                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
103                         new JLabel(System.getProperty("java.runtime.version")),
104                         1, 1);
105                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
106                         new JLabel(I18nManager.getText("dialog.about.systeminfo.java3d") + " : "),
107                         0, 2);
108                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
109                         new JLabel(I18nManager.getText(WindowFactory.isJava3dEnabled()?"dialog.about.yes":"dialog.about.no")),
110                         1, 2);
111                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
112                         new JLabel(I18nManager.getText("dialog.about.systeminfo.povray") + " : "),
113                         0, 3);
114                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
115                         new JLabel(I18nManager.getText(ExternalTools.isPovrayInstalled()?"dialog.about.yes":"dialog.about.no")),
116                         1, 3);
117                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
118                         new JLabel(I18nManager.getText("dialog.about.systeminfo.exiftool") + " : "),
119                         0, 4);
120                 addToGridBagPanel(sysInfoPanel, gridBag, constraints,
121                         new JLabel(I18nManager.getText(ExternalTools.isExiftoolInstalled()?"dialog.about.yes":"dialog.about.no")),
122                         1, 4);
123                 tabPane.add(I18nManager.getText("dialog.about.systeminfo"), sysInfoPanel);
124
125                 // Third pane for credits
126                 JPanel creditsPanel = new JPanel();
127                 gridBag = new GridBagLayout();
128                 creditsPanel.setLayout(gridBag);
129                 constraints = new GridBagConstraints();
130                 constraints.weightx = 0.0; constraints.weighty = 0.0;
131
132                 addToGridBagPanel(creditsPanel, gridBag, constraints,
133                         new JLabel(I18nManager.getText("dialog.about.credits.code") + " : "),
134                         0, 0);
135                 addToGridBagPanel(creditsPanel, gridBag, constraints,
136                         new JLabel("activityworkshop.net"),
137                         1, 0);
138                 addToGridBagPanel(creditsPanel, gridBag, constraints,
139                         new JLabel(I18nManager.getText("dialog.about.credits.exifcode") + " : "),
140                         0, 1);
141                 addToGridBagPanel(creditsPanel, gridBag, constraints,
142                         new JLabel("Drew Noakes"),
143                         1, 1);
144                 addToGridBagPanel(creditsPanel, gridBag, constraints,
145                         new JLabel(I18nManager.getText("dialog.about.credits.icons") + " : "),
146                         0, 2);
147                 addToGridBagPanel(creditsPanel, gridBag, constraints,
148                         new JLabel("Eclipse"),
149                         1, 2);
150                 addToGridBagPanel(creditsPanel, gridBag, constraints,
151                         new JLabel(I18nManager.getText("dialog.about.credits.translators") + " : "),
152                         0, 3);
153                 addToGridBagPanel(creditsPanel, gridBag, constraints,
154                         new JLabel("Ramon, Miguel, InĂ©s, Piotr"),
155                         1, 3);
156                 addToGridBagPanel(creditsPanel, gridBag, constraints,
157                         new JLabel(I18nManager.getText("dialog.about.credits.translations") + " : "),
158                         0, 4);
159                 addToGridBagPanel(creditsPanel, gridBag, constraints,
160                         new JLabel("Open Office, Gpsdrive, Babelfish, Leo, Launchpad"),
161                         1, 4);
162                 addToGridBagPanel(creditsPanel, gridBag, constraints,
163                         new JLabel(I18nManager.getText("dialog.about.credits.devtools") + " : "),
164                         0, 5);
165                 addToGridBagPanel(creditsPanel, gridBag, constraints,
166                         new JLabel("Mandriva Linux, Sun Java, Eclipse, Svn, Gimp"),
167                         1, 5);
168                 addToGridBagPanel(creditsPanel, gridBag, constraints,
169                         new JLabel(I18nManager.getText("dialog.about.credits.othertools") + " : "),
170                         0, 6);
171                 addToGridBagPanel(creditsPanel, gridBag, constraints,
172                         new JLabel("Garble, Kate, Povray, Exiftool, Inkscape, Google Earth"),
173                         1, 6);
174                 addToGridBagPanel(creditsPanel, gridBag, constraints,
175                         new JLabel(I18nManager.getText("dialog.about.credits.thanks") + " : "),
176                         0, 7);
177                 addToGridBagPanel(creditsPanel, gridBag, constraints,
178                         new JLabel("Friends and loved ones, for encouragement and support"),
179                         1, 7);
180                 tabPane.add(I18nManager.getText("dialog.about.credits"), creditsPanel);
181
182                 // OK button at the bottom
183                 JPanel okPanel = new JPanel();
184                 okPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
185                 _okButton = new JButton(I18nManager.getText("button.ok"));
186                 _okButton.addActionListener(new ActionListener()
187                 {
188                         public void actionPerformed(ActionEvent e)
189                         {
190                                 dispose();
191                         }
192                 });
193                 _okButton.addKeyListener(new KeyListener() {
194                         public void keyPressed(KeyEvent e)
195                         {
196                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {dispose();}
197                         }
198                         public void keyTyped(KeyEvent e) {}
199                         public void keyReleased(KeyEvent e) {}
200                 });
201                 okPanel.add(_okButton);
202                 mainPanel.add(okPanel, BorderLayout.SOUTH);
203                 return mainPanel;
204         }
205
206         /**
207          * Helper function to reduce complexity of gui making code
208          * when adding labels to a GridBagLayout
209          * @param inPanel panel to add to
210          * @param inLayout GridBagLayout object
211          * @param inConstraints GridBagConstraints object
212          * @param inLabel label to add
213          * @param inX grid x
214          * @param inY grid y
215          */
216         private static void addToGridBagPanel(JPanel inPanel, GridBagLayout inLayout, GridBagConstraints inConstraints,
217                 JLabel inLabel, int inX, int inY)
218         {
219                 // set x and y in constraints
220                 inConstraints.gridx = inX;
221                 inConstraints.gridy = inY;
222                 // set anchor
223                 inConstraints.anchor = (inX == 0?GridBagConstraints.EAST:GridBagConstraints.WEST);
224                 // set constraints to label
225                 inLayout.setConstraints(inLabel, inConstraints);
226                 // add label to panel
227                 inPanel.add(inLabel);
228         }
229
230
231         /**
232          * Show window
233          */
234         public void show()
235         {
236                 pack();
237                 // setSize(300,200);
238                 super.show();
239                 _okButton.requestFocus();
240         }
241 }