1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1864 |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
787 |
* |
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; |
24 |
|
|
|
25 |
iliev |
1786 |
import java.awt.event.ActionEvent; |
26 |
|
|
import java.awt.event.ActionListener; |
27 |
|
|
|
28 |
|
|
import javax.swing.SwingUtilities; |
29 |
|
|
|
30 |
iliev |
911 |
import org.jsampler.view.JSViews; |
31 |
iliev |
787 |
|
32 |
|
|
/** |
33 |
iliev |
911 |
* The main class of the application. |
34 |
iliev |
787 |
* @author Grigor Iliev |
35 |
|
|
*/ |
36 |
|
|
public class JSampler { |
37 |
iliev |
911 |
/** The application name. */ |
38 |
iliev |
787 |
public final static String NAME = "JSampler"; |
39 |
|
|
|
40 |
iliev |
911 |
/** The application version. */ |
41 |
iliev |
1567 |
public final static String VERSION = "0.8a"; |
42 |
iliev |
787 |
|
43 |
iliev |
1786 |
public static String[] scripts; |
44 |
iliev |
911 |
|
45 |
iliev |
1786 |
|
46 |
iliev |
911 |
/** |
47 |
|
|
* The entry point of the application. |
48 |
|
|
* @param args The command line arguments. |
49 |
|
|
* @see CC#cleanExit |
50 |
|
|
*/ |
51 |
iliev |
787 |
public static void |
52 |
|
|
main(String[] args) { |
53 |
iliev |
1786 |
scripts = args; |
54 |
iliev |
787 |
CC.initJSampler(); |
55 |
iliev |
1285 |
initGUI(); |
56 |
iliev |
787 |
} |
57 |
iliev |
1864 |
|
58 |
|
|
/** |
59 |
|
|
* Schedule the specified script to be run when connection is established. |
60 |
|
|
* @param fileName The path of the script to run. |
61 |
|
|
*/ |
62 |
|
|
public static void |
63 |
|
|
open(String fileName) { |
64 |
|
|
CC.getLogger().warning(fileName); |
65 |
|
|
if(fileName == null) return; |
66 |
|
|
if(CC.getClient().isConnected()) { |
67 |
|
|
CC.getMainFrame().runScript(fileName); |
68 |
|
|
return; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
if(scripts == null) { |
72 |
|
|
scripts = new String[1]; |
73 |
|
|
scripts[0] = fileName; |
74 |
|
|
CC.addConnectionEstablishedListener(new ConnectionEstablishedListener()); |
75 |
|
|
} else { |
76 |
|
|
String[] files = new String[scripts.length + 1]; |
77 |
|
|
for(int i = 0; i < scripts.length; i++) { |
78 |
|
|
files[i] = scripts[i]; |
79 |
|
|
} |
80 |
|
|
files[files.length - 1] = fileName; |
81 |
|
|
scripts = files; |
82 |
|
|
} |
83 |
|
|
} |
84 |
iliev |
787 |
|
85 |
|
|
private static void |
86 |
|
|
initGUI() { |
87 |
iliev |
911 |
JSViews.parseManifest(); |
88 |
|
|
JSViews.setView(JSViews.getDefaultView()); |
89 |
iliev |
1285 |
|
90 |
iliev |
1786 |
SwingUtilities.invokeLater(new Runnable() { |
91 |
iliev |
1285 |
public void |
92 |
iliev |
1786 |
run() { initGUI0(); } |
93 |
iliev |
1285 |
}); |
94 |
iliev |
787 |
} |
95 |
iliev |
1786 |
|
96 |
|
|
private static void |
97 |
|
|
initGUI0() { |
98 |
iliev |
1864 |
if(scripts != null) { |
99 |
|
|
CC.addConnectionEstablishedListener(new ConnectionEstablishedListener()); |
100 |
|
|
} |
101 |
iliev |
1786 |
|
102 |
iliev |
1915 |
JSUtils.checkJSamplerHome(); |
103 |
iliev |
1786 |
CC.loadOrchestras(); |
104 |
|
|
CC.loadServerList(); |
105 |
|
|
CC.connect(); |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
private static class ConnectionEstablishedListener implements ActionListener, Runnable { |
109 |
|
|
@Override |
110 |
|
|
public void |
111 |
|
|
actionPerformed(ActionEvent e) { |
112 |
|
|
if(scripts == null) return; |
113 |
|
|
for(String s : scripts) CC.getMainFrame().runScript(s); |
114 |
iliev |
1864 |
scripts = null; |
115 |
iliev |
1786 |
SwingUtilities.invokeLater(this); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
@Override |
119 |
|
|
public void |
120 |
|
|
run() { CC.removeConnectionEstablishedListener(this); } |
121 |
|
|
} |
122 |
iliev |
787 |
} |