1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler.view.fantasia; |
24 |
|
25 |
import java.awt.Color; |
26 |
import java.awt.Desktop; |
27 |
import java.awt.Dialog; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.Frame; |
30 |
import java.awt.GridBagConstraints; |
31 |
import java.awt.GridBagLayout; |
32 |
import java.awt.Insets; |
33 |
|
34 |
import java.awt.event.ActionEvent; |
35 |
import java.awt.event.ActionListener; |
36 |
|
37 |
import java.net.URI; |
38 |
import java.net.URL; |
39 |
|
40 |
import javax.swing.BorderFactory; |
41 |
import javax.swing.Box; |
42 |
import javax.swing.BoxLayout; |
43 |
import javax.swing.JButton; |
44 |
import javax.swing.JEditorPane; |
45 |
import javax.swing.JLabel; |
46 |
import javax.swing.JPanel; |
47 |
import javax.swing.JScrollPane; |
48 |
import javax.swing.JTabbedPane; |
49 |
|
50 |
import net.sf.juife.InformationDialog; |
51 |
import net.sf.juife.JuifeUtils; |
52 |
import net.sf.juife.LinkButton; |
53 |
|
54 |
import org.jsampler.HF; |
55 |
|
56 |
import org.jvnet.substance.SubstanceLookAndFeel; |
57 |
|
58 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
59 |
|
60 |
/** |
61 |
* |
62 |
* @author Grigor Iliev |
63 |
*/ |
64 |
public class HelpAboutDlg extends InformationDialog { |
65 |
private JLabel lProductName = |
66 |
new JLabel("<html>\n<font size=+1>Fantasia (version 0.7a)</font>"); |
67 |
|
68 |
private JLabel lAuthor = new JLabel(i18n.getLabel("HelpAboutDlg.lAuthor")); |
69 |
private LinkButton btnAuthor = new Lnkbutton(i18n.getLabel("HelpAboutDlg.btnAuthor")); |
70 |
|
71 |
private JLabel lLicense = new JLabel(i18n.getLabel("HelpAboutDlg.lLicense")); |
72 |
private LinkButton btnLicense = new Lnkbutton("GNU General Public License v.2"); |
73 |
|
74 |
private JLabel lDesign = new JLabel(i18n.getLabel("HelpAboutDlg.lDesign")); |
75 |
|
76 |
private JLabel lCopyright = new JLabel(i18n.getLabel("HelpAboutDlg.lCopyright")); |
77 |
|
78 |
private JPanel mainPane = new JPanel(); |
79 |
|
80 |
/** Creates a new instance of <code>HelpAboutDlg</code> */ |
81 |
public |
82 |
HelpAboutDlg(Frame owner) { |
83 |
super(owner, i18n.getLabel("HelpAboutDlg.title")); |
84 |
|
85 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
86 |
|
87 |
lProductName.setHorizontalAlignment(JLabel.CENTER); |
88 |
lProductName.setAlignmentX(LEFT_ALIGNMENT); |
89 |
mainPane.add(lProductName); |
90 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
91 |
|
92 |
JTabbedPane tp = new JTabbedPane(); |
93 |
tp.addTab(i18n.getLabel("HelpAboutDlg.about"), createAboutPane()); |
94 |
tp.addTab(i18n.getLabel("HelpAboutDlg.details"), createDetailsPane()); |
95 |
|
96 |
tp.setAlignmentX(LEFT_ALIGNMENT); |
97 |
|
98 |
mainPane.add(tp); |
99 |
|
100 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
101 |
|
102 |
lCopyright.setFont(lCopyright.getFont().deriveFont(java.awt.Font.PLAIN)); |
103 |
lCopyright.setFont(lCopyright.getFont().deriveFont(10.0f)); |
104 |
lCopyright.setHorizontalAlignment(JLabel.CENTER); |
105 |
lCopyright.setAlignmentX(LEFT_ALIGNMENT); |
106 |
mainPane.add(lCopyright); |
107 |
|
108 |
setMainPane(mainPane); |
109 |
|
110 |
pack(); |
111 |
|
112 |
installListeners(); |
113 |
} |
114 |
|
115 |
private void |
116 |
installListeners() { |
117 |
btnAuthor.addActionListener(new ActionListener() { |
118 |
public void |
119 |
actionPerformed(ActionEvent e) { |
120 |
browse("http://www.grigoriliev.com"); |
121 |
} |
122 |
}); |
123 |
|
124 |
btnLicense.addActionListener(new ActionListener() { |
125 |
public void |
126 |
actionPerformed(ActionEvent e) { showLicense(License.GPL); } |
127 |
}); |
128 |
} |
129 |
|
130 |
private JPanel |
131 |
createAboutPane() { |
132 |
GridBagLayout gridbag = new GridBagLayout(); |
133 |
GridBagConstraints c = new GridBagConstraints(); |
134 |
|
135 |
JPanel p = new JPanel(); |
136 |
p.setLayout(gridbag); |
137 |
|
138 |
c.gridx = 0; |
139 |
c.gridy = 0; |
140 |
c.insets = new Insets(0, 0, 0, 6); |
141 |
c.anchor = GridBagConstraints.EAST; |
142 |
gridbag.setConstraints(lAuthor, c); |
143 |
p.add(lAuthor); |
144 |
|
145 |
c.gridx = 0; |
146 |
c.gridy = 1; |
147 |
gridbag.setConstraints(lLicense, c); |
148 |
p.add(lLicense); |
149 |
|
150 |
c.gridx = 0; |
151 |
c.gridy = 2; |
152 |
gridbag.setConstraints(lDesign, c); |
153 |
p.add(lDesign); |
154 |
|
155 |
btnAuthor.setUnvisitedColor(new Color(0xFFA300)); |
156 |
c.gridx = 1; |
157 |
c.gridy = 0; |
158 |
c.weightx = 1.0; |
159 |
c.insets = new Insets(0, 0, 0, 0); |
160 |
c.anchor = GridBagConstraints.WEST; |
161 |
gridbag.setConstraints(btnAuthor, c); |
162 |
p.add(btnAuthor); |
163 |
|
164 |
c.gridx = 1; |
165 |
c.gridy = 1; |
166 |
gridbag.setConstraints(btnLicense, c); |
167 |
p.add(btnLicense); |
168 |
|
169 |
JLabel l = new JLabel("Olivier Boyer, Grigor Iliev"); |
170 |
l.setFont(l.getFont().deriveFont(java.awt.Font.BOLD)); |
171 |
c.gridx = 1; |
172 |
c.gridy = 2; |
173 |
gridbag.setConstraints(l, c); |
174 |
p.add(l); |
175 |
|
176 |
p.setAlignmentX(LEFT_ALIGNMENT); |
177 |
|
178 |
JPanel aboutPane = new JPanel(); |
179 |
aboutPane.setLayout(new BoxLayout(aboutPane, BoxLayout.Y_AXIS)); |
180 |
|
181 |
aboutPane.add(p); |
182 |
|
183 |
aboutPane.add(Box.createRigidArea(new Dimension(0, 12))); |
184 |
|
185 |
aboutPane.add(createLibrariesPane()); |
186 |
|
187 |
aboutPane.add(Box.createRigidArea(new Dimension(0, 12))); |
188 |
|
189 |
return aboutPane; |
190 |
} |
191 |
|
192 |
private JPanel |
193 |
createDetailsPane() { |
194 |
JPanel detailsPane = new JPanel(); |
195 |
detailsPane.setLayout(new BoxLayout(detailsPane, BoxLayout.Y_AXIS)); |
196 |
|
197 |
detailsPane.add(new ContactInfoPane()); |
198 |
JPanel p = new JPanel(); |
199 |
p.setLayout(new java.awt.BorderLayout()); |
200 |
p.setOpaque(false); |
201 |
detailsPane.add(p); |
202 |
return detailsPane; |
203 |
} |
204 |
|
205 |
private JPanel |
206 |
createLibrariesPane() { |
207 |
JPanel p = new JPanel(); |
208 |
GridBagLayout gridbag = new GridBagLayout(); |
209 |
GridBagConstraints c = new GridBagConstraints(); |
210 |
p.setLayout(gridbag); |
211 |
|
212 |
Button btn = new Button("swingx"); |
213 |
btn.addActionListener(new ActionListener() { |
214 |
public void |
215 |
actionPerformed(ActionEvent e) { |
216 |
browse("http://swingx.dev.java.net/"); |
217 |
} |
218 |
}); |
219 |
|
220 |
c.gridx = 1; |
221 |
c.gridy = 0; |
222 |
c.insets = new Insets(3, 3, 3, 3); |
223 |
gridbag.setConstraints(btn, c); |
224 |
p.add(btn); |
225 |
|
226 |
btn = new Button("substance"); |
227 |
btn.addActionListener(new ActionListener() { |
228 |
public void |
229 |
actionPerformed(ActionEvent e) { |
230 |
browse("http://substance.dev.java.net/"); |
231 |
} |
232 |
}); |
233 |
|
234 |
c.gridx = 1; |
235 |
c.gridy = 1; |
236 |
gridbag.setConstraints(btn, c); |
237 |
p.add(btn); |
238 |
|
239 |
btn = new Button("jlscp"); |
240 |
btn.addActionListener(new ActionListener() { |
241 |
public void |
242 |
actionPerformed(ActionEvent e) { |
243 |
browse("http://sourceforge.net/projects/jlscp/"); |
244 |
} |
245 |
}); |
246 |
|
247 |
c.gridx = 0; |
248 |
c.gridy = 2; |
249 |
gridbag.setConstraints(btn, c); |
250 |
p.add(btn); |
251 |
|
252 |
btn = new Button("substance-swingx"); |
253 |
btn.addActionListener(new ActionListener() { |
254 |
public void |
255 |
actionPerformed(ActionEvent e) { |
256 |
browse("http://substance-swingx.dev.java.net/"); |
257 |
} |
258 |
}); |
259 |
|
260 |
c.gridx = 1; |
261 |
c.gridy = 2; |
262 |
gridbag.setConstraints(btn, c); |
263 |
p.add(btn); |
264 |
|
265 |
btn = new Button("juife"); |
266 |
btn.addActionListener(new ActionListener() { |
267 |
public void |
268 |
actionPerformed(ActionEvent e) { |
269 |
browse("http://sourceforge.net/projects/juife/"); |
270 |
} |
271 |
}); |
272 |
|
273 |
c.gridx = 2; |
274 |
c.gridy = 2; |
275 |
gridbag.setConstraints(btn, c); |
276 |
p.add(btn); |
277 |
|
278 |
p.setBorder(BorderFactory.createTitledBorder ( |
279 |
i18n.getLabel("HelpAboutDlg.using") |
280 |
)); |
281 |
|
282 |
p.setAlignmentX(LEFT_ALIGNMENT); |
283 |
|
284 |
return p; |
285 |
} |
286 |
|
287 |
private void |
288 |
showLicense(License license) { |
289 |
new LicenseDlg(this, license).setVisible(true); |
290 |
} |
291 |
|
292 |
private boolean |
293 |
checkDesktopSupported() { |
294 |
if(Desktop.isDesktopSupported()) return true; |
295 |
|
296 |
HF.showErrorMessage(i18n.getError("HelpAboutDlg.DesktopApiNotSupported"), this); |
297 |
|
298 |
return false; |
299 |
} |
300 |
|
301 |
private void |
302 |
browse(String uri) { |
303 |
if(!checkDesktopSupported()) return; |
304 |
|
305 |
try { Desktop.getDesktop().browse(new URI(uri)); } |
306 |
catch(Exception x) { x.printStackTrace(); } |
307 |
} |
308 |
|
309 |
private void |
310 |
mail(String uri) { |
311 |
if(!checkDesktopSupported()) return; |
312 |
|
313 |
Desktop desktop = Desktop.getDesktop(); |
314 |
|
315 |
try { Desktop.getDesktop().mail(new URI(uri)); } |
316 |
catch(Exception x) { x.printStackTrace(); } |
317 |
} |
318 |
|
319 |
class ContactInfoPane extends JPanel { |
320 |
private JLabel lAuthorEmail = |
321 |
new JLabel(i18n.getLabel("HelpAboutDlg.lAuthorEmail")); |
322 |
private JLabel lLSWebsite = new JLabel(i18n.getLabel("HelpAboutDlg.lLSWebsite")); |
323 |
private JLabel lJSWebsite = new JLabel(i18n.getLabel("HelpAboutDlg.lJSWebsite")); |
324 |
|
325 |
private Lnkbutton btnAuthorEmail = new Lnkbutton("grigor@grigoriliev.com"); |
326 |
private Lnkbutton btnLSWebsite = new Lnkbutton("www.linuxsampler.org"); |
327 |
private Lnkbutton btnJSWebsite = new Lnkbutton("sf.net/projects/jsampler"); |
328 |
|
329 |
private Button btnLSMailingList = |
330 |
new Button(i18n.getButtonLabel("HelpAboutDlg.btnLSMailingList")); |
331 |
|
332 |
ContactInfoPane() { |
333 |
GridBagLayout gridbag = new GridBagLayout(); |
334 |
GridBagConstraints c = new GridBagConstraints(); |
335 |
|
336 |
setLayout(gridbag); |
337 |
|
338 |
c.gridx = 0; |
339 |
c.gridy = 0; |
340 |
c.insets = new Insets(0, 0, 0, 6); |
341 |
c.anchor = GridBagConstraints.EAST; |
342 |
gridbag.setConstraints(lAuthorEmail, c); |
343 |
add(lAuthorEmail); |
344 |
|
345 |
c.gridx = 0; |
346 |
c.gridy = 1; |
347 |
gridbag.setConstraints(lLSWebsite, c); |
348 |
add(lLSWebsite); |
349 |
|
350 |
c.gridx = 0; |
351 |
c.gridy = 2; |
352 |
c.anchor = GridBagConstraints.EAST; |
353 |
gridbag.setConstraints(lJSWebsite, c); |
354 |
add(lJSWebsite); |
355 |
|
356 |
c.gridx = 1; |
357 |
c.gridy = 0; |
358 |
c.insets = new Insets(0, 0, 0, 0); |
359 |
c.anchor = GridBagConstraints.WEST; |
360 |
gridbag.setConstraints(btnAuthorEmail, c); |
361 |
add(btnAuthorEmail); |
362 |
|
363 |
c.gridx = 1; |
364 |
c.gridy = 1; |
365 |
gridbag.setConstraints(btnLSWebsite, c); |
366 |
add(btnLSWebsite); |
367 |
|
368 |
c.gridx = 1; |
369 |
c.gridy = 2; |
370 |
gridbag.setConstraints(btnJSWebsite, c); |
371 |
add(btnJSWebsite); |
372 |
|
373 |
c.gridx = 0; |
374 |
c.gridy = 3; |
375 |
c.gridwidth = 2; |
376 |
c.insets = new Insets(12, 0, 0, 0); |
377 |
c.anchor = GridBagConstraints.CENTER; |
378 |
gridbag.setConstraints(btnLSMailingList, c); |
379 |
add(btnLSMailingList); |
380 |
|
381 |
setBorder(BorderFactory.createTitledBorder ( |
382 |
i18n.getLabel("HelpAboutDlg.contactInfoPane") |
383 |
)); |
384 |
|
385 |
btnAuthorEmail.addActionListener(new ActionListener() { |
386 |
public void |
387 |
actionPerformed(ActionEvent e) { |
388 |
browse("mailto:grigor@grigoriliev.com"); |
389 |
} |
390 |
}); |
391 |
|
392 |
btnLSWebsite.addActionListener(new ActionListener() { |
393 |
public void |
394 |
actionPerformed(ActionEvent e) { |
395 |
browse("http://www.linuxsampler.org"); |
396 |
} |
397 |
}); |
398 |
|
399 |
btnJSWebsite.addActionListener(new ActionListener() { |
400 |
public void |
401 |
actionPerformed(ActionEvent e) { |
402 |
browse("http://sf.net/projects/jsampler/"); |
403 |
} |
404 |
}); |
405 |
|
406 |
btnLSMailingList.addActionListener(new ActionListener() { |
407 |
public void |
408 |
actionPerformed(ActionEvent e) { |
409 |
browse("http://lists.sourceforge.net/lists/listinfo/linuxsampler-devel"); |
410 |
} |
411 |
}); |
412 |
} |
413 |
} |
414 |
|
415 |
private class Lnkbutton extends LinkButton { |
416 |
Lnkbutton(String s) { |
417 |
super(s); |
418 |
Color c = new Color(0xFFA300); |
419 |
setUnvisitedColor(c); |
420 |
setUnvisitedFontStyle(BOLD); |
421 |
setVisitedColor(c); |
422 |
setVisitedFontStyle(BOLD); |
423 |
setHoverColor(c); |
424 |
setHoverFontStyle(BOLD | UNDERLINE); |
425 |
} |
426 |
} |
427 |
|
428 |
private class Button extends JButton { |
429 |
Button(String s) { |
430 |
super(s); |
431 |
putClientProperty ( |
432 |
SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY, |
433 |
"org.jvnet.substance.button.StandardButtonShaper" |
434 |
); |
435 |
|
436 |
setForeground(new Color(0xFFA300)); |
437 |
setFont(getFont().deriveFont(java.awt.Font.BOLD)); |
438 |
} |
439 |
} |
440 |
} |
441 |
|
442 |
|
443 |
|
444 |
enum License { GPL, LGPL } |
445 |
|
446 |
class LicenseDlg extends InformationDialog { |
447 |
LicenseDlg(Dialog owner, License license) { |
448 |
super(owner); |
449 |
|
450 |
switch(license) { |
451 |
case GPL: setTitle("GNU General Public License"); break; |
452 |
case LGPL: setTitle("GNU Lesser General Public License"); break; |
453 |
} |
454 |
|
455 |
JScrollPane sp = new JScrollPane(new LicensePane(license)); |
456 |
sp.setPreferredSize(new Dimension(800, 400)); |
457 |
|
458 |
setMainPane(sp); |
459 |
} |
460 |
|
461 |
static class LicensePane extends JEditorPane { |
462 |
private static URL urlGPL; |
463 |
private static URL urlLGPL; |
464 |
|
465 |
static { |
466 |
String s = "licenses/gpl.html"; |
467 |
urlGPL = ClassLoader.getSystemClassLoader().getResource(s); |
468 |
s = "licenses/lgpl.html"; |
469 |
urlLGPL = ClassLoader.getSystemClassLoader().getResource(s); |
470 |
} |
471 |
|
472 |
LicensePane(License license) { |
473 |
try { |
474 |
switch(license) { |
475 |
case GPL: setPage(urlGPL); break; |
476 |
case LGPL: setPage(urlLGPL); break; |
477 |
} |
478 |
} catch(Exception x) { |
479 |
x.printStackTrace(); |
480 |
} |
481 |
|
482 |
setEditable(false); |
483 |
} |
484 |
} |
485 |
} |