1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2010 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.UIManager; |
31 |
|
32 |
import org.jsampler.CC; |
33 |
import org.jsampler.JSPrefs; |
34 |
|
35 |
import org.jsampler.view.InstrumentsDbTableView; |
36 |
import org.jsampler.view.InstrumentsDbTreeView; |
37 |
import org.jsampler.view.BasicIconSet; |
38 |
import org.jsampler.view.JSMainFrame; |
39 |
import org.jsampler.view.JSViewConfig; |
40 |
|
41 |
import org.pushingpixels.substance.api.SubstanceConstants; |
42 |
import org.pushingpixels.substance.api.SubstanceLookAndFeel; |
43 |
|
44 |
/** |
45 |
* |
46 |
* @author Grigor Iliev |
47 |
*/ |
48 |
public class ViewConfig extends JSViewConfig { |
49 |
private InstrumentsDbTreeView instrumentsDbTreeView = new TreeView(); |
50 |
private InstrumentsDbTableView instrumentsDbTableView = new TableView(); |
51 |
private BasicIconSet basicIconSet = new IconSet(); |
52 |
|
53 |
private Map nativeMenuPropsMap = null; |
54 |
private Map menuPropsMap = null; |
55 |
|
56 |
/** Creates a new instance of <code>ViewConfig</code> */ |
57 |
public |
58 |
ViewConfig() { |
59 |
try { |
60 |
if(isUsingScreenMenuBar()) { |
61 |
// fix for setting the menu bar on top of the screen |
62 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
63 |
nativeMenuPropsMap = getMenuProperties(); |
64 |
} |
65 |
UIManager.setLookAndFeel(new SubstanceFantasiaLookAndFeel()); |
66 |
UIManager.put(SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.FALSE); |
67 |
|
68 |
UIManager.put ( |
69 |
SubstanceLookAndFeel.TABBED_PANE_CONTENT_BORDER_KIND, |
70 |
SubstanceConstants.TabContentPaneBorderKind.SINGLE_FULL |
71 |
); |
72 |
|
73 |
if(isUsingScreenMenuBar()) { |
74 |
// fix for setting the menu bar on top of the screen |
75 |
menuPropsMap = getMenuProperties(); |
76 |
setNativeMenuProperties(); |
77 |
} |
78 |
|
79 |
if(!preferences().getBoolProperty("TurnOffCustomWindowDecoration")) { |
80 |
javax.swing.JFrame.setDefaultLookAndFeelDecorated(true); |
81 |
javax.swing.JDialog.setDefaultLookAndFeelDecorated(true); |
82 |
} |
83 |
|
84 |
Res.loadTheme(preferences().getStringProperty("Theme")); |
85 |
} catch(Exception e) { |
86 |
e.printStackTrace(); |
87 |
} |
88 |
} |
89 |
|
90 |
/** |
91 |
* If running on Mac OS and third party LaF is used |
92 |
* certain properties from the system LaF should be set |
93 |
* to be able to move the menu bar on top of the screen. |
94 |
*/ |
95 |
public void |
96 |
setNativeMenuProperties() { |
97 |
setMenuProperties(nativeMenuPropsMap); |
98 |
} |
99 |
|
100 |
/** |
101 |
* If running on Mac OS and third party LaF is used |
102 |
* certain properties from the system LaF should be set |
103 |
* to be able to move the menu bar on top of the screen. |
104 |
* This method is used to reverse them back to the LaF to be used. |
105 |
*/ |
106 |
public void |
107 |
restoreMenuProperties() { |
108 |
setMenuProperties(menuPropsMap); |
109 |
} |
110 |
|
111 |
private void |
112 |
setMenuProperties(Map props) { |
113 |
if(props == null) return; |
114 |
for(Object o : props.keySet()) UIManager.put(o, props.get(o)); |
115 |
} |
116 |
|
117 |
public Map |
118 |
getMenuProperties() { |
119 |
Map props = new HashMap(); |
120 |
props.put("MenuBarUI", UIManager.get("MenuBarUI")); |
121 |
props.put("MenuUI", UIManager.get("MenuUI")); |
122 |
props.put("MenuItemUI", UIManager.get("MenuItemUI")); |
123 |
props.put("CheckBoxMenuItemUI", UIManager.get("CheckBoxMenuItemUI")); |
124 |
props.put("RadioButtonMenuItemUI", UIManager.get("RadioButtonMenuItemUI")); |
125 |
props.put("PopupMenuUI", UIManager.get("PopupMenuUI")); |
126 |
return props; |
127 |
} |
128 |
|
129 |
@Override |
130 |
public JSPrefs |
131 |
preferences() { return FantasiaPrefs.preferences(); } |
132 |
|
133 |
/** Exports the view configuration of the current session. */ |
134 |
@Override |
135 |
public String |
136 |
exportSessionViewConfig() { |
137 |
StringBuffer sb = new StringBuffer(); |
138 |
MainFrame frame = (MainFrame)CC.getMainFrame(); |
139 |
|
140 |
for(int i = 0; i < frame.getChannelsPaneCount(); i++) { |
141 |
exportSamplerChannels(sb, i); |
142 |
} |
143 |
|
144 |
MidiDevicesPane midi = frame.getRightSidePane().getDevicesPane().getMidiDevicesPane(); |
145 |
|
146 |
for(int i = 0; i < midi.getDevicePaneCount(); i++) { |
147 |
sb.append("#jsampler.fantasia: [MIDI device]\r\n"); |
148 |
|
149 |
boolean b = midi.getDevicePaneAt(i).isOptionsPaneExpanded(); |
150 |
sb.append("#jsampler.fantasia: expanded = ").append(b).append("\r\n"); |
151 |
|
152 |
sb.append("#\r\n"); |
153 |
} |
154 |
|
155 |
AudioDevicesPane au = frame.getRightSidePane().getDevicesPane().getAudioDevicesPane(); |
156 |
|
157 |
for(int i = 0; i < au.getDevicePaneCount(); i++) { |
158 |
sb.append("#jsampler.fantasia: [audio device]\r\n"); |
159 |
|
160 |
boolean b = au.getDevicePaneAt(i).isOptionsPaneExpanded(); |
161 |
sb.append("#jsampler.fantasia: expanded = ").append(b).append("\r\n"); |
162 |
|
163 |
sb.append("#\r\n"); |
164 |
} |
165 |
|
166 |
return sb.toString(); |
167 |
} |
168 |
|
169 |
private void |
170 |
exportSamplerChannels(StringBuffer sb, int channelsPane) { |
171 |
JSMainFrame frame = CC.getMainFrame(); |
172 |
|
173 |
for(int i = 0; i < frame.getChannelsPane(channelsPane).getChannelCount(); i++) { |
174 |
Channel c = (Channel)frame.getChannelsPane(channelsPane).getChannel(i); |
175 |
|
176 |
sb.append("#jsampler.fantasia: [channel]\r\n"); |
177 |
|
178 |
sb.append("#jsampler.fantasia: channelLane = "); |
179 |
sb.append(channelsPane + 1).append("\r\n"); |
180 |
|
181 |
switch(c.getViewTracker().getOriginalView().getType()) { |
182 |
case SMALL: |
183 |
sb.append("#jsampler.fantasia: viewType = SMALL\r\n"); |
184 |
break; |
185 |
|
186 |
case NORMAL: |
187 |
sb.append("#jsampler.fantasia: viewType = NORMAL\r\n"); |
188 |
break; |
189 |
} |
190 |
|
191 |
boolean b = c.getViewTracker().getOriginalView().isOptionsButtonSelected(); |
192 |
sb.append("#jsampler.fantasia: expanded = ").append(b).append("\r\n"); |
193 |
|
194 |
sb.append("#\r\n"); |
195 |
} |
196 |
} |
197 |
|
198 |
@Override |
199 |
public InstrumentsDbTreeView |
200 |
getInstrumentsDbTreeView() { return instrumentsDbTreeView; } |
201 |
|
202 |
@Override |
203 |
public InstrumentsDbTableView |
204 |
getInstrumentsDbTableView() { return instrumentsDbTableView; } |
205 |
|
206 |
@Override |
207 |
public BasicIconSet |
208 |
getBasicIconSet() { return basicIconSet; } |
209 |
|
210 |
private class TreeView implements InstrumentsDbTreeView { |
211 |
@Override |
212 |
public Icon |
213 |
getRootIcon() { return Res.iconDb16; } |
214 |
|
215 |
@Override |
216 |
public Icon |
217 |
getClosedIcon() { return Res.iconFolder16; } |
218 |
|
219 |
@Override |
220 |
public Icon |
221 |
getOpenIcon() { return Res.iconFolderOpen16; } |
222 |
|
223 |
@Override |
224 |
public Icon |
225 |
getInstrumentIcon() { return Res.iconInstrument16; } |
226 |
|
227 |
@Override |
228 |
public Icon |
229 |
getGigInstrumentIcon() { return Res.iconInstrument16; } |
230 |
} |
231 |
|
232 |
private static class TableView implements InstrumentsDbTableView { |
233 |
@Override |
234 |
public Icon |
235 |
getFolderIcon() { return Res.iconFolder16; } |
236 |
|
237 |
@Override |
238 |
public Icon |
239 |
getInstrumentIcon() { return Res.iconInstrument16; } |
240 |
|
241 |
@Override |
242 |
public Icon |
243 |
getGigInstrumentIcon() { return Res.iconInstrument16; } |
244 |
} |
245 |
|
246 |
private class IconSet implements BasicIconSet { |
247 |
@Override |
248 |
public ImageIcon |
249 |
getApplicationIcon() { return Res.iconAppIcon; } |
250 |
|
251 |
@Override |
252 |
public Icon |
253 |
getBack16Icon() { return Res.iconBack16; } |
254 |
|
255 |
@Override |
256 |
public Icon |
257 |
getUp16Icon() { return Res.iconUp16; } |
258 |
|
259 |
@Override |
260 |
public Icon |
261 |
getForward16Icon() { return Res.iconNext16; } |
262 |
|
263 |
@Override |
264 |
public Icon |
265 |
getReload16Icon() { return Res.iconReload16; } |
266 |
|
267 |
@Override |
268 |
public Icon |
269 |
getPreferences16Icon() { return Res.iconPreferences16; } |
270 |
|
271 |
@Override |
272 |
public Icon |
273 |
getWarning32Icon() { return Res.iconWarning32; } |
274 |
|
275 |
@Override |
276 |
public Icon |
277 |
getQuestion32Icon() { return Res.iconQuestion32; } |
278 |
} |
279 |
|
280 |
@Override |
281 |
public boolean |
282 |
getInstrumentsDbSupport() { return true; } |
283 |
} |