From 9178ad72e324d92a1857073740a4c57bbe243028 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 26 May 2013 13:34:59 +0200 Subject: [PATCH] Add GUI that can display faders. --- .../pterodactylus/sonitus/gui/ControlledPane.java | 52 ++++++++++++++++ .../net/pterodactylus/sonitus/gui/FaderPanel.java | 70 ++++++++++++++++++++++ .../net/pterodactylus/sonitus/gui/MainWindow.java | 70 ++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java create mode 100644 src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java create mode 100644 src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java diff --git a/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java new file mode 100644 index 0000000..5ec2735 --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java @@ -0,0 +1,52 @@ +/* + * Sonitus - ControlledTab.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 javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JPanel; + +import net.pterodactylus.sonitus.data.Controlled; +import net.pterodactylus.sonitus.data.Controller; +import net.pterodactylus.sonitus.data.controller.Fader; + +/** + * Panel that displays all {@link Controller}s of a {@link Controlled} + * component. + * + * @author David ‘Bombe’ Roden + */ +public class ControlledPane extends JPanel { + + /** + * Creates a new controlled pane. + * + * @param controlled + * The controlled whose controllers to display + */ + public ControlledPane(Controlled controlled) { + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + for (Controller controller : controlled.controllers()) { + if (controller instanceof Fader) { + add(new FaderPanel((Fader) controller)); + } + } + add(Box.createGlue()); + } + +} diff --git a/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java b/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java new file mode 100644 index 0000000..b6b0d5b --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java @@ -0,0 +1,70 @@ +/* + * Sonitus - FaderPanel.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 javax.swing.BorderFactory; +import javax.swing.DefaultBoundedRangeModel; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSlider; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import net.pterodactylus.sonitus.data.controller.Fader; + +/** + * Displays a {@link Fader}. + * + * @author David ‘Bombe’ Roden + */ +public class FaderPanel extends JPanel { + + /** + * Creates a new fader panel. + * + * @param fader + * The fader being controlled + */ + public FaderPanel(final Fader fader) { + super(new GridBagLayout()); + setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); + + /* create label. */ + JLabel label = new JLabel("Volume"); + 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. */ + add(new JLabel("-∞"), new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); + 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())); + slider.addChangeListener(new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent changeEvent) { + fader.value(((JSlider) changeEvent.getSource()).getValue()); + } + }); + 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 new file mode 100644 index 0000000..7b515fb --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java @@ -0,0 +1,70 @@ +/* + * Sonitus - MainWindow.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.BorderLayout; +import java.awt.Dimension; +import java.util.List; +import javax.swing.JFrame; +import javax.swing.JTabbedPane; +import javax.swing.WindowConstants; + +import net.pterodactylus.sonitus.data.Controlled; +import net.pterodactylus.sonitus.data.Controller; +import net.pterodactylus.sonitus.main.Version; + +/** + * Sonitus main window. + * + * @author David ‘Bombe’ Roden + */ +public class MainWindow extends JFrame { + + /** The tabbed pane displaying all controlled components. */ + private final JTabbedPane tabbedPane = new JTabbedPane(); + + /** Creates a new main window. */ + public MainWindow() { + super(String.format("Sonitus %s", Version.version())); + getContentPane().add(tabbedPane, BorderLayout.CENTER); + setSize(new Dimension(800, 450)); + + /* FIXME - shut everything down properly. */ + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + } + + // + // ACTIONS + // + + /** + * Adds the given controlled to this main window. + * + * @param controlled + * The controlled to add + */ + public void addControllers(Controlled controlled) { + List controllers = controlled.controllers(); + if (controllers.isEmpty()) { + return; + } + ControlledPane controlledPane = new ControlledPane(controlled); + tabbedPane.addTab(controlled.toString(), controlledPane); + } + +} -- 2.7.4