19b9fac9815ad78f8943f236cfe1a5512313c365
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / gui / ControlledPane.java
1 /*
2  * Sonitus - ControlledTab.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sonitus.gui;
19
20 import java.awt.GridBagConstraints;
21 import java.awt.GridBagLayout;
22 import java.awt.Insets;
23 import javax.swing.BorderFactory;
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26
27 import net.pterodactylus.sonitus.data.Controlled;
28 import net.pterodactylus.sonitus.data.Controller;
29 import net.pterodactylus.sonitus.data.controller.Fader;
30 import net.pterodactylus.sonitus.data.controller.Knob;
31 import net.pterodactylus.sonitus.data.controller.Switch;
32
33 /**
34  * Panel that displays all {@link Controller}s of a {@link Controlled}
35  * component.
36  *
37  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38  */
39 public class ControlledPane extends JPanel {
40
41         /**
42          * Creates a new controlled pane.
43          *
44          * @param controlled
45          *              The controlled whose controllers to display
46          */
47         public ControlledPane(Controlled controlled) {
48                 super(new GridBagLayout());
49                 setBorder(BorderFactory.createEmptyBorder(6, 12, 12, 12));
50
51                 int controllerIndex = 0;
52                 for (Controller controller : controlled.controllers()) {
53                         add(new JLabel(controller.name()), new GridBagConstraints(0, controllerIndex, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(6, 0, 0, 6), 0, 0));
54                         if (controller instanceof Fader) {
55                                 add(new FaderPanel((Fader) controller), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0));
56                         } else if (controller instanceof Switch) {
57                                 add(new SwitchPanel((Switch) controller), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0));
58                         } else if (controller instanceof Knob) {
59                                 add(new KnobPanel((Knob) controller), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0));
60                         }
61                         ++controllerIndex;
62                 }
63                 add(new JPanel(), new GridBagConstraints(0, controllerIndex, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
64         }
65
66 }