public interface Controller<V extends Comparable<V>> {
/**
+ * Returns the name of this controller.
+ *
+ * @return The name of this controller
+ */
+ String name();
+
+ /**
* Returns the minimum value of this controller.
*
* @return The minimum value of this controller
*/
public abstract class AbstractController<V extends Comparable<V>> implements Controller<V> {
+ /** The name of this controller. */
+ private final String name;
+
/** The minimum value of this controller. */
private final V minimum;
/**
* Creates a new abstract controller.
*
+ * @param name
+ * The name of the controller
* @param minimum
* The minimum value of the controller
* @param maximum
* {@code true} if this controller has a “center” position, {@code false}
* otherwise
* @param currentValue
- * The current value of this controller
*/
- public AbstractController(V minimum, V maximum, boolean centered, V currentValue) {
+ public AbstractController(String name, V minimum, V maximum, boolean centered, V currentValue) {
+ this.name = name;
this.minimum = minimum;
this.maximum = maximum;
this.centered = centered;
//
@Override
+ public String name() {
+ return name;
+ }
+
+ @Override
public V minimum() {
return minimum;
}
*/
public abstract class Fader extends AbstractController<Double> {
- /** Creates a new fader that is at maximum position. */
- public Fader() {
- this(1.0);
+ /**
+ * Creates a new fader that is at maximum position.
+ *
+ * @param name
+ * The name of the fader
+ */
+ public Fader(String name) {
+ this(name, 1.0);
}
/**
* Creates a new fader that is at the given position.
*
+ * @param name
+ * The name of the fader
* @param currentValue
* The current value of the fader (from {@code 0.0} to {@code 1.0})
*/
- public Fader(Double currentValue) {
- super(0.0, 1.0, false, currentValue);
+ public Fader(String name, Double currentValue) {
+ super(name, 0.0, 1.0, false, currentValue);
}
}
*/
public abstract class Switch extends AbstractController<Boolean> {
- /** Creates a new switch that is off. */
- public Switch() {
- this(false);
+ /**
+ * Creates a new switch that is off.
+ *
+ * @param name
+ * The name of the switch
+ */
+ public Switch(String name) {
+ this(name, false);
}
/**
* Creates a new switch with the given state.
*
+ * @param name
+ * The name of the switch
* @param active
* The state of the switch
*/
- public Switch(boolean active) {
- super(false, true, false, active);
+ public Switch(String name, boolean active) {
+ super(name, false, true, false, active);
}
}
/** Creates a new audio sink. */
public AudioSink() {
super();
- volumeFader = new Fader() {
+ volumeFader = new Fader("Volume") {
@Override
protected void valueSet(Double value) {
}
}
};
- muteSwitch = new Switch() {
+ muteSwitch = new Switch("Mute") {
private float previousValue;
setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
/* create label. */
- JLabel label = new JLabel("Volume");
+ JLabel label = new JLabel(fader.name());
add(label, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
/* create fader labels. */
setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
/* create label. */
- JLabel label = new JLabel("Mute");
+ JLabel label = new JLabel(switchController.name());
add(label, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
/* create checkbox. */