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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2195 - (show annotations) (download)
Tue Jun 28 22:44:39 2011 UTC (12 years, 10 months ago) by iliev
File size: 10524 byte(s)
* Sampler Browser (work in progress): initial implementation of main pane

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

  ViewVC Help
Powered by ViewVC