From f761d816f6e2f14bc80efb45e4cb5c130fa9a57f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 26 May 2013 14:18:59 +0200 Subject: [PATCH] =?utf8?q?Make=20controller=E2=80=99s=20value=E2=80=99s=20?= =?utf8?q?type=20variable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sonitus/data/Controlled.java | 2 +- .../net/pterodactylus/sonitus/data/Controller.java | 10 ++++---- .../data/controller/AbstractController.java | 30 +++++++++++----------- .../sonitus/data/controller/Fader.java | 6 ++--- .../sonitus/data/controller/Switch.java | 4 +-- .../sonitus/data/filter/DummyFilter.java | 2 +- .../pterodactylus/sonitus/data/sink/AudioSink.java | 12 ++++----- .../pterodactylus/sonitus/data/sink/FileSink.java | 2 +- .../sonitus/data/sink/Icecast2Sink.java | 2 +- .../sonitus/data/source/FileSource.java | 2 +- .../sonitus/data/source/MultiSource.java | 2 +- .../sonitus/data/source/StreamSource.java | 2 +- .../net/pterodactylus/sonitus/gui/FaderPanel.java | 4 +-- .../net/pterodactylus/sonitus/gui/MainWindow.java | 2 +- .../net/pterodactylus/sonitus/gui/SwitchPanel.java | 2 +- 15 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/data/Controlled.java b/src/main/java/net/pterodactylus/sonitus/data/Controlled.java index 88ce3e0..b84a114 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Controlled.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Controlled.java @@ -31,6 +31,6 @@ public interface Controlled { * * @return The controllers of this component */ - public List controllers(); + public List> controllers(); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/Controller.java b/src/main/java/net/pterodactylus/sonitus/data/Controller.java index 01e157a..afc92c0 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Controller.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Controller.java @@ -22,21 +22,21 @@ package net.pterodactylus.sonitus.data; * * @author David ‘Bombe’ Roden */ -public interface Controller { +public interface Controller> { /** * Returns the minimum value of this controller. * * @return The minimum value of this controller */ - int minimum(); + V minimum(); /** * Returns the maximum value of this controller. * * @return The maximum value of this controller */ - int maximum(); + V maximum(); /** * Returns whether this control has a “center” position. @@ -51,7 +51,7 @@ public interface Controller { * * @return The current value of this controller */ - int value(); + V value(); /** * Sets the current value of this controller. @@ -59,6 +59,6 @@ public interface Controller { * @param value * The current value of this controller */ - void value(int value); + void value(V value); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java b/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java index 43276fc..c091573 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java +++ b/src/main/java/net/pterodactylus/sonitus/data/controller/AbstractController.java @@ -28,19 +28,19 @@ import net.pterodactylus.sonitus.data.Controller; * * @author David ‘Bombe’ Roden */ -public abstract class AbstractController implements Controller { +public abstract class AbstractController> implements Controller { /** The minimum value of this controller. */ - private final int minimum; + private final V minimum; /** The maximum value of this controller. */ - private final int maximum; + private final V maximum; /** Whether this controller has a “center” position. */ private final boolean centered; /** The current value of this controller. */ - private int value; + private V value; /** * Creates a new abstract controller. @@ -55,7 +55,7 @@ public abstract class AbstractController implements Controller { * @param currentValue * The current value of this controller */ - public AbstractController(int minimum, int maximum, boolean centered, int currentValue) { + public AbstractController(V minimum, V maximum, boolean centered, V currentValue) { this.minimum = minimum; this.maximum = maximum; this.centered = centered; @@ -67,12 +67,12 @@ public abstract class AbstractController implements Controller { // @Override - public int minimum() { + public V minimum() { return minimum; } @Override - public int maximum() { + public V maximum() { return maximum; } @@ -82,14 +82,14 @@ public abstract class AbstractController implements Controller { } @Override - public int value() { + public V value() { return value; } @Override - public void value(int value) { - int newValue = Math.min(maximum, Math.max(minimum, value)); - if (newValue != this.value) { + public void value(V value) { + V newValue = (value.compareTo(minimum) < 0) ? minimum : ((value.compareTo(maximum) > 0) ? maximum : value); + if (newValue.compareTo(this.value) != 0) { this.value = newValue; valueSet(newValue); } @@ -100,13 +100,13 @@ public abstract class AbstractController implements Controller { // /** - * Adjusts the controller. This method is called from {@link #value(int)} if - * the new value is different from the current value. Also, the value is - * clamped to fit within the range of this controller. + * Adjusts the controller. This method is called from {@link + * #value(Comparable)} if the new value is different from the current value. + * Also, the value is clamped to fit within the range of this controller. * * @param value * The new value */ - protected abstract void valueSet(int value); + protected abstract void valueSet(V value); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/controller/Fader.java b/src/main/java/net/pterodactylus/sonitus/data/controller/Fader.java index 4cb6f28..0f78ea2 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/controller/Fader.java +++ b/src/main/java/net/pterodactylus/sonitus/data/controller/Fader.java @@ -24,7 +24,7 @@ import net.pterodactylus.sonitus.data.Controller; * * @author David ‘Bombe’ Roden */ -public abstract class Fader extends AbstractController { +public abstract class Fader extends AbstractController { /** Creates a new fader that is at maximum position. */ public Fader() { @@ -37,8 +37,8 @@ public abstract class Fader extends AbstractController { * @param currentValue * The current value of the fader (from {@code 0.0} to {@code 1.0}) */ - public Fader(double currentValue) { - super(0, Integer.MAX_VALUE, false, (int) (Math.max(0, Math.min(1, currentValue)) * Integer.MAX_VALUE)); + public Fader(Double currentValue) { + super(0.0, 1.0, false, currentValue); } } diff --git a/src/main/java/net/pterodactylus/sonitus/data/controller/Switch.java b/src/main/java/net/pterodactylus/sonitus/data/controller/Switch.java index ae815cb..cb853a3 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/controller/Switch.java +++ b/src/main/java/net/pterodactylus/sonitus/data/controller/Switch.java @@ -22,7 +22,7 @@ package net.pterodactylus.sonitus.data.controller; * * @author David ‘Bombe’ Roden */ -public abstract class Switch extends AbstractController { +public abstract class Switch extends AbstractController { /** Creates a new switch that is off. */ public Switch() { @@ -36,7 +36,7 @@ public abstract class Switch extends AbstractController { * The state of the switch */ public Switch(boolean active) { - super(0, 1, false, active ? 1 : 0); + super(false, true, false, active); } } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java index 2247ecc..9d81923 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java @@ -54,7 +54,7 @@ public class DummyFilter implements Filter { // @Override - public List controllers() { + public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java index 720b919..fdcbbd6 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java @@ -67,10 +67,10 @@ public class AudioSink implements Sink { volumeFader = new Fader() { @Override - protected void valueSet(int value) { + protected void valueSet(Double value) { if (sourceDataLine != null) { FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(VOLUME); - volumeControl.setValue(value * volumeControl.getMaximum() / (float) maximum()); + volumeControl.setValue((float) (value * volumeControl.getMaximum())); } } }; @@ -79,10 +79,10 @@ public class AudioSink implements Sink { private float previousValue; @Override - protected void valueSet(int value) { + protected void valueSet(Boolean value) { if (sourceDataLine != null) { FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(VOLUME); - if (value == 1) { + if (value) { previousValue = volumeControl.getValue(); volumeControl.setValue(0); } else { @@ -98,8 +98,8 @@ public class AudioSink implements Sink { // @Override - public List controllers() { - return Arrays.asList(volumeFader, muteSwitch); + public List> controllers() { + return Arrays.>asList(volumeFader, muteSwitch); } // diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java index f3600f0..9da8b48 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java @@ -58,7 +58,7 @@ public class FileSink implements Sink { // @Override - public List controllers() { + public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java index 359c262..89a930c 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java @@ -115,7 +115,7 @@ public class Icecast2Sink implements Sink { // @Override - public List controllers() { + public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java index 08139d5..840bd9f 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java @@ -78,7 +78,7 @@ public class FileSource implements Source { // @Override - public List controllers() { + public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java index 0779b1a..6eab01e 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java @@ -88,7 +88,7 @@ public class MultiSource implements Source { // @Override - public List controllers() { + public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java index 8c7464c..90cf645 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java @@ -121,7 +121,7 @@ public class StreamSource implements Source { // @Override - public List controllers() { + public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java b/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java index b6b0d5b..68ca774 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java @@ -56,12 +56,12 @@ public class FaderPanel extends JPanel { add(new JLabel("0"), new GridBagConstraints(3, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); /* create fader. */ - JSlider slider = new JSlider(new DefaultBoundedRangeModel(fader.value(), 0, fader.minimum(), fader.maximum())); + JSlider slider = new JSlider(new DefaultBoundedRangeModel((int) (fader.value() * Integer.MAX_VALUE), 0, 0, Integer.MAX_VALUE)); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent changeEvent) { - fader.value(((JSlider) changeEvent.getSource()).getValue()); + fader.value(((JSlider) changeEvent.getSource()).getValue() / (double) Integer.MAX_VALUE); } }); add(slider, new GridBagConstraints(2, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); diff --git a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java index 7b515fb..0cc3b13 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java @@ -59,7 +59,7 @@ public class MainWindow extends JFrame { * The controlled to add */ public void addControllers(Controlled controlled) { - List controllers = controlled.controllers(); + List> controllers = controlled.controllers(); if (controllers.isEmpty()) { return; } diff --git a/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java b/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java index e20906d..40ba4d8 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java @@ -56,7 +56,7 @@ public class SwitchPanel extends JPanel { @Override public void actionPerformed(ActionEvent actionEvent) { - switchController.value(((JCheckBox) actionEvent.getSource()).isSelected() ? 1 : 0); + switchController.value(((JCheckBox) actionEvent.getSource()).isSelected()); } }); add(checkBox, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); -- 2.7.4