Add switch panel.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 26 May 2013 12:00:58 +0000 (14:00 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 May 2013 20:54:38 +0000 (22:54 +0200)
src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java
src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java [new file with mode: 0644]

index 5ec2735..cfc5f83 100644 (file)
@@ -24,6 +24,7 @@ import javax.swing.JPanel;
 import net.pterodactylus.sonitus.data.Controlled;
 import net.pterodactylus.sonitus.data.Controller;
 import net.pterodactylus.sonitus.data.controller.Fader;
+import net.pterodactylus.sonitus.data.controller.Switch;
 
 /**
  * Panel that displays all {@link Controller}s of a {@link Controlled}
@@ -44,6 +45,8 @@ public class ControlledPane extends JPanel {
                for (Controller controller : controlled.controllers()) {
                        if (controller instanceof Fader) {
                                add(new FaderPanel((Fader) controller));
+                       } else if (controller instanceof Switch) {
+                               add(new SwitchPanel((Switch) controller));
                        }
                }
                add(Box.createGlue());
diff --git a/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java b/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java
new file mode 100644 (file)
index 0000000..e20906d
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Sonitus - SwitchPanel.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sonitus.gui;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.BorderFactory;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import net.pterodactylus.sonitus.data.controller.Switch;
+
+/**
+ * Displays a {@link Switch}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SwitchPanel extends JPanel {
+
+       /**
+        * Creates a new fader panel.
+        *
+        * @param fader
+        *              The fader being controlled
+        */
+       public SwitchPanel(final Switch switchController) {
+               super(new GridBagLayout());
+               setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+               /* create label. */
+               JLabel label = new JLabel("Mute");
+               add(label, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
+
+               /* create checkbox. */
+               JCheckBox checkBox = new JCheckBox();
+               checkBox.addActionListener(new ActionListener() {
+
+                       @Override
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               switchController.value(((JCheckBox) actionEvent.getSource()).isSelected() ? 1 : 0);
+                       }
+               });
+               add(checkBox, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
+       }
+
+}