1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2009 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.classic; |
24 |
|
25 |
import java.awt.Desktop; |
26 |
import java.awt.Dialog; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Frame; |
29 |
import java.awt.GridBagConstraints; |
30 |
import java.awt.GridBagLayout; |
31 |
import java.awt.Insets; |
32 |
|
33 |
import java.awt.event.ActionEvent; |
34 |
import java.awt.event.ActionListener; |
35 |
|
36 |
import java.net.URI; |
37 |
import java.net.URL; |
38 |
|
39 |
import javax.swing.BorderFactory; |
40 |
import javax.swing.Box; |
41 |
import javax.swing.BoxLayout; |
42 |
import javax.swing.ImageIcon; |
43 |
import javax.swing.JEditorPane; |
44 |
import javax.swing.JLabel; |
45 |
import javax.swing.JPanel; |
46 |
import javax.swing.JScrollPane; |
47 |
import javax.swing.JSeparator; |
48 |
import javax.swing.JTextField; |
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 static org.jsampler.view.classic.ClassicI18n.i18n; |
57 |
|
58 |
|
59 |
/** |
60 |
* |
61 |
* @author grish |
62 |
*/ |
63 |
public class HelpAboutDlg extends InformationDialog { |
64 |
private JLabel lProductName = |
65 |
new JLabel("<html>\n<font size=+1>JS Classic (version 0.9)</font>"); |
66 |
|
67 |
private JLabel lAuthor = new JLabel(i18n.getLabel("HelpAboutDlg.lAuthor")); |
68 |
private JTextField tfAuthor = new JTextField(i18n.getLabel("HelpAboutDlg.tfAuthor")); |
69 |
|
70 |
private JLabel lLicense = new JLabel(i18n.getLabel("HelpAboutDlg.lLicense")); |
71 |
private LinkButton btnLicense = new LinkButton("GNU General Public License"); |
72 |
|
73 |
private JLabel lLibraries = new JLabel("Using:"); |
74 |
|
75 |
private LinkButton btnJlscp = |
76 |
new LinkButton("jlscp - A java LinuxSampler control protocol API"); |
77 |
|
78 |
private LinkButton btnJuife |
79 |
= new LinkButton("juife - Java User Interface Framework Extensions"); |
80 |
|
81 |
|
82 |
private JLabel lCopyright = new JLabel(i18n.getLabel("HelpAboutDlg.lCopyright")); |
83 |
|
84 |
private JPanel mainPane = new JPanel(); |
85 |
|
86 |
/** Creates a new instance of HelpAboutDlg */ |
87 |
public HelpAboutDlg(Frame owner) { |
88 |
super(owner, i18n.getLabel("HelpAboutDlg.title")); |
89 |
|
90 |
GridBagLayout gridbag = new GridBagLayout(); |
91 |
GridBagConstraints c = new GridBagConstraints(); |
92 |
|
93 |
JPanel p = new JPanel(); |
94 |
p.setLayout(gridbag); |
95 |
|
96 |
c.gridx = 0; |
97 |
c.gridy = 1; |
98 |
c.insets = new Insets(0, 0, 0, 6); |
99 |
c.anchor = GridBagConstraints.EAST; |
100 |
gridbag.setConstraints(lAuthor, c); |
101 |
p.add(lAuthor); |
102 |
|
103 |
c.gridx = 0; |
104 |
c.gridy = 2; |
105 |
gridbag.setConstraints(lLicense, c); |
106 |
p.add(lLicense); |
107 |
|
108 |
c.gridx = 0; |
109 |
c.gridy = 3; |
110 |
c.insets = new Insets(12, 0, 0, 6); |
111 |
c.anchor = GridBagConstraints.EAST; |
112 |
gridbag.setConstraints(lLibraries, c); |
113 |
p.add(lLibraries); |
114 |
|
115 |
tfAuthor.setEditable(false); |
116 |
tfAuthor.setBorder(BorderFactory.createEmptyBorder()); |
117 |
|
118 |
c.gridx = 1; |
119 |
c.gridy = 1; |
120 |
c.weightx = 1.0; |
121 |
c.insets = new Insets(0, 0, 0, 0); |
122 |
c.anchor = GridBagConstraints.WEST; |
123 |
gridbag.setConstraints(tfAuthor, c); |
124 |
p.add(tfAuthor); |
125 |
|
126 |
c.gridx = 1; |
127 |
c.gridy = 2; |
128 |
gridbag.setConstraints(btnLicense, c); |
129 |
p.add(btnLicense); |
130 |
|
131 |
c.gridx = 1; |
132 |
c.gridy = 3; |
133 |
c.insets = new Insets(12, 0, 0, 0); |
134 |
gridbag.setConstraints(btnJlscp, c); |
135 |
p.add(btnJlscp); |
136 |
|
137 |
c.gridx = 1; |
138 |
c.gridy = 4; |
139 |
c.insets = new Insets(0, 0, 0, 0); |
140 |
gridbag.setConstraints(btnJuife, c); |
141 |
p.add(btnJuife); |
142 |
|
143 |
// |
144 |
/*c.gridx = 0; |
145 |
c.gridy = 1; |
146 |
c.gridwidth = 2; |
147 |
gridbag.setConstraints(lCopyright, c); |
148 |
p.add(lCopyright);*/ |
149 |
|
150 |
lProductName.setHorizontalAlignment(JLabel.CENTER); |
151 |
c.gridx = 0; |
152 |
c.gridy = 0; |
153 |
c.gridwidth = 2; |
154 |
c.insets = new Insets(0, 0, 12, 0); |
155 |
c.anchor = GridBagConstraints.CENTER; |
156 |
gridbag.setConstraints(lProductName, c); |
157 |
p.add(lProductName); |
158 |
|
159 |
/*p = new JPanel(); |
160 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
161 |
|
162 |
p.add(lLicense); |
163 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
164 |
p.add(btnLicense); |
165 |
|
166 |
mainPane.add(p);*/ |
167 |
|
168 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
169 |
p.setAlignmentX(LEFT_ALIGNMENT); |
170 |
mainPane.add(p); |
171 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
172 |
|
173 |
/*lContactInfo.setAlignmentX(LEFT_ALIGNMENT); |
174 |
mainPane.add(lContactInfo); |
175 |
|
176 |
JSeparator sep = new JSeparator(); |
177 |
sep.setAlignmentX(LEFT_ALIGNMENT); |
178 |
mainPane.add(sep);*/ |
179 |
|
180 |
ContactInfoPane contactInfoPane = new ContactInfoPane(); |
181 |
contactInfoPane.setAlignmentX(LEFT_ALIGNMENT); |
182 |
mainPane.add(contactInfoPane); |
183 |
|
184 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
185 |
|
186 |
lCopyright.setFont(lCopyright.getFont().deriveFont(java.awt.Font.PLAIN)); |
187 |
lCopyright.setHorizontalAlignment(JLabel.CENTER); |
188 |
lCopyright.setAlignmentX(LEFT_ALIGNMENT); |
189 |
mainPane.add(lCopyright); |
190 |
|
191 |
setMainPane(mainPane); |
192 |
|
193 |
pack(); |
194 |
//setResizable(false); |
195 |
|
196 |
btnLicense.addActionListener(new ActionListener() { |
197 |
public void |
198 |
actionPerformed(ActionEvent e) { showLicense(License.GPL); } |
199 |
}); |
200 |
|
201 |
btnJlscp.addActionListener(new ActionListener() { |
202 |
public void |
203 |
actionPerformed(ActionEvent e) { showJlscpInfo(); } |
204 |
}); |
205 |
|
206 |
btnJuife.addActionListener(new ActionListener() { |
207 |
public void |
208 |
actionPerformed(ActionEvent e) { showJuifeInfo(); } |
209 |
}); |
210 |
} |
211 |
|
212 |
private void |
213 |
showLicense(License license) { |
214 |
new LicenseDlg(this, license).setVisible(true); |
215 |
} |
216 |
|
217 |
private void |
218 |
showJlscpInfo() { |
219 |
String website = "http://sourceforge.net/projects/jlscp"; |
220 |
String ver = Package.getPackage("org.linuxsampler.lscp").getImplementationVersion(); |
221 |
new LibraryInfoDlg(this, "jlscp", ver, website, License.GPL).setVisible(true); |
222 |
} |
223 |
|
224 |
private void |
225 |
showJuifeInfo() { |
226 |
String website = "http://sourceforge.net/projects/juife"; |
227 |
String ver = Package.getPackage("net.sf.juife").getImplementationVersion(); |
228 |
new LibraryInfoDlg(this, "juife", ver, website, License.LGPL).setVisible(true); |
229 |
} |
230 |
|
231 |
class ContactInfoPane extends JPanel { |
232 |
private JLabel lAuthorEmail = |
233 |
new JLabel(i18n.getLabel("HelpAboutDlg.lAuthorEmail")); |
234 |
private JLabel lLSWebsite = new JLabel(i18n.getLabel("HelpAboutDlg.lLSWebsite")); |
235 |
private LinkButton btnAuthorEmail = new LinkButton("grigor@grigoriliev.com"); |
236 |
private LinkButton btnLSWebsite = new LinkButton("www.linuxsampler.org"); |
237 |
|
238 |
private JLabel lLSMailingList = |
239 |
new JLabel(i18n.getLabel("HelpAboutDlg.lLSMailingList")); |
240 |
|
241 |
private LinkButton btnMailingList = new LinkButton ( |
242 |
"lists.sourceforge.net/lists/listinfo/linuxsampler-devel" |
243 |
); |
244 |
|
245 |
ContactInfoPane() { |
246 |
GridBagLayout gridbag = new GridBagLayout(); |
247 |
GridBagConstraints c = new GridBagConstraints(); |
248 |
|
249 |
setLayout(gridbag); |
250 |
|
251 |
c.gridx = 0; |
252 |
c.gridy = 0; |
253 |
c.insets = new Insets(0, 0, 0, 6); |
254 |
c.anchor = GridBagConstraints.EAST; |
255 |
gridbag.setConstraints(lAuthorEmail, c); |
256 |
add(lAuthorEmail); |
257 |
|
258 |
c.gridx = 0; |
259 |
c.gridy = 1; |
260 |
gridbag.setConstraints(lLSWebsite, c); |
261 |
add(lLSWebsite); |
262 |
|
263 |
c.gridx = 0; |
264 |
c.gridy = 2; |
265 |
c.anchor = GridBagConstraints.EAST; |
266 |
gridbag.setConstraints(lLSMailingList, c); |
267 |
add(lLSMailingList); |
268 |
|
269 |
c.gridx = 1; |
270 |
c.gridy = 0; |
271 |
c.insets = new Insets(0, 0, 0, 0); |
272 |
c.anchor = GridBagConstraints.WEST; |
273 |
gridbag.setConstraints(btnAuthorEmail, c); |
274 |
add(btnAuthorEmail); |
275 |
|
276 |
c.gridx = 1; |
277 |
c.gridy = 1; |
278 |
gridbag.setConstraints(btnLSWebsite, c); |
279 |
add(btnLSWebsite); |
280 |
|
281 |
c.gridx = 1; |
282 |
c.gridy = 2; |
283 |
c.gridwidth = 2; |
284 |
gridbag.setConstraints(btnMailingList, c); |
285 |
add(btnMailingList); |
286 |
|
287 |
setBorder(BorderFactory.createTitledBorder ( |
288 |
i18n.getLabel("HelpAboutDlg.contactInfoPane") |
289 |
)); |
290 |
|
291 |
installListeners(); |
292 |
} |
293 |
|
294 |
private void |
295 |
installListeners() { |
296 |
btnAuthorEmail.addActionListener(new ActionListener() { |
297 |
public void |
298 |
actionPerformed(ActionEvent e) { |
299 |
browse("mailto:grigor@grigoriliev.com"); |
300 |
} |
301 |
}); |
302 |
|
303 |
btnLSWebsite.addActionListener(new ActionListener() { |
304 |
public void |
305 |
actionPerformed(ActionEvent e) { |
306 |
browse("http://www.linuxsampler.org"); |
307 |
} |
308 |
}); |
309 |
|
310 |
btnMailingList.addActionListener(new ActionListener() { |
311 |
public void |
312 |
actionPerformed(ActionEvent e) { |
313 |
browse("http://lists.sourceforge.net/lists/listinfo/linuxsampler-devel"); |
314 |
} |
315 |
}); |
316 |
} |
317 |
} |
318 |
|
319 |
private boolean |
320 |
checkDesktopSupported() { |
321 |
if(Desktop.isDesktopSupported()) return true; |
322 |
|
323 |
HF.showErrorMessage(i18n.getError("HelpAboutDlg.DesktopApiNotSupported"), this); |
324 |
|
325 |
return false; |
326 |
} |
327 |
|
328 |
private void |
329 |
browse(String uri) { |
330 |
if(!checkDesktopSupported()) return; |
331 |
|
332 |
try { Desktop.getDesktop().browse(new URI(uri)); } |
333 |
catch(Exception x) { x.printStackTrace(); } |
334 |
} |
335 |
|
336 |
private void |
337 |
mail(String uri) { |
338 |
if(!checkDesktopSupported()) return; |
339 |
|
340 |
Desktop desktop = Desktop.getDesktop(); |
341 |
|
342 |
try { Desktop.getDesktop().mail(new URI(uri)); } |
343 |
catch(Exception x) { x.printStackTrace(); } |
344 |
} |
345 |
} |
346 |
|
347 |
class WebButton extends LinkButton { |
348 |
WebButton(String text) { |
349 |
super(text); |
350 |
|
351 |
setDisabledColor(getUnvisitedColor()); |
352 |
setDisabledFontStyle(UNDERLINE); |
353 |
setUnvisitedFontStyle(UNDERLINE); |
354 |
setEnabled(false); |
355 |
} |
356 |
} |
357 |
|
358 |
enum License { GPL, LGPL } |
359 |
|
360 |
class LicenseDlg extends InformationDialog { |
361 |
LicenseDlg(Dialog owner, License license) { |
362 |
super(owner); |
363 |
|
364 |
switch(license) { |
365 |
case GPL: setTitle("GNU General Public License"); break; |
366 |
case LGPL: setTitle("GNU Lesser General Public License"); break; |
367 |
} |
368 |
|
369 |
JScrollPane sp = new JScrollPane(new LicensePane(license)); |
370 |
sp.setPreferredSize(new Dimension(800, 400)); |
371 |
|
372 |
setMainPane(sp); |
373 |
} |
374 |
|
375 |
static class LicensePane extends JEditorPane { |
376 |
private static URL urlGPL; |
377 |
private static URL urlLGPL; |
378 |
|
379 |
static { |
380 |
String s = "licenses/gpl.html"; |
381 |
urlGPL = ClassLoader.getSystemClassLoader().getResource(s); |
382 |
s = "licenses/lgpl.html"; |
383 |
urlLGPL = ClassLoader.getSystemClassLoader().getResource(s); |
384 |
} |
385 |
|
386 |
LicensePane(License license) { |
387 |
try { |
388 |
switch(license) { |
389 |
case GPL: setPage(urlGPL); break; |
390 |
case LGPL: setPage(urlLGPL); break; |
391 |
} |
392 |
} catch(Exception x) { |
393 |
x.printStackTrace(); |
394 |
} |
395 |
|
396 |
setEditable(false); |
397 |
} |
398 |
} |
399 |
} |
400 |
|
401 |
class LibraryInfoDlg extends InformationDialog { |
402 |
private JLabel lAuthor = new JLabel(i18n.getLabel("LibraryInfoDlg.lAuthor")); |
403 |
private JTextField tfAuthor = new JTextField(i18n.getLabel("LibraryInfoDlg.tfAuthor")); |
404 |
|
405 |
private JLabel lLicense = new JLabel(i18n.getLabel("LibraryInfoDlg.lLicense")); |
406 |
private LinkButton btnLicense = new LinkButton(" "); |
407 |
|
408 |
private JLabel lWebsite = new JLabel(i18n.getLabel("LibraryInfoDlg.lWebsite")); |
409 |
private WebButton btnWebsite = new WebButton(""); |
410 |
|
411 |
LibraryInfoDlg ( |
412 |
Dialog owner, |
413 |
String libName, |
414 |
String libVersion, |
415 |
String website, |
416 |
final License license |
417 |
) { |
418 |
super(owner, libName); |
419 |
|
420 |
switch(license) { |
421 |
case GPL: btnLicense.setText("GNU General Public License"); break; |
422 |
case LGPL: btnLicense.setText("GNU Lesser General Public License"); break; |
423 |
} |
424 |
|
425 |
btnWebsite.setText(website); |
426 |
|
427 |
setMainPane(new LibraryInfoPane(libName, libVersion, license)); |
428 |
|
429 |
btnLicense.addActionListener(new ActionListener() { |
430 |
public void |
431 |
actionPerformed(ActionEvent e) { showLicense(license); } |
432 |
}); |
433 |
} |
434 |
|
435 |
private void |
436 |
showLicense(License license) { |
437 |
new LicenseDlg(this, license).setVisible(true); |
438 |
} |
439 |
|
440 |
class LibraryInfoPane extends JPanel { |
441 |
private JLabel lProductName; |
442 |
|
443 |
|
444 |
LibraryInfoPane(String libName, String libVersion, final License license) { |
445 |
lProductName = new JLabel ( |
446 |
"<html>\n<font size=+1>" + libName + |
447 |
" (version " + libVersion + ")</font>" |
448 |
); |
449 |
|
450 |
GridBagLayout gridbag = new GridBagLayout(); |
451 |
GridBagConstraints c = new GridBagConstraints(); |
452 |
|
453 |
setLayout(gridbag); |
454 |
|
455 |
c.gridx = 0; |
456 |
c.gridy = 1; |
457 |
c.insets = new Insets(0, 0, 0, 6); |
458 |
c.anchor = GridBagConstraints.EAST; |
459 |
gridbag.setConstraints(lAuthor, c); |
460 |
add(lAuthor); |
461 |
|
462 |
c.gridx = 0; |
463 |
c.gridy = 2; |
464 |
gridbag.setConstraints(lLicense, c); |
465 |
add(lLicense); |
466 |
|
467 |
c.gridx = 0; |
468 |
c.gridy = 3; |
469 |
c.insets = new Insets(12, 0, 0, 6); |
470 |
gridbag.setConstraints(lWebsite, c); |
471 |
add(lWebsite); |
472 |
|
473 |
tfAuthor.setEditable(false); |
474 |
tfAuthor.setBorder(BorderFactory.createEmptyBorder()); |
475 |
|
476 |
c.gridx = 1; |
477 |
c.gridy = 1; |
478 |
c.insets = new Insets(0, 0, 0, 0); |
479 |
c.anchor = GridBagConstraints.WEST; |
480 |
gridbag.setConstraints(tfAuthor, c); |
481 |
add(tfAuthor); |
482 |
|
483 |
c.gridx = 1; |
484 |
c.gridy = 2; |
485 |
gridbag.setConstraints(btnLicense, c); |
486 |
add(btnLicense); |
487 |
|
488 |
c.gridx = 1; |
489 |
c.gridy = 3; |
490 |
c.insets = new Insets(12, 0, 0, 0); |
491 |
gridbag.setConstraints(btnWebsite, c); |
492 |
add(btnWebsite); |
493 |
|
494 |
lProductName.setHorizontalAlignment(JLabel.CENTER); |
495 |
c.gridx = 0; |
496 |
c.gridy = 0; |
497 |
c.gridwidth = 2; |
498 |
c.insets = new Insets(0, 0, 12, 0); |
499 |
c.anchor = GridBagConstraints.CENTER; |
500 |
gridbag.setConstraints(lProductName, c); |
501 |
add(lProductName); |
502 |
} |
503 |
} |
504 |
} |