Add knob controller panel.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / gui / ControlledPane.java
index 5ec2735..19b9fac 100644 (file)
 
 package net.pterodactylus.sonitus.gui;
 
-import javax.swing.Box;
-import javax.swing.BoxLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
 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.Knob;
+import net.pterodactylus.sonitus.data.controller.Switch;
 
 /**
  * Panel that displays all {@link Controller}s of a {@link Controlled}
@@ -40,13 +45,22 @@ public class ControlledPane extends JPanel {
         *              The controlled whose controllers to display
         */
        public ControlledPane(Controlled controlled) {
-               setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+               super(new GridBagLayout());
+               setBorder(BorderFactory.createEmptyBorder(6, 12, 12, 12));
+
+               int controllerIndex = 0;
                for (Controller controller : controlled.controllers()) {
+                       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));
                        if (controller instanceof Fader) {
-                               add(new FaderPanel((Fader) controller));
+                               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));
+                       } else if (controller instanceof Switch) {
+                               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));
+                       } else if (controller instanceof Knob) {
+                               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));
                        }
+                       ++controllerIndex;
                }
-               add(Box.createGlue());
+               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));
        }
 
 }