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

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/ViewConfig.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (hide annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 12276 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2195 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
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.view.fantasia;
24    
25 iliev 2288 import org.jsampler.view.swing.SHF;
26 iliev 1864 import java.util.HashMap;
27     import java.util.Map;
28    
29 iliev 1286 import javax.swing.Icon;
30 iliev 1786 import javax.swing.ImageIcon;
31 iliev 2148 import javax.swing.JPopupMenu;
32 iliev 1286 import javax.swing.UIManager;
33    
34 iliev 2200 import org.jsampler.AudioDeviceModel;
35 iliev 1752 import org.jsampler.CC;
36 iliev 1286 import org.jsampler.JSPrefs;
37    
38 iliev 2288 import org.jsampler.view.JSMainFrame;
39 iliev 1286 import org.jsampler.view.InstrumentsDbTableView;
40     import org.jsampler.view.InstrumentsDbTreeView;
41 iliev 1752 import org.jsampler.view.BasicIconSet;
42 iliev 2148 import org.jsampler.view.fantasia.basic.MultiColumnMenu;
43 iliev 2200 import org.jsampler.view.std.StdViewConfig;
44 iliev 1286
45 iliev 2146 import org.pushingpixels.substance.api.SubstanceConstants;
46     import org.pushingpixels.substance.api.SubstanceLookAndFeel;
47 iliev 1286
48 iliev 2288 import static org.jsampler.view.swing.SamplerTreeModel.*;
49 iliev 2195
50 iliev 1286 /**
51     *
52     * @author Grigor Iliev
53     */
54 iliev 2200 public class ViewConfig extends StdViewConfig {
55 iliev 1286 private InstrumentsDbTreeView instrumentsDbTreeView = new TreeView();
56     private InstrumentsDbTableView instrumentsDbTableView = new TableView();
57 iliev 2195 private SamplerBrowserView samplerBrowserView = new SamplerBrowserView();
58 iliev 1752 private BasicIconSet basicIconSet = new IconSet();
59 iliev 1864
60     private Map nativeMenuPropsMap = null;
61     private Map menuPropsMap = null;
62 iliev 1286
63     /** Creates a new instance of <code>ViewConfig</code> */
64     public
65     ViewConfig() {
66     try {
67 iliev 1865 if(isUsingScreenMenuBar()) {
68 iliev 1864 // fix for setting the menu bar on top of the screen
69     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
70     nativeMenuPropsMap = getMenuProperties();
71     }
72 iliev 2146 UIManager.setLookAndFeel(new SubstanceFantasiaLookAndFeel());
73 iliev 1743 UIManager.put(SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.FALSE);
74 iliev 1496
75 iliev 1729 UIManager.put (
76     SubstanceLookAndFeel.TABBED_PANE_CONTENT_BORDER_KIND,
77     SubstanceConstants.TabContentPaneBorderKind.SINGLE_FULL
78     );
79 iliev 1864
80 iliev 1865 if(isUsingScreenMenuBar()) {
81 iliev 1864 // fix for setting the menu bar on top of the screen
82     menuPropsMap = getMenuProperties();
83     setNativeMenuProperties();
84     }
85 iliev 1729
86 iliev 1496 if(!preferences().getBoolProperty("TurnOffCustomWindowDecoration")) {
87     javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
88     javax.swing.JDialog.setDefaultLookAndFeelDecorated(true);
89     }
90    
91     Res.loadTheme(preferences().getStringProperty("Theme"));
92 iliev 1286 } catch(Exception e) {
93     e.printStackTrace();
94     }
95     }
96 iliev 1864
97     /**
98     * If running on Mac OS and third party LaF is used
99     * certain properties from the system LaF should be set
100     * to be able to move the menu bar on top of the screen.
101     */
102     public void
103     setNativeMenuProperties() {
104     setMenuProperties(nativeMenuPropsMap);
105     }
106    
107     /**
108     * If running on Mac OS and third party LaF is used
109     * certain properties from the system LaF should be set
110     * to be able to move the menu bar on top of the screen.
111     * This method is used to reverse them back to the LaF to be used.
112     */
113     public void
114     restoreMenuProperties() {
115     setMenuProperties(menuPropsMap);
116     }
117    
118     private void
119     setMenuProperties(Map props) {
120     if(props == null) return;
121     for(Object o : props.keySet()) UIManager.put(o, props.get(o));
122     }
123    
124     public Map
125     getMenuProperties() {
126     Map props = new HashMap();
127     props.put("MenuBarUI", UIManager.get("MenuBarUI"));
128     props.put("MenuUI", UIManager.get("MenuUI"));
129     props.put("MenuItemUI", UIManager.get("MenuItemUI"));
130     props.put("CheckBoxMenuItemUI", UIManager.get("CheckBoxMenuItemUI"));
131     props.put("RadioButtonMenuItemUI", UIManager.get("RadioButtonMenuItemUI"));
132     props.put("PopupMenuUI", UIManager.get("PopupMenuUI"));
133     return props;
134     }
135 iliev 1286
136 iliev 1786 @Override
137 iliev 1286 public JSPrefs
138     preferences() { return FantasiaPrefs.preferences(); }
139    
140 iliev 1767 /** Exports the view configuration of the current session. */
141 iliev 1786 @Override
142 iliev 1767 public String
143     exportSessionViewConfig() {
144     StringBuffer sb = new StringBuffer();
145 iliev 2288 MainFrame frame = (MainFrame)SHF.getMainFrame();
146 iliev 1767
147 iliev 1818 for(int i = 0; i < frame.getChannelsPaneCount(); i++) {
148     exportSamplerChannels(sb, i);
149     }
150    
151     MidiDevicesPane midi = frame.getRightSidePane().getDevicesPane().getMidiDevicesPane();
152    
153     for(int i = 0; i < midi.getDevicePaneCount(); i++) {
154     sb.append("#jsampler.fantasia: [MIDI device]\r\n");
155 iliev 1767
156 iliev 1818 boolean b = midi.getDevicePaneAt(i).isOptionsPaneExpanded();
157     sb.append("#jsampler.fantasia: expanded = ").append(b).append("\r\n");
158    
159     sb.append("#\r\n");
160     }
161    
162     AudioDevicesPane au = frame.getRightSidePane().getDevicesPane().getAudioDevicesPane();
163    
164     for(int i = 0; i < au.getDevicePaneCount(); i++) {
165     sb.append("#jsampler.fantasia: [audio device]\r\n");
166    
167     boolean b = au.getDevicePaneAt(i).isOptionsPaneExpanded();
168     sb.append("#jsampler.fantasia: expanded = ").append(b).append("\r\n");
169    
170     sb.append("#\r\n");
171     }
172    
173     return sb.toString();
174     }
175    
176     private void
177     exportSamplerChannels(StringBuffer sb, int channelsPane) {
178     JSMainFrame frame = CC.getMainFrame();
179    
180     for(int i = 0; i < frame.getChannelsPane(channelsPane).getChannelCount(); i++) {
181     Channel c = (Channel)frame.getChannelsPane(channelsPane).getChannel(i);
182    
183 iliev 1767 sb.append("#jsampler.fantasia: [channel]\r\n");
184    
185 iliev 1867 sb.append("#jsampler.fantasia: channelLane = ");
186 iliev 1818 sb.append(channelsPane + 1).append("\r\n");
187    
188 iliev 1767 switch(c.getViewTracker().getOriginalView().getType()) {
189     case SMALL:
190     sb.append("#jsampler.fantasia: viewType = SMALL\r\n");
191     break;
192    
193     case NORMAL:
194     sb.append("#jsampler.fantasia: viewType = NORMAL\r\n");
195     break;
196     }
197    
198 iliev 1818 boolean b = c.getViewTracker().getOriginalView().isOptionsButtonSelected();
199     sb.append("#jsampler.fantasia: expanded = ").append(b).append("\r\n");
200 iliev 1767
201 iliev 1818 sb.append("#\r\n");
202 iliev 1767 }
203     }
204    
205 iliev 1786 @Override
206 iliev 1286 public InstrumentsDbTreeView
207     getInstrumentsDbTreeView() { return instrumentsDbTreeView; }
208    
209 iliev 1786 @Override
210 iliev 1286 public InstrumentsDbTableView
211     getInstrumentsDbTableView() { return instrumentsDbTableView; }
212    
213 iliev 1786 @Override
214 iliev 2195 public org.jsampler.view.SamplerBrowserView
215     getSamplerBrowserView() { return samplerBrowserView; }
216    
217     @Override
218 iliev 1752 public BasicIconSet
219     getBasicIconSet() { return basicIconSet; }
220    
221 iliev 1286 private class TreeView implements InstrumentsDbTreeView {
222 iliev 1786 @Override
223 iliev 1286 public Icon
224     getRootIcon() { return Res.iconDb16; }
225    
226 iliev 1786 @Override
227 iliev 1286 public Icon
228     getClosedIcon() { return Res.iconFolder16; }
229    
230 iliev 1786 @Override
231 iliev 1286 public Icon
232     getOpenIcon() { return Res.iconFolderOpen16; }
233    
234 iliev 1786 @Override
235 iliev 1286 public Icon
236     getInstrumentIcon() { return Res.iconInstrument16; }
237    
238 iliev 1786 @Override
239 iliev 1286 public Icon
240     getGigInstrumentIcon() { return Res.iconInstrument16; }
241     }
242    
243     private static class TableView implements InstrumentsDbTableView {
244 iliev 1786 @Override
245 iliev 1286 public Icon
246     getFolderIcon() { return Res.iconFolder16; }
247    
248 iliev 1786 @Override
249 iliev 1286 public Icon
250     getInstrumentIcon() { return Res.iconInstrument16; }
251    
252 iliev 1786 @Override
253 iliev 1286 public Icon
254     getGigInstrumentIcon() { return Res.iconInstrument16; }
255     }
256    
257 iliev 1752 private class IconSet implements BasicIconSet {
258 iliev 1786 @Override
259     public ImageIcon
260     getApplicationIcon() { return Res.iconAppIcon; }
261    
262     @Override
263 iliev 1752 public Icon
264     getBack16Icon() { return Res.iconBack16; }
265    
266 iliev 1786 @Override
267 iliev 1752 public Icon
268     getUp16Icon() { return Res.iconUp16; }
269    
270 iliev 1786 @Override
271 iliev 1752 public Icon
272     getForward16Icon() { return Res.iconNext16; }
273    
274 iliev 1786 @Override
275 iliev 1752 public Icon
276     getReload16Icon() { return Res.iconReload16; }
277    
278 iliev 1786 @Override
279 iliev 1752 public Icon
280     getPreferences16Icon() { return Res.iconPreferences16; }
281 iliev 1767
282 iliev 1786 @Override
283 iliev 1767 public Icon
284     getWarning32Icon() { return Res.iconWarning32; }
285    
286 iliev 1786 @Override
287 iliev 1767 public Icon
288     getQuestion32Icon() { return Res.iconQuestion32; }
289 iliev 1752 }
290    
291 iliev 2195 private class SamplerBrowserView implements org.jsampler.view.SamplerBrowserView {
292     @Override
293     public Icon
294     getSamplerIcon() { return Res.iconSampler16; }
295    
296     @Override
297     public Icon
298 iliev 2200 getOpenIcon() { return Res.iconFolderOpen16; }
299    
300     @Override
301     public Icon
302     getCloseIcon() { return Res.iconFolder16; }
303    
304     @Override
305     public Icon
306     getChannelLaneOpenIcon() { return Res.iconFolderOpen16; }
307    
308     @Override
309     public Icon
310     getChannelLaneCloseIcon() { return Res.iconFolder16; }
311    
312     @Override
313     public Icon
314     getSamplerChannelIcon() { return Res.iconSamplerChannel16; }
315    
316     @Override
317     public Icon
318     getFxSendsOpenIcon() { return Res.iconFolderOpen16; }
319    
320     @Override
321     public Icon
322     getFxSendsCloseIcon() { return Res.iconFolder16; }
323    
324     @Override
325     public Icon
326     getFxSendIcon() { return Res.iconFxSend16; }
327    
328     @Override
329     public Icon
330     getDestEffectDirIcon() { return Res.iconDestEffect16; }
331    
332     @Override
333     public Icon
334     getDestEffectIcon() { return Res.iconEffectInstanceLnk16; }
335    
336     @Override
337     public Icon
338 iliev 2195 getAudioDevicesOpenIcon() { return Res.iconAudioDevsOpen16; }
339    
340     @Override
341     public Icon
342     getAudioDevicesCloseIcon() { return Res.iconAudioDevsClose16; }
343    
344     @Override
345     public Icon
346     getAudioDeviceIcon() { return Res.iconAudioDev16; }
347    
348     @Override
349     public Icon
350     getEffectsOpenIcon() { return Res.iconEffectsOpen16; }
351    
352     @Override
353     public Icon
354     getEffectsCloseIcon() { return Res.iconEffectsClose16; }
355    
356     @Override
357     public Icon
358     getEffectIcon() { return Res.iconEffect16; }
359    
360     @Override
361     public Icon
362     getEffectInstanceIcon() { return Res.iconEffectInstance16; }
363    
364     @Override
365     public Icon
366     getEffectChainIcon() { return Res.iconEffectChain16; }
367    
368     @Override
369     public Icon
370     getEffectChainsOpenIcon() { return Res.iconEffectChainsOpen16; }
371    
372     @Override
373     public Icon
374     getEffectChainsCloseIcon() { return Res.iconEffectChainsClose16; }
375    
376     @Override
377     public Icon
378     getIcon(Object value, boolean b) {
379     if(value instanceof SamplerTreeNode) return getSamplerIcon();
380    
381 iliev 2200 if(value instanceof SamplerChannelDirTreeNode) {
382     if(b) return getOpenIcon();
383     else return getCloseIcon();
384     }
385    
386     if(value instanceof ChannelLaneTreeNode) {
387     if(b) return getChannelLaneOpenIcon();
388     else return getChannelLaneCloseIcon();
389     }
390    
391     if(value instanceof SamplerChannelTreeNode) return getSamplerChannelIcon();
392    
393     if(value instanceof FxSendDirTreeNode) {
394     if(b) return getFxSendsOpenIcon();
395     else return getFxSendsCloseIcon();
396     }
397    
398     if(value instanceof FxSendTreeNode) return getFxSendIcon();
399    
400 iliev 2195 if(value instanceof AudioDevicesTreeNode) {
401     if(b) return getAudioDevicesOpenIcon();
402     else return getAudioDevicesCloseIcon();
403     }
404    
405 iliev 2200 if(value instanceof DestEffectDirTreeNode) return getDestEffectDirIcon();
406     if(value instanceof DestEffectTreeNode) return getDestEffectIcon();
407    
408 iliev 2195 if(value instanceof AudioDeviceTreeNode) return getAudioDeviceIcon();
409    
410     if(value instanceof SendEffectChainsTreeNode) {
411     if(b) return getEffectChainsOpenIcon();
412     else return getEffectChainsCloseIcon();
413     }
414    
415     if(value instanceof SendEffectChainTreeNode) return getEffectChainIcon();
416    
417     if(value instanceof EffectInstanceTreeNode) return getEffectInstanceIcon();
418    
419     if(value instanceof InternalEffectsTreeNode) {
420     if(b) return getEffectsOpenIcon();
421     else return getEffectsCloseIcon();
422     }
423    
424     if(value instanceof InternalEffectTreeNode) return getEffectIcon();
425    
426     return null;
427     }
428     }
429    
430 iliev 1786 @Override
431 iliev 1286 public boolean
432     getInstrumentsDbSupport() { return true; }
433 iliev 2148
434     /** Constructs a new multicolumn menu with the supplied string as its text. */
435     @Override
436     public javax.swing.JMenu
437     createMultiColumnMenu(String s) { return new MultiColumnMenu(s); }
438    
439     /** Constructs a new multicolumn popup menu. */
440     @Override
441     public JPopupMenu
442     createMultiColumnPopupMenu()
443     { return new MultiColumnMenu.FantasiaPopupMenu(); }
444 iliev 2200
445     @Override
446     public DestEffectChooser
447     createDestEffectChooser(AudioDeviceModel dev) { return new DestEffectChooser(dev); }
448 iliev 1286 }

  ViewVC Help
Powered by ViewVC