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 |
package org.jsampler.view.fantasia; |
24 |
|
25 |
import java.util.HashMap; |
26 |
import java.util.Map; |
27 |
|
28 |
import javax.swing.Icon; |
29 |
import javax.swing.ImageIcon; |
30 |
import javax.swing.JPopupMenu; |
31 |
import javax.swing.UIManager; |
32 |
|
33 |
import org.jsampler.AudioDeviceModel; |
34 |
import org.jsampler.CC; |
35 |
import org.jsampler.JSPrefs; |
36 |
|
37 |
import org.jsampler.view.InstrumentsDbTableView; |
38 |
import org.jsampler.view.InstrumentsDbTreeView; |
39 |
import org.jsampler.view.BasicIconSet; |
40 |
import org.jsampler.view.JSMainFrame; |
41 |
import org.jsampler.view.fantasia.basic.MultiColumnMenu; |
42 |
import org.jsampler.view.std.JSDestEffectChooser; |
43 |
import org.jsampler.view.std.StdViewConfig; |
44 |
|
45 |
import org.pushingpixels.substance.api.SubstanceConstants; |
46 |
import org.pushingpixels.substance.api.SubstanceLookAndFeel; |
47 |
|
48 |
import static org.jsampler.view.SamplerTreeModel.*; |
49 |
|
50 |
/** |
51 |
* |
52 |
* @author Grigor Iliev |
53 |
*/ |
54 |
public class ViewConfig extends StdViewConfig { |
55 |
private InstrumentsDbTreeView instrumentsDbTreeView = new TreeView(); |
56 |
private InstrumentsDbTableView instrumentsDbTableView = new TableView(); |
57 |
private SamplerBrowserView samplerBrowserView = new SamplerBrowserView(); |
58 |
private BasicIconSet basicIconSet = new IconSet(); |
59 |
|
60 |
private Map nativeMenuPropsMap = null; |
61 |
private Map menuPropsMap = null; |
62 |
|
63 |
/** Creates a new instance of <code>ViewConfig</code> */ |
64 |
public |
65 |
ViewConfig() { |
66 |
try { |
67 |
if(isUsingScreenMenuBar()) { |
68 |
// fix for setting the menu bar on top of the screen |
69 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
70 |
nativeMenuPropsMap = getMenuProperties(); |
71 |
} |
72 |
UIManager.setLookAndFeel(new SubstanceFantasiaLookAndFeel()); |
73 |
UIManager.put(SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.FALSE); |
74 |
|
75 |
UIManager.put ( |
76 |
SubstanceLookAndFeel.TABBED_PANE_CONTENT_BORDER_KIND, |
77 |
SubstanceConstants.TabContentPaneBorderKind.SINGLE_FULL |
78 |
); |
79 |
|
80 |
if(isUsingScreenMenuBar()) { |
81 |
// fix for setting the menu bar on top of the screen |
82 |
menuPropsMap = getMenuProperties(); |
83 |
setNativeMenuProperties(); |
84 |
} |
85 |
|
86 |
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 |
} catch(Exception e) { |
93 |
e.printStackTrace(); |
94 |
} |
95 |
} |
96 |
|
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 |
|
136 |
@Override |
137 |
public JSPrefs |
138 |
preferences() { return FantasiaPrefs.preferences(); } |
139 |
|
140 |
/** Exports the view configuration of the current session. */ |
141 |
@Override |
142 |
public String |
143 |
exportSessionViewConfig() { |
144 |
StringBuffer sb = new StringBuffer(); |
145 |
MainFrame frame = (MainFrame)CC.getMainFrame(); |
146 |
|
147 |
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 |
|
156 |
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 |
sb.append("#jsampler.fantasia: [channel]\r\n"); |
184 |
|
185 |
sb.append("#jsampler.fantasia: channelLane = "); |
186 |
sb.append(channelsPane + 1).append("\r\n"); |
187 |
|
188 |
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 |
boolean b = c.getViewTracker().getOriginalView().isOptionsButtonSelected(); |
199 |
sb.append("#jsampler.fantasia: expanded = ").append(b).append("\r\n"); |
200 |
|
201 |
sb.append("#\r\n"); |
202 |
} |
203 |
} |
204 |
|
205 |
@Override |
206 |
public InstrumentsDbTreeView |
207 |
getInstrumentsDbTreeView() { return instrumentsDbTreeView; } |
208 |
|
209 |
@Override |
210 |
public InstrumentsDbTableView |
211 |
getInstrumentsDbTableView() { return instrumentsDbTableView; } |
212 |
|
213 |
@Override |
214 |
public org.jsampler.view.SamplerBrowserView |
215 |
getSamplerBrowserView() { return samplerBrowserView; } |
216 |
|
217 |
@Override |
218 |
public BasicIconSet |
219 |
getBasicIconSet() { return basicIconSet; } |
220 |
|
221 |
private class TreeView implements InstrumentsDbTreeView { |
222 |
@Override |
223 |
public Icon |
224 |
getRootIcon() { return Res.iconDb16; } |
225 |
|
226 |
@Override |
227 |
public Icon |
228 |
getClosedIcon() { return Res.iconFolder16; } |
229 |
|
230 |
@Override |
231 |
public Icon |
232 |
getOpenIcon() { return Res.iconFolderOpen16; } |
233 |
|
234 |
@Override |
235 |
public Icon |
236 |
getInstrumentIcon() { return Res.iconInstrument16; } |
237 |
|
238 |
@Override |
239 |
public Icon |
240 |
getGigInstrumentIcon() { return Res.iconInstrument16; } |
241 |
} |
242 |
|
243 |
private static class TableView implements InstrumentsDbTableView { |
244 |
@Override |
245 |
public Icon |
246 |
getFolderIcon() { return Res.iconFolder16; } |
247 |
|
248 |
@Override |
249 |
public Icon |
250 |
getInstrumentIcon() { return Res.iconInstrument16; } |
251 |
|
252 |
@Override |
253 |
public Icon |
254 |
getGigInstrumentIcon() { return Res.iconInstrument16; } |
255 |
} |
256 |
|
257 |
private class IconSet implements BasicIconSet { |
258 |
@Override |
259 |
public ImageIcon |
260 |
getApplicationIcon() { return Res.iconAppIcon; } |
261 |
|
262 |
@Override |
263 |
public Icon |
264 |
getBack16Icon() { return Res.iconBack16; } |
265 |
|
266 |
@Override |
267 |
public Icon |
268 |
getUp16Icon() { return Res.iconUp16; } |
269 |
|
270 |
@Override |
271 |
public Icon |
272 |
getForward16Icon() { return Res.iconNext16; } |
273 |
|
274 |
@Override |
275 |
public Icon |
276 |
getReload16Icon() { return Res.iconReload16; } |
277 |
|
278 |
@Override |
279 |
public Icon |
280 |
getPreferences16Icon() { return Res.iconPreferences16; } |
281 |
|
282 |
@Override |
283 |
public Icon |
284 |
getWarning32Icon() { return Res.iconWarning32; } |
285 |
|
286 |
@Override |
287 |
public Icon |
288 |
getQuestion32Icon() { return Res.iconQuestion32; } |
289 |
} |
290 |
|
291 |
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 |
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 |
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 |
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 |
if(value instanceof AudioDevicesTreeNode) { |
401 |
if(b) return getAudioDevicesOpenIcon(); |
402 |
else return getAudioDevicesCloseIcon(); |
403 |
} |
404 |
|
405 |
if(value instanceof DestEffectDirTreeNode) return getDestEffectDirIcon(); |
406 |
if(value instanceof DestEffectTreeNode) return getDestEffectIcon(); |
407 |
|
408 |
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 |
@Override |
431 |
public boolean |
432 |
getInstrumentsDbSupport() { return true; } |
433 |
|
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 |
|
445 |
@Override |
446 |
public DestEffectChooser |
447 |
createDestEffectChooser(AudioDeviceModel dev) { return new DestEffectChooser(dev); } |
448 |
} |