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; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
|
28 |
import javax.swing.SwingUtilities; |
29 |
|
30 |
import org.jsampler.view.JSViews; |
31 |
|
32 |
/** |
33 |
* The main class of the application. |
34 |
* @author Grigor Iliev |
35 |
*/ |
36 |
public class JSampler { |
37 |
/** The application name. */ |
38 |
public final static String NAME = "JSampler"; |
39 |
|
40 |
/** The application version. */ |
41 |
public final static String VERSION = "0.9"; |
42 |
|
43 |
public static String[] scripts; |
44 |
|
45 |
|
46 |
/** |
47 |
* The entry point of the application. |
48 |
* @param args The command line arguments. |
49 |
* @see CC#cleanExit |
50 |
*/ |
51 |
public static void |
52 |
main(String[] args) { |
53 |
scripts = args; |
54 |
CC.initJSampler(); |
55 |
initGUI(); |
56 |
} |
57 |
|
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 |
|
85 |
private static void |
86 |
initGUI() { |
87 |
JSViews.parseManifest(); |
88 |
JSViews.setView(JSViews.getDefaultView()); |
89 |
|
90 |
SwingUtilities.invokeLater(new Runnable() { |
91 |
public void |
92 |
run() { initGUI0(); } |
93 |
}); |
94 |
} |
95 |
|
96 |
private static void |
97 |
initGUI0() { |
98 |
if(scripts != null) { |
99 |
CC.addConnectionEstablishedListener(new ConnectionEstablishedListener()); |
100 |
} |
101 |
|
102 |
JSUtils.checkJSamplerHome(); |
103 |
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 |
scripts = null; |
115 |
SwingUtilities.invokeLater(this); |
116 |
} |
117 |
|
118 |
@Override |
119 |
public void |
120 |
run() { CC.removeConnectionEstablishedListener(this); } |
121 |
} |
122 |
} |