/[svn]/jsampler/trunk/src/org/jsampler/view/JSViews.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/JSViews.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1285 - (show annotations) (download)
Fri Aug 10 19:55:03 2007 UTC (16 years, 8 months ago) by iliev
File size: 4948 byte(s)
* Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

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
24 package org.jsampler.view;
25
26 import java.net.URL;
27
28 import java.util.StringTokenizer;
29 import java.util.Vector;
30
31 import java.util.jar.Attributes;
32 import java.util.jar.Manifest;
33
34 import java.util.logging.Level;
35
36 import javax.swing.SwingUtilities;
37
38 import org.jsampler.CC;
39 import org.jsampler.HF;
40
41 /**
42 * This class provides information about the available views in the current distribution.
43 * @author Grigor Iliev
44 */
45 public class JSViews {
46 private static Vector<ViewEntry> viewEntries = new Vector<ViewEntry>();
47 private static String currentView = null;
48 private static String defaultView = null;
49
50 /** Forbits instantiation of JSViews */
51 private
52 JSViews() { }
53
54 /**
55 * Gets a list of all available views.
56 * @return A list of all available views.
57 */
58 public static String[]
59 getAvailableViews() {
60 String[] views = new String[viewEntries.size()];
61 for(int i = 0; i < viewEntries.size(); i++) views[i] = viewEntries.get(i).name;
62 return views;
63 }
64
65 /**
66 * Gets the current view name of this distribution.
67 * @return The current view name of this distribution.
68 */
69 public static String
70 getCurrentView() { return currentView; }
71
72 /**
73 * Gets the default view name of this distribution.
74 * @return The default view name of this distribution.
75 */
76 public static String
77 getDefaultView() { return defaultView; }
78
79 /**
80 * Changes the current view.
81 * This method should be invoked only from the event-dispatching thread.
82 * @param viewName The new view to be used.
83 */
84 public static void
85 setView(String viewName) {
86 if(viewName == null) {
87 CC.getLogger().info("viewName is null!");
88 return;
89 }
90
91 ViewEntry entry = null;
92
93 for(ViewEntry ve : viewEntries) {
94 if(viewName.equals(ve.name)) {
95 entry = ve;
96 break;
97 }
98 }
99
100 if(entry == null) {
101 CC.getLogger().info("Missing view: " + viewName);
102 return;
103 }
104 if(CC.getMainFrame() != null) {
105 SwingUtilities.invokeLater(new Runnable() {
106 public void
107 run() { CC.getMainFrame().setVisible(false); }
108 });
109 }
110
111 try {
112 CC.setViewConfig (
113 (JSViewConfig)Class.forName(entry.viewConfig).newInstance()
114 );
115 } catch(Exception e) {
116 CC.getLogger().info(HF.getErrorMessage(e));
117 return;
118 }
119
120 final ViewEntry e = entry;
121 SwingUtilities.invokeLater(new Runnable() {
122 public void
123 run() { setView0(e); }
124 });
125 }
126
127 private static void
128 setView0(ViewEntry entry) {
129 try {
130 CC.setMainFrame((JSMainFrame)Class.forName(entry.mainFrame).newInstance());
131 CC.setProgressIndicator (
132 (JSProgress)Class.forName(entry.progressIndicator).newInstance()
133 );
134 CC.getMainFrame().setVisible(true);
135 currentView = entry.name;
136 } catch(Exception e) {
137 CC.getLogger().log(Level.INFO, HF.getErrorMessage(e), e);
138 return;
139 }
140 }
141
142 /**
143 * Parses the manifest file <code>views.mf</code> to gather information
144 * about the available views in this JSampler distribution.
145 */
146 public static void
147 parseManifest() {
148 viewEntries.removeAllElements();
149
150 try {
151 Manifest m = new Manifest(JSViews.class.getResourceAsStream("views.mf"));
152 String s = m.getMainAttributes().getValue("JS-Views");
153 if(s == null) {
154 CC.getLogger().warning("Missing manifest attribute: JS-Views");
155 return;
156 }
157
158 StringTokenizer st = new StringTokenizer(s);
159 while(st.hasMoreTokens()) {
160 s = st.nextToken();
161 Attributes a = m.getAttributes(s);
162
163 if(a == null) {
164 CC.getLogger().warning("Missing manifest entry: " + s);
165 continue;
166 }
167
168 ViewEntry ve = new ViewEntry();
169 ve.name = a.getValue("View-Name");
170 ve.viewConfig = a.getValue("View-Config");
171 ve.mainFrame = a.getValue("Main-Frame");
172 ve.progressIndicator = a.getValue("Progress-Indicator");
173
174 viewEntries.addElement(ve);
175 }
176
177 s = m.getMainAttributes().getValue("JS-Default-View");
178 Attributes a = m.getAttributes(s);
179 if(a != null) defaultView = a.getValue("View-Name");
180 } catch(Exception x) {
181 CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
182 }
183 }
184
185 private static class ViewEntry {
186 String name;
187 String viewConfig;
188 String mainFrame;
189 String progressIndicator;
190 }
191 }

  ViewVC Help
Powered by ViewVC