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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 913 - (hide annotations) (download)
Mon Aug 7 18:45:48 2006 UTC (17 years, 8 months ago) by iliev
File size: 4504 byte(s)
updating to JSampler 0.3a

1 iliev 913 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005, 2006 Grigor Kirilov Iliev
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 org.jsampler.CC;
37     import org.jsampler.HF;
38    
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    
104     if(CC.getMainFrame() != null) CC.getMainFrame().setVisible(false);
105    
106     try { CC.setMainFrame((JSMainFrame) Class.forName(entry.mainFrame).newInstance()); }
107     catch(Exception e) {
108     CC.getLogger().info(HF.getErrorMessage(e));
109     if(CC.getMainFrame() != null) CC.getMainFrame().setVisible(true);
110     return;
111     }
112    
113     try { CC.setProgressIndicator (
114     (JSProgress)Class.forName(entry.progressIndicator).newInstance()
115     );} catch(Exception e) { CC.getLogger().info(HF.getErrorMessage(e)); }
116    
117     CC.getMainFrame().setVisible(true);
118    
119     currentView = viewName;
120     }
121    
122     /**
123     * Parses the manifest file <code>views.mf</code> to gather information
124     * about the available views in this JSampler distribution.
125     */
126     public static void
127     parseManifest() {
128     viewEntries.removeAllElements();
129    
130     try {
131     Manifest m = new Manifest(JSViews.class.getResourceAsStream("views.mf"));
132     String s = m.getMainAttributes().getValue("JS-Views");
133     if(s == null) {
134     CC.getLogger().warning("Missing manifest attribute: JS-Views");
135     return;
136     }
137    
138     StringTokenizer st = new StringTokenizer(s);
139     while(st.hasMoreTokens()) {
140     s = st.nextToken();
141     Attributes a = m.getAttributes(s);
142    
143     if(a == null) {
144     CC.getLogger().warning("Missing manifest entry: " + s);
145     continue;
146     }
147    
148     ViewEntry ve = new ViewEntry();
149     ve.name = a.getValue("View-Name");
150     ve.mainFrame = a.getValue("Main-Frame");
151     ve.progressIndicator = a.getValue("Progress-Indicator");
152    
153     viewEntries.addElement(ve);
154     }
155    
156     s = m.getMainAttributes().getValue("JS-Default-View");
157     Attributes a = m.getAttributes(s);
158     if(a != null) defaultView = a.getValue("View-Name");
159     } catch(Exception x) {
160     CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
161     }
162     }
163    
164     private static class ViewEntry {
165     String name;
166     String mainFrame;
167     String progressIndicator;
168     }
169     }

  ViewVC Help
Powered by ViewVC