1 |
iliev |
1308 |
/* |
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 |
|
|
package org.jsampler.view.std; |
23 |
|
|
|
24 |
iliev |
1496 |
import java.awt.Desktop; |
25 |
|
|
|
26 |
|
|
import java.net.URI; |
27 |
|
|
|
28 |
iliev |
1308 |
import java.util.Vector; |
29 |
|
|
|
30 |
|
|
import org.jsampler.CC; |
31 |
iliev |
1496 |
import org.jsampler.HF; |
32 |
iliev |
1308 |
import org.jsampler.JSPrefs; |
33 |
|
|
|
34 |
iliev |
1496 |
import static org.jsampler.view.std.StdI18n.i18n; |
35 |
iliev |
1308 |
|
36 |
iliev |
1496 |
|
37 |
iliev |
1308 |
/** |
38 |
|
|
* |
39 |
|
|
* @author Grigor Iliev |
40 |
|
|
*/ |
41 |
|
|
public class StdUtils { |
42 |
|
|
|
43 |
|
|
/** Forbids the instantiation of this class */ |
44 |
|
|
private |
45 |
|
|
StdUtils() { } |
46 |
|
|
|
47 |
|
|
private static JSPrefs |
48 |
|
|
preferences() { return CC.getViewConfig().preferences(); } |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Updates the specified string list property by adding the specified |
52 |
|
|
* element on the top. Also restricts the maximum number of elements to 12. |
53 |
|
|
*/ |
54 |
|
|
public static void |
55 |
|
|
updateRecentElements(String property, String newElement) { |
56 |
|
|
String[] elements = preferences().getStringListProperty(property); |
57 |
|
|
Vector<String> v = new Vector<String>(); |
58 |
|
|
v.add(newElement); |
59 |
|
|
for(String s : elements) { |
60 |
|
|
if(!newElement.equals(s)) v.add(s); |
61 |
|
|
} |
62 |
|
|
if(v.size() > 12) v.setSize(12); |
63 |
|
|
|
64 |
|
|
elements = v.toArray(new String[v.size()]); |
65 |
|
|
preferences().setStringListProperty(property, elements); |
66 |
|
|
} |
67 |
iliev |
1496 |
|
68 |
|
|
public static boolean |
69 |
|
|
checkDesktopSupported() { |
70 |
|
|
if(Desktop.isDesktopSupported()) return true; |
71 |
|
|
|
72 |
|
|
String s = i18n.getError("StdUtils.DesktopApiNotSupported"); |
73 |
|
|
HF.showErrorMessage(s, CC.getMainFrame()); |
74 |
|
|
|
75 |
|
|
return false; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
public static void |
79 |
|
|
browse(String uri) { |
80 |
|
|
if(!checkDesktopSupported()) return; |
81 |
|
|
|
82 |
|
|
try { Desktop.getDesktop().browse(new URI(uri)); } |
83 |
|
|
catch(Exception x) { x.printStackTrace(); } |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
public static void |
87 |
|
|
mail(String uri) { |
88 |
|
|
if(!StdUtils.checkDesktopSupported()) return; |
89 |
|
|
|
90 |
|
|
Desktop desktop = Desktop.getDesktop(); |
91 |
|
|
|
92 |
|
|
try { Desktop.getDesktop().mail(new URI(uri)); } |
93 |
|
|
catch(Exception x) { x.printStackTrace(); } |
94 |
|
|
} |
95 |
iliev |
1308 |
} |