
402
|
Chapter 10, Audio
#78 Provide Audio Controls During Playback
HACK
units represented by the control (like “dB” for a gain-related control, or
“frames per second” for one that is timing-related).
Anyways, you’ve probably figured out that you can build a GUI by using
Swing to provide a view to these
Control
s. In fact, it’s fairly straightforward
to take a factory approach to handing out
JComponent
s based on
Control
s, as
shown in Table 10-1.
The
CompoundControl can’t be handled as easily because you can’t know how
far you’ll have to recursively dig into its hierarchy of controls, nor how to
represent them in relation to one another. For what it’s worth, JavaSound
does not define any
CompoundControl.Type constants, and it’s not clear that
any
CompoundControls exist in J2SE; the Javadoc only speaks in theory of
supporting something like a graphic equalizer, which would need to be a
CompoundControl.
Theory to Practice
To handle the different types of controls that can be encountered, one nice
approach would be to build a factory: you hand it a
Control, and it gives you
back a
JComponent that you can add to your GUI. Example 10-12 shows a
simple implementation of this.
Table 10-1. Controls and their Swing representation
Control type Swing representation
BooleanControl JCheckBox
EnumControl JComboBox
FloatControl JSlider
Example 10-12. Factory to generate Swing widgets for JavaSound controls
import javax.sound.sampled.*; ...