/[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 2288 - (show annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 4905 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

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

  ViewVC Help
Powered by ViewVC