/[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 2148 - (show annotations) (download)
Thu Oct 14 14:45:42 2010 UTC (13 years, 5 months ago) by iliev
File size: 8322 byte(s)
* Add/Edit Instrument dialog and New MIDI Instrument wizard
  are now resizable
* Using multicolumn menus for loading instruments from
  Instruments Database and selecting values in string list parameters

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

  ViewVC Help
Powered by ViewVC