From: David ‘Bombe’ Roden Date: Sun, 26 May 2013 12:00:58 +0000 (+0200) Subject: Add switch panel. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0d21261bc2ce53628a1d19749519a2c479bb06c0;p=sonitus.git Add switch panel. --- diff --git a/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java index 5ec2735..cfc5f83 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java @@ -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 index 0000000..e20906d --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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)); + } + +}