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; |
24 |
|
25 |
import java.beans.PropertyChangeEvent; |
26 |
import java.beans.PropertyChangeListener; |
27 |
|
28 |
import org.jsampler.CC; |
29 |
import org.jsampler.JSPrefs; |
30 |
import org.jsampler.MidiInstrument; |
31 |
|
32 |
import static org.jsampler.JSPrefs.*; |
33 |
|
34 |
/** |
35 |
* Provides the view configuration. |
36 |
* @author Grigor Iliev |
37 |
*/ |
38 |
public abstract class JSViewConfig<I> { |
39 |
private boolean measurementUnitDecibel; |
40 |
|
41 |
private int firstMidiBankNumber; |
42 |
private int firstMidiProgramNumber; |
43 |
|
44 |
/** Creates a new instance of <code>JSViewConfig</code> */ |
45 |
public |
46 |
JSViewConfig() { |
47 |
measurementUnitDecibel = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
48 |
|
49 |
String s = VOL_MEASUREMENT_UNIT_DECIBEL; |
50 |
preferences().addPropertyChangeListener(s, new PropertyChangeListener() { |
51 |
public void |
52 |
propertyChange(PropertyChangeEvent e) { |
53 |
boolean b; |
54 |
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
55 |
measurementUnitDecibel = b; |
56 |
} |
57 |
}); |
58 |
|
59 |
firstMidiBankNumber = preferences().getIntProperty(FIRST_MIDI_BANK_NUMBER); |
60 |
firstMidiProgramNumber = preferences().getIntProperty(FIRST_MIDI_PROGRAM_NUMBER); |
61 |
|
62 |
MidiInstrument.setFirstProgramNumber(firstMidiProgramNumber); |
63 |
|
64 |
s = FIRST_MIDI_BANK_NUMBER; |
65 |
preferences().addPropertyChangeListener(s, new PropertyChangeListener() { |
66 |
public void |
67 |
propertyChange(PropertyChangeEvent e) { |
68 |
firstMidiBankNumber = preferences().getIntProperty(FIRST_MIDI_BANK_NUMBER); |
69 |
} |
70 |
}); |
71 |
|
72 |
s = FIRST_MIDI_PROGRAM_NUMBER; |
73 |
preferences().addPropertyChangeListener(s, new PropertyChangeListener() { |
74 |
public void |
75 |
propertyChange(PropertyChangeEvent e) { |
76 |
firstMidiProgramNumber = preferences().getIntProperty(FIRST_MIDI_PROGRAM_NUMBER); |
77 |
MidiInstrument.setFirstProgramNumber(firstMidiProgramNumber); |
78 |
} |
79 |
}); |
80 |
} |
81 |
|
82 |
/** |
83 |
* Provides UI information for instruments database trees. |
84 |
*/ |
85 |
public abstract InstrumentsDbTreeView<I> getInstrumentsDbTreeView(); |
86 |
|
87 |
/** |
88 |
* Provides UI information for instruments database tables. |
89 |
*/ |
90 |
public abstract InstrumentsDbTableView<I> getInstrumentsDbTableView(); |
91 |
|
92 |
public abstract SamplerBrowserView<I> getSamplerBrowserView(); |
93 |
|
94 |
public abstract BasicIconSet<I> getBasicIconSet(); |
95 |
|
96 |
public abstract JSPrefs preferences(); |
97 |
|
98 |
/** |
99 |
* Determines whether this view provides instruments database support. |
100 |
* @return <code>false</code> |
101 |
*/ |
102 |
public boolean |
103 |
getInstrumentsDbSupport() { return false; } |
104 |
|
105 |
public abstract void initInstrumentsDbTreeModel(); |
106 |
public abstract void resetInstrumentsDbTreeModel(); |
107 |
|
108 |
/** |
109 |
* Determines whether the volume values should be shown in decibels. |
110 |
*/ |
111 |
public boolean |
112 |
isMeasurementUnitDecibel() { return measurementUnitDecibel; } |
113 |
|
114 |
/** Exports the view configuration of the current session. */ |
115 |
public String |
116 |
exportSessionViewConfig() { return ""; } |
117 |
|
118 |
private SessionViewConfig sessionViewConfig = null; |
119 |
|
120 |
public SessionViewConfig |
121 |
getSessionViewConfig() { return sessionViewConfig; } |
122 |
|
123 |
public void |
124 |
setSessionViewConfig(SessionViewConfig config) { sessionViewConfig = config; } |
125 |
|
126 |
public int |
127 |
getFirstMidiBankNumber() { return firstMidiBankNumber; } |
128 |
|
129 |
public int |
130 |
getFirstMidiProgramNumber() { return firstMidiProgramNumber; } |
131 |
|
132 |
public abstract int getDefaultModKey(); |
133 |
|
134 |
/** |
135 |
* Determines whether main menu is moved to |
136 |
* the screen menu bar when running on Mac OS |
137 |
*/ |
138 |
public boolean |
139 |
isUsingScreenMenuBar() { |
140 |
if(!CC.isMacOS()) return false; |
141 |
String s = System.getProperty("apple.laf.useScreenMenuBar"); |
142 |
return (s != null && "true".equalsIgnoreCase(s)) ? true : false; |
143 |
} |
144 |
|
145 |
/** |
146 |
* Shows a dialog with the specified error message. |
147 |
* @param msg The error message to be shown. |
148 |
*/ |
149 |
public abstract void showErrorMessage(String msg); |
150 |
|
151 |
/** |
152 |
* Shows a dialog with error message. |
153 |
* @param e The <code>Exception</code> from which the error message is obtained. |
154 |
*/ |
155 |
public abstract void showErrorMessage(Exception e); |
156 |
|
157 |
/** |
158 |
* Shows a dialog with error message. |
159 |
* @param e The <code>Exception</code> from which the error message is obtained. |
160 |
* @param prefix The prefix to be added to the error message. |
161 |
*/ |
162 |
public abstract void showErrorMessage(Exception e, String prefix); |
163 |
|
164 |
/** |
165 |
* Sets the default font to be used in the GUI. |
166 |
* @param fontName The name of the font to be used as default. |
167 |
*/ |
168 |
public abstract void setUIDefaultFont(String fontName); |
169 |
} |